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

📄 key.c

📁 一个LCD TV的源程序, 用的是realtek的IC
💻 C
字号:


/*******************************************************************************/
//  Function.c
//  Copyright (c) HIMAX, Inc. All rights reserved.
//  Edit by Taylor Chen
/*******************************************************************************/
#include "intrins.h"
#include "MCU_IO.h"
#include "COMMON.H"
#include "Key.H"
#include "MAIN.H"
#include "i2c_control.h"
#include "HX8824.h"
#include "OSD.h"
#include "rs232.h"

bdata unsigned char bkeycodeA; // now state
sbit bup            = bkeycodeA^7;
sbit bdown	        = bkeycodeA^6;
sbit bleft          = bkeycodeA^5;
sbit bright         = bkeycodeA^4;
sbit bpower         = bkeycodeA^3;
sbit bISP           = bkeycodeA^2;
sbit bburnin        = bkeycodeA^1;
bdata unsigned char bkeycodeB; // previous state
sbit bpup           = bkeycodeB^7;
sbit bpdown         = bkeycodeB^6;
sbit bpleft         = bkeycodeB^5;
sbit bpright        = bkeycodeB^4;
sbit bppower        = bkeycodeB^3;
sbit bpISP          = bkeycodeB^2;
sbit bpburnin       = bkeycodeB^1;
bdata unsigned char bkeycodeC;
sbit bkey_fast      = bkeycodeC^7;
sbit bkeypress      = bkeycodeC^6;
sbit bosdtimeout    = bkeycodeC^5;
sbit bpage_enter    = bkeycodeC^4;
sbit bbrg_con_hot   = bkeycodeC^3;
sbit bout_range_saving = bkeycodeC^2;



idata unsigned char RepeatKeyCounter, KeyTimerCounter, Counter, Second;

/* -------------------------------------------------------------------
  Name    : Key_Snap
  Purpose :
  Passed  :
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
BYTE Key_Snap(void)
{
  BYTE Previous = 0x00, Now = 0xff;

  do{
    Previous = (P1 & 0x1F);  // "0" : active
    DelayX1ms(3);
    Now = (P1 & 0x1F);
    }while(Previous!=Now); // wait signal stable

  return (~Now & 0x1F);

}/* -------------------------------------------------------------------
  Name    : Get_Key
  Purpose :
  Passed  :
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Get_Key(void)
{
  Byte Key_Value, TotalKeyPress;

  bkeycodeA = 0;
  Key_Value = Key_Snap();
  if(Key_Value == 0x01)
    bpower = 1;
  if(Key_Value == 0x02)
    bright = 1;
  if(Key_Value == 0x04)
    bleft = 1;
  if(Key_Value == 0x08)
    bup = 1;
  if(Key_Value == 0x10)
    bdown = 1;
  if(Key_Value == 0x18)
    bISP = 1;
  if(Key_Value == 0x11)
    bBurnInMode = 1;
  if(Key_Value == 0x03)
    bSwitchInput = 1;

						 
// Puts_UART("in getkey loop");HexTobyStr(Panel_Type);Puts_UART(byStr);Puts_UART("\r\n");
  TotalKeyPress = (Byte)bpower + (Byte)bright + (Byte)bup + (Byte)bdown + (Byte)bleft + (Byte)bright;
/*
  if(TotalKeyPress == 1)
    Print_String(5, 2, 0x00, 0x07, "1");
  else if(TotalKeyPress > 1)
    Print_String(5, 2, 0x00, 0x07, "2");
  else if(TotalKeyPress < 1)
    Print_String(5, 2, 0x00, 0x07, "0");
*/

  if(bkeycodeA == 0)               // no key be pressed
  {
    bkeycodeB = RepeatKeyCounter = bkeypress = bkey_fast = 0;
    //Print_String(5, 2, 0x00, 0x07, "0");
  }
  else                             // key pressed
  {
    Second = 0;
    if(bkeycodeA == bkeycodeB)      // key stable
    {
      if(bleft || bright)           // accerlate left, right key only
      {
        RepeatKeyCounter++;
        if(RepeatKeyCounter > 60)
        {
          bkey_fast = 1;
          RepeatKeyCounter = 60;
        }
      }
    }
    else                            // key not stable
    {
        RepeatKeyCounter = bkey_fast = 0;
    }
    if(bkeypress)
    {
      bkeycodeA = 0;                // set as no key be pressed, means release key and read again
    }
    else
    {
      KeyTimerCounter = 0;
      bkeypress = 1;
      bkeycodeB = bkeycodeA;
    }
  }
}
/* -------------------------------------------------------------------
  Name    : Key_Proc
  Purpose :
  Passed  :
  Returns :
  Notes   :
  ------------------------------------------------------------------- */
void Key_Proc()
{
#if TV
	Byte i, j;
#endif
    if(bISP)
    {
        LEDG = LEDR = 1;
        BootFromLDROM();
    }	 
    Puts_UART("in keyproc loop = ");HexTobyStr(bBurnInMode);Puts_UART(byStr);Puts_UART("\r\n");

    if(bBurnInMode)
    {				   
        Puts_UART("in burn in mode loop = ");HexTobyStr(Panel_Type);Puts_UART(byStr);Puts_UART("\r\n");
        if(bpower)
            if((I2CReadByte(HX8824_ADDR, HX8824_TEST_PATTERN) & 0x0F) < 0x0F )
			{
                I2CWriteByte(HX8824_ADDR, HX8824_TEST_PATTERN, I2CReadByte(HX8824_ADDR, HX8824_TEST_PATTERN) + 1);
                Puts_UART("pattern +1 = ");HexTobyStr(Panel_Type);Puts_UART(byStr);Puts_UART("\r\n");
			}
            else if((I2CReadByte(HX8824_ADDR, HX8824_TEST_PATTERN) & 0x0F) == 0x0F)
			{
                I2CWriteByte(HX8824_ADDR, HX8824_TEST_PATTERN, I2CReadByte(HX8824_ADDR, HX8824_TEST_PATTERN) & 0xF0);
				Puts_UART("pattern +1 = ");HexTobyStr(Panel_Type);Puts_UART(byStr);Puts_UART("\r\n");
			}
    }
/*  // ************  for 

⌨️ 快捷键说明

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