⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 function.c

📁 一个LCD TV的源程序, 用的是realtek的IC
💻 C
📖 第 1 页 / 共 3 页
字号:
/*******************************************************************************
  Function.c
  Copyright (c) HIMAX, Inc. All rights reserved.
  Edit by Taylor Chen
*******************************************************************************/
#include "intrins.h"
#include "MCU_IO.h"
#include "COMMON.H"
#include "Function.H"
#include "MAIN.H"
#include "i2c_control.h"
#include "HX8824.h"
#include "Key.h"
#include "OSD.h"
#include "ModeTable.h"
/*==============================================================================*/

extern code unsigned char EEPDATA[64][16];
/*==============================================================================*/
/* -------------------------------------------------------------------
  Name    : BootFromLDROM
  Purpose : Enter MCU ISP Mode
  Passed  : Word
  Returns :
  Notes   :
  ------------------------------------------------------------------- */

void BootFromLDROM(void)
{
	IE 		= 0x00;    // Disable all interrupt
	CHPENR	= 0x87;  //
	CHPENR 	= 0x59;
	CHPCON 	= 0x03;
	CHPENR 	= 0x00;
	TCON 	= 0x00;
	IP 		= 0x00;
	TL0 	= 0xfe;
	TH0		= 0xff;
	TMOD 	= 0x01;
	IE 		= 0x82;    // Enable interrupt Timer/counter 0
	TCON 	= 0x10;
	PCON	= 0x01;
	while(1);
}

/* -------------------------------------------------------------------
  Name    : DelayX1ms
  Purpose : Delay 1ms Seconds
  Passed  :
  Returns :
  Notes   :
  ------------------------------------------------------------------- */

void DelayX1ms(unsigned int n)
{

  unsigned int i;

  while(n--!=0)
    for (i=0; i<86; i++)
      ;
}

/* -------------------------------------------------------------------
  Name    : DelayX10ms
  Purpose : Delay 10ms Seconds
  Passed  :
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void DelayX10ms(unsigned int n)
{

  unsigned int i;

  while(n--!=0)
    for (i=0; i<860; i++)
      ;
}

/* -------------------------------------------------------------------
  Name    : Print_Icon
  Purpose : Print ICON
  Passed  : Display area, attribute
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Print_Icon(Byte Disp_R, Byte Disp_C, Byte Attr0, Byte Attr1, Byte Attr2)
{
    BYTE Disp;
    Disp = (Disp_R - 1)*32 + (Disp_C - 1);
    I2CWrite2Byte(HX8824_ADDR, HX8824_DISPLAY_AREA, Disp, Disp >> 8);  //0xBE
    I2CWrite3Byte(HX8824_ADDR, HX8824_OSD_ATTR, Attr0, Attr1, Attr2); //0xC0
}
/* -------------------------------------------------------------------
  Name    : Print_String
  Purpose : Print String
  Passed  : Display area, attribute
  Returns :
  Notes   :
  ------------------------------------------------------------------- */

void Print_String(Byte Disp_R, Byte Disp_C, Byte Attr0, Byte Attr1, Byte *string)
{
    BYTE Disp, i = 0;
    Disp = (Disp_R - 1)*32 + (Disp_C - 1);
    while((*(string+i))!='\0')
    {
        I2CWrite2Byte(HX8824_ADDR, HX8824_DISPLAY_AREA, Disp, Disp >> 8);  //0xBE
        //I2CWrite3Byte(HX8824_ADDR, HX8824_OSD_ATTR, Attr0, Attr1, *(string + i) - 64); //0xC0
        I2CWrite3Byte(HX8824_ADDR, HX8824_OSD_ATTR, Attr0, Attr1, *(string + i) - 47); //0xC0
        Disp++;
        i++;
    }
}

/* -------------------------------------------------------------------
  Name    : Select_Item
  Purpose : Select Item
  Passed  :
  Returns :
  Notes   :
  ------------------------------------------------------------------- */

void Select_Item(void)
{
  unsigned char prev, next;
  Byte i;

  prev=(Item+(TOTAL_ICON-1))%TOTAL_ICON;       //TOTAL_ICON = 12
  next=(Item+(TOTAL_ICON+1))%TOTAL_ICON;
  Puts_UART("Item = ");HexTobyStr(Item);Puts_UART(byStr);Puts_UART("\r\n");


  for(i = 0; i < 3; i++)
  {
    Print_Icon(ICONPOS[prev][0], ICONPOS[prev][1], 0x00, 0x07, ICONGROUP[prev][0]);
    Print_Icon(ICONPOS[prev][0], ICONPOS[prev][1] + 1, 0x00, 0x07, ICONGROUP[prev][1]);
    Print_Icon(ICONPOS[next][0], ICONPOS[next][1], 0x00, 0x07, ICONGROUP[next][0]);
    Print_Icon(ICONPOS[next][0], ICONPOS[next][1] + 1, 0x00, 0x07, ICONGROUP[next][1]);
    Print_Icon(ICONPOS[Item][0], ICONPOS[Item][1], 0x03, 0x07, ICONGROUP[Item][0]);
    Print_Icon(ICONPOS[Item][0], ICONPOS[Item][1] + 1, 0x03, 0x07, ICONGROUP[Item][1]);
  }
  OSDBarHandle(Item, 5, 6, 0x03, 0x05);
}

/* -------------------------------------------------------------------
  Name    : OSD_Bar_Handle
  Purpose : Adjust OSD Bar
  Passed  : Item, row, column, attr0, attr1
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void OSDBarHandle(Byte Item, Byte row, Byte col, Byte attr0, Byte attr1)
{
    Byte i, j;
    Byte BarMaxValue, BarMaxCount = 20, Item_ADDR;
    Word CurrentValue, OSDMaxValue, OSDMinValue;
    Byte UpdateValue;

    BarMaxValue = BarMaxCount * 5;
    switch(Item)
    {
        case 0:
            Item_ADDR = HX8824_BRIGHTNESS;
            OSDMaxValue = 255;
            OSDMinValue = 0;
        break;
        case 1:
            Item_ADDR = HX8824_CONTRAST;
            OSDMaxValue = 255;
            OSDMinValue = 0;
        break;
        case 2:
            Item_ADDR = HX8824_SATSINHUE;
            OSDMaxValue = 511;
            OSDMinValue = 0;
        break;
        case 3:
            Item_ADDR = HX8824_SATCOSHUE;
            OSDMaxValue = 511;
            OSDMinValue = 0;
        break;
        case 6:
            Item_ADDR = HX8824_SHARPNESS;
            OSDMaxValue = 31;
            OSDMinValue = 0;
        break;
        default:
        break;
    }
    if(Item_ADDR == HX8824_SATSINHUE || Item_ADDR == HX8824_SATCOSHUE)
    {
    	CurrentValue = (I2CReadByte(HX8824_ADDR, Item_ADDR + 1) << 8 | (I2CReadByte(HX8824_ADDR, Item_ADDR)));
    	Puts_UART("Current value = ");HexTobyStr(CurrentValue);Puts_UART(byStr);Puts_UART("\r\n");
    	CurrentValue = (CurrentValue * BarMaxValue) / (OSDMaxValue - OSDMinValue);
    	Puts_UART("Current value = ");HexTobyStr(CurrentValue);Puts_UART(byStr);Puts_UART("\r\n");
    }
    else
    {
      CurrentValue = I2CReadByte(HX8824_ADDR, Item_ADDR);
    	Puts_UART("Current value = ");HexTobyStr(CurrentValue);Puts_UART(byStr);Puts_UART("\r\n");
    	CurrentValue = (CurrentValue * BarMaxValue) / (OSDMaxValue - OSDMinValue);
    	Puts_UART("Current value = ");HexTobyStr(CurrentValue);Puts_UART(byStr);Puts_UART("\r\n");
    }
    UpdateValue = CurrentValue;
    Print_Icon(row, col, attr0, attr1, 0x2C);              // left    :1
    j = UpdateValue / 5;
    for(i = 1; i < (j + 1); i++)
    {
        Print_Icon(row, col + i, attr0, attr1, 0x32);      // full    :i = j
    }
    j = UpdateValue % 5;
    Print_Icon(row, col + (i++), attr0, attr1, 0x2D + j);  // nonfull  :j+2
    for(; i < (BarMaxCount + 1); i++)
    {
        Print_Icon(row, col + i, attr0, attr1, 0x2D);      // empty    :
    }
    Print_Icon(row, (col + (BarMaxCount + 1)), attr0, attr1, 0x33);
}

/* -------------------------------------------------------------------
  Name    : Sharpness_Adj
  Purpose : Adjust Sharpness
  Passed  : +/-
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Sharp_Adj(Byte S)
{
    Word temp;
    temp = I2CReadByte(HX8824_ADDR, HX8824_SHARPNESS); // convert 0~255 to 0~100
    switch(S)
    {
        case 0:
            if(temp != 0)
                temp--;
            else
                temp = 0;
        break;
        case 1:
            if(temp != 0x1F)
                temp++;
            else
                temp = 0x1F;
        break;
    }
    I2CWriteByte(HX8824_ADDR, HX8824_SHARPNESS, temp);
#if EEPROM
    I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SHARPNESS)/256)*2), ParaAddress + EE_SHARPNESS, temp);
    Puts_UART("Write to EEPROM device addr ");HexTobyStr(EEPROM_MCU | (((ParaAddress + EE_SHARPNESS)/256)*2));Puts_UART(byStr);Puts_UART("\r\n");
    Puts_UART("Write to EEPROM address");HexTobyStr(ParaAddress + EE_SHARPNESS);Puts_UART(byStr);Puts_UART("\r\n");
    Puts_UART("Write to EEPROM value");HexTobyStr(temp);Puts_UART(byStr);Puts_UART("\r\n");
#endif
    OSDBarHandle(Item, 5, 6, 0x03, 0x05);
}

/* -------------------------------------------------------------------
  Name    : Contrast_Adj
  Purpose : Adjust Contrast
  Passed  : Read/Write
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Contrast_Adj(Byte S)
{
    Word temp;
    temp = I2CReadByte(HX8824_ADDR, HX8824_CONTRAST); // convert 0~255 to 0~100
    temp = temp*100/255;
    switch(S)
    {
        case 0:
            if(temp > 0)
                temp--;
            if(temp != 0)
                temp = temp*255/100 + 1;
            else
                temp = 0;
        break;
        case 1:
            if(temp < 100)
                temp++;
            if(temp != 100)
                temp = temp*255/100 + 1;
            else
                temp = 255;
        break;
    }
    I2CWriteByte(HX8824_ADDR, HX8824_CONTRAST, temp);
#if EEPROM
    I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_CONTRAST)/256)*2), ParaAddress + EE_CONTRAST, temp);
#endif
    OSDBarHandle(Item, 5, 6, 0x03, 0x05);
}

/* -------------------------------------------------------------------
  Name    : Bright_Adj
  Purpose : Adjust Brightness
  Passed  : +/-
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Bright_Adj(Byte S)
{
    Word temp;
    temp = I2CReadByte(HX8824_ADDR, HX8824_BRIGHTNESS); // convert 0~255 to 0~100
    temp = temp*100/255;
    switch(S)
    {
        case 0:
            if(temp > 0)
                temp--;
            if(temp != 0)
                temp = temp*255/100 + 1;
            else
                temp = 0;
        break;
        case 1:
            if(temp < 100)
                temp++;
            if(temp != 100)
                temp = temp*255/100 + 1;
            else
                temp = 255;
        break;
    }
    I2CWriteByte(HX8824_ADDR, HX8824_BRIGHTNESS, temp);
#if EEPROM
    I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_BRIGHTNESS)/256)*2), ParaAddress + EE_BRIGHTNESS, temp);
#endif
    OSDBarHandle(Item, 5, 6, 0x03, 0x05);
}
/* -------------------------------------------------------------------
  Name    : Sat_Sin_Hue_Adj
  Purpose : Hue Saturation
  Passed  : +/-
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Sat_Sin_Hue_Adj(Byte S)
{
    long temp;
    temp = (I2CReadByte(HX8824_ADDR, HX8824_SATSINHUE + 1) << 8) | I2CReadByte(HX8824_ADDR, HX8824_SATSINHUE); // convert 0~255 to 0~100
    temp = temp*100/511;
    switch(S)
    {
        case 0:
            if(temp > 0)
                temp--;
            if(temp != 0)
                temp = temp*511/100 + 1;
            else
                temp = 0;
        break;
        case 1:
            if(temp < 100)
                temp++;
            if(temp != 100)
                temp = temp*511/100 + 1;
            else
                temp = 511;
        break;
    }
    I2CWriteByte(HX8824_ADDR, HX8824_SATSINHUE, temp);
    I2CWriteByte(HX8824_ADDR, HX8824_SATSINHUE + 1, temp >> 8);
#if EEPROM
    I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SAT_SIN_HUE)/256)*2), ParaAddress + EE_SAT_SIN_HUE, temp);
    I2CWriteByte(EEPROM_MCU | (((ParaAddress + EE_SAT_SIN_HUE)/256)*2), ParaAddress + EE_SAT_SIN_HUE + 1, temp >> 8);
#endif
    OSDBarHandle(Item, 5, 6, 0x03, 0x05);
}
/* -------------------------------------------------------------------
  Name    : Sat_Cos_Hue_Adj
  Purpose : Hue Saturation
  Passed  : +/-
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Sat_Cos_Hue_Adj(Byte S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -