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

📄 lcd_msg.c

📁 keil c51平台,此代码可用于学习TFT LCD 之TCON,SCALER,OSD,(本人自己修改)
💻 C
字号:
#define __MESSAGE__

#include "reg52.h"

#include "MAIN_DEF.H"
#include "CONFIG.H"
#include "ACCESS.H"
#include "LCD_FUNC.H"
#include "LCD_MSG.H"
#include "LCD_MAIN.H"
#include "LCD_OSD.H"
#include "MTV512.H"

unsigned char GetKeyState(void)
{
    unsigned char ucKeyState=0;

#if (IRPOLLING)
    {
        Data[0]   = (1 < ucIR_State) ? 0 : ucIR_Cmd[0];

        if (Data[0])
        {
            switch (Data[0])
            {
#if (POWER_KEY_TYPE == TYPE_ONE_TOUCH)
            // Only when power-key is one-touch style, you can use IR remote controller to switch power on/off
            case IR_POWER_KEY :     ucKeyState=ucKeyState|POWER_KEY_MASK;     break;//0x10
#endif
            // Use IR to implement standard key
            case IR_ENTER_KEY :     ucKeyState=ucKeyState|ENTER_KEY_MASK;     break;//0x02
            // Other IR function key
            default :        
                ucKeyState=ucKeyState|IR_KEY_MASK;

#if (VIDEO_CHIP != VDC_NONE)
                switch (Data[0])
                {
                case IR_FUNC_SOURCE :   Data[0] = NOTIFY_IR_SOURCE;     break;//0x1a
                case IR_FUNC_DISP :     Data[0] = NOTIFY_IR_DISP;       break;//0x1b
                case IR_FUNC_JUMP :     Data[0] = NOTIFY_IR_JUMP;       break;//0x1c
                case IR_FUNC_CHDEC :    Data[0] = NOTIFY_IR_CHDEC;      break;//0x1d
                case IR_FUNC_CHINC :    Data[0] = NOTIFY_IR_CHINC;      break;//0x1e
                case IR_FUNC_VOLINC :   Data[0] = NOTIFY_IR_VOLINC;     break;//0x1f
                case IR_FUNC_VOLDEC :   Data[0] = NOTIFY_IR_VOLDEC;     break;//0x20
                case IR_FUNC_MENU :     Data[0] = NOTIFY_IR_MENU;       break;//0x21
                case IR_FUNC_CHNUM :    Data[0] = NOTIFY_IR_CHNUM;      break;//0x22
                case IR_FUNC_MUTE :     Data[0] = NOTIFY_IR_MUTE;       break;//0x23
                case IR_FUNC_NUM0 :     Data[0] = NOTIFY_IR_NUM0;       break;//0x10
                case IR_FUNC_NUM1 :     Data[0] = NOTIFY_IR_NUM1;       break;//0x11
                case IR_FUNC_NUM2 :     Data[0] = NOTIFY_IR_NUM2;       break;//0x12
                case IR_FUNC_NUM3 :     Data[0] = NOTIFY_IR_NUM3;       break;//0x13
                case IR_FUNC_NUM4 :     Data[0] = NOTIFY_IR_NUM4;       break;//0x14
                case IR_FUNC_NUM5 :     Data[0] = NOTIFY_IR_NUM5;       break;//0x15
                case IR_FUNC_NUM6 :     Data[0] = NOTIFY_IR_NUM6;       break;//0x16
                case IR_FUNC_NUM7 :     Data[0] = NOTIFY_IR_NUM7;       break;//0x17
                case IR_FUNC_NUM8 :     Data[0] = NOTIFY_IR_NUM8;       break;//0x18
                case IR_FUNC_NUM9 :     Data[0] = NOTIFY_IR_NUM9;       break;//0x19
                case IR_LEFT_KEY  :     Data[0] = NOTIFY_IR_LEFT_KEY;   break;//0x19
                case IR_RIGHT_KEY :     Data[0] = NOTIFY_IR_RIGHT_KEY;  break;//0x19
                default :               ucKeyState  = 0;                break;
                }
#endif
                break;
            }
        }
    }//#if (IRPOLLING)
#endif

    if(!bRIGHT_KEY)
        ucKeyState=ucKeyState|RIGHT_KEY_MASK;
    if(!bLEFT_KEY)
	ucKeyState=ucKeyState|LEFT_KEY_MASK;
    if(!bENTER_KEY)
	ucKeyState=ucKeyState|ENTER_KEY_MASK;
    if(!bAUTO_KEY)
	ucKeyState=ucKeyState|AUTO_KEY_MASK;
    if(!bPOWER_KEY)
	ucKeyState=ucKeyState|POWER_KEY_MASK;

#if (KEY_TYPE == KEY_6)
    if(!bEXIT_KEY)
	ucKeyState=ucKeyState|EXIT_KEY_MASK;
#endif

#if (TV_CHIP != TV_NONE)
    if(!bCHINC_KEY)
	ucKeyState=ucKeyState|CHINC_KEY_MASK;
    if(!bCHDEC_KEY)
	ucKeyState=ucKeyState|CHDEC_KEY_MASK;
#endif

    return ucKeyState;
}

// Key_Trans() is used for generating key related messages, including OSD timout message.
// You can just issue the message or execute system default function, like changing input source.

// BE CAREFUL !! YOU CANNOT CHANGE ANY OSD STATUS REGISTERS OR CALL ANY OSD PROCESS HERE !!
// You should not expect OSD_Proc() can always receive your message.
// Because main program will shield OSD process from been triggered when input signal isn't stable,
// and terminate OSD process when input source is changed.
unsigned char Key_Trans()
{
    static unsigned char    idata   ucP3_Prev       = 0;
    static unsigned char    idata   ucP3_Curr       = 0;
    static unsigned char    idata   ucKey_Repeat    = 0;

    unsigned char   ucNotify    = NOTIFY_NONE;

    // Save the previous key status
    ucP3_Prev   = ucP3_Curr;
    // Sample the current key status
    ucP3_Curr   = GetKeyState();

#if (POWER_KEY_TYPE == TYPE_TWO_STATE)
    // We MUST handle power-key first.
    if (bPower_Status)
    {
        if (ucP3_Curr & POWER_KEY_MASK)
            ucP3_Curr   ^= POWER_KEY_MASK;  // Go further to handle other keys (and mask power-key)
        else
        {
            Delay_Xms(20);

            ucP3_Prev   = ucP3_Curr;
            ucP3_Curr   = GetKeyState();

            if (ucP3_Curr & POWER_KEY_MASK)
                ucP3_Curr   ^= POWER_KEY_MASK;  // Go further to handle other keys (and mask power-key)
            else
                return  NOTIFY_POWERDOWN;
        }
    }
    else
    {
        if (ucP3_Curr & POWER_KEY_MASK)
        {
            ucKey_Issued    = 0;

            Delay_Xms(20);

            ucP3_Prev   = ucP3_Curr;
            ucP3_Curr   = GetKeyState();

            if (ucP3_Curr & POWER_KEY_MASK)
                return NOTIFY_POWERUP;
            else
                return NOTIFY_NONE;
        }
        else
            return NOTIFY_NONE;
    }

#else   // POWER_KEY_TYPE is TYPE_ONE_TOUCH

    if (bPower_Status)
    {
        if (POWER_KEY_MASK & ucP3_Curr)
        {
            if ((ucP3_Prev ^ ucP3_Curr) & POWER_KEY_MASK)
            {
                Delay_Xms(20);

                ucP3_Curr   = GetKeyState();

                if ((ucP3_Prev ^ ucP3_Curr) & POWER_KEY_MASK)   
		{
#if (AUDIO_TYPE == AUDIO_SC7313)
    		    Data[0] = 4;
    		    Data[1] = ADDR_SC7313;
    		    Data[2] = 0xbf;                           // Front right  - mutedB  10111111b
    		    Data[3] = 0x9f;                           // Front left   - mutedB  10011111b
    		    I2CWrite(Data);
#endif
#if (AUDIO_TYPE == AUDIO_62429)					
	  	    bAUDIO_PD = 0;
#endif  
#if(OUTPUT_BUS == RSDS_TYPE)	//V230
		    RTDCodeW(RTD_PW12V_DOWN);
#endif		    
                    return NOTIFY_POWERDOWN;
                }    
                else
                    return NOTIFY_NONE;
            }
        }
    }
    else
    {
        if (POWER_KEY_MASK & ucP3_Curr)
        {
            if ((ucP3_Prev ^ ucP3_Curr) & POWER_KEY_MASK)
            {
                ucKey_Issued    = 0;

                Delay_Xms(20);

                ucP3_Curr   = GetKeyState();

                if ((ucP3_Prev ^ ucP3_Curr) & POWER_KEY_MASK)
		{
#if (AUDIO_TYPE == AUDIO_SC7313)
    		    Data[0] = 4;
    		    Data[1] = ADDR_SC7313;
    		    Data[2] = 0xb4;                           // Front right  - mutedB  10111111b
    		    Data[3] = 0x94;                           // Front left   - mutedB  10011111b
    		    I2CWrite(Data);
#endif
#if (AUDIO_TYPE == AUDIO_62429)					
	  	    bAUDIO_PD = 1;
#endif                    
                    
                    return NOTIFY_POWERUP;
		}	
                else
                    return NOTIFY_NONE;
            }
            else
                return NOTIFY_NONE;
        }
    }

#endif

    // Generate Key Messages
    switch (ucP3_Curr)
    {
    case AUTO_KEY_MASK :
        if(ucOSD_Page_Index)
#if(IRPOLLING)
    		usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    		usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif

        if ((ucP3_Prev ^ ucP3_Curr) & AUTO_KEY_MASK)
        {
            ucKey_Issued    = 0;
            ucNotify        = NOTIFY_AUTO_KEY;
        }
        break;

#if (KEY_TYPE == KEY_6)        
    case EXIT_KEY_MASK :
        if(ucOSD_Page_Index)
#if(IRPOLLING)
    		usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    		usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif
        if ((ucP3_Prev ^ ucP3_Curr) & EXIT_KEY_MASK)
        {
            ucKey_Issued    = 0;
            ucNotify        = NOTIFY_EXIT_KEY;
        }
        break;
#endif

    case CHINC_KEY_MASK :
#if(IRPOLLING)
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif
        if ((ucP3_Prev ^ ucP3_Curr) & CHINC_KEY_MASK)
        {
            ucKey_Issued    = 0;
            ucNotify        = NOTIFY_CHINC_KEY;
            ucKey_Repeat    = KEY_REPEAT_COUNT;
        }
        else
        {
            if (ucKey_Repeat)
                ucKey_Repeat    -= 1;
            else
            {
                if (KEY_TURBO_ENABLE > ucKey_Issued)
                {
                    ucKey_Issued    += 1;
                    ucKey_Repeat    = KEY_REPEAT_PERIOD;
                }
                else
                    ucKey_Repeat    = 0;

                ucNotify        = NOTIFY_CHINC_KEY;                     // Post CHINC-key repeat message
            }
        }
        break;
        
    case CHDEC_KEY_MASK :
#if(IRPOLLING)
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif        
        if ((ucP3_Prev ^ ucP3_Curr) & CHDEC_KEY_MASK)
        {
            ucKey_Issued    = 0;
            ucNotify        = NOTIFY_CHDEC_KEY;
            ucKey_Repeat    = KEY_REPEAT_COUNT;
        }
        else
        {
            if (ucKey_Repeat)
                ucKey_Repeat    -= 1;
            else
            {
                if (KEY_TURBO_ENABLE > ucKey_Issued)
                {
                    ucKey_Issued    += 1;
                    ucKey_Repeat    = KEY_REPEAT_PERIOD;
                }
                else
                    ucKey_Repeat    = 0;

                ucNotify        = NOTIFY_CHDEC_KEY;                     // Post CHINC-key repeat message
            }
        }
        break;
   
    case ENTER_KEY_MASK :
        if ((ucP3_Prev ^ ucP3_Curr) & ENTER_KEY_MASK)
        {
            ucKey_Issued    = 0;
#if(IRPOLLING)
    	    usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    	    usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif
            ucNotify        = NOTIFY_ENTER_KEY;                         // Post enter-key pressed message
            ucKey_Repeat    = KEY_REPEAT_COUNT * 8;
        }
        else
        {
            if (ucKey_Repeat)
                ucKey_Repeat    -= 1;
            else
            {
                if (ucOSD_Page_Index)
                {
                    usOSD_Timer = 0;
                    ucNotify    = NOTIFY_CLEAR_OSD;
                }
            }
        }
        break;
    
    case RIGHT_KEY_MASK :
#if(IRPOLLING)
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif
            
        if ((ucP3_Prev ^ ucP3_Curr) & RIGHT_KEY_MASK)
        {
            ucKey_Issued    = 0;

            ucNotify        = NOTIFY_RIGHT_KEY;                         // Post right-key pressed message
            ucKey_Repeat    = KEY_REPEAT_COUNT;
        }
        else
        {
            if (ucKey_Repeat)
                ucKey_Repeat    -= 1;
            else
            {
                if (KEY_TURBO_ENABLE > ucKey_Issued)
                {
                    ucKey_Issued    += 1;
                    ucKey_Repeat    = KEY_REPEAT_PERIOD;
                }
                else
                    ucKey_Repeat    = 0;

                ucNotify        = NOTIFY_RIGHT_KEY;                     // Post right-key repeat message
            }
        }
        break;
    
    case LEFT_KEY_MASK :
#if(IRPOLLING)
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    	usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif
        if ((ucP3_Prev ^ ucP3_Curr) & LEFT_KEY_MASK)
        {
            ucKey_Issued    = 0;

            ucNotify        = NOTIFY_LEFT_KEY;                          // Post left-key pressed message
            ucKey_Repeat    = KEY_REPEAT_COUNT;
        }
        else
        {
            if (ucKey_Repeat)
                ucKey_Repeat    -= 1;
            else
            {
                if (KEY_TURBO_ENABLE > ucKey_Issued)
                {
                    ucKey_Issued    += 1;
                    ucKey_Repeat    = KEY_REPEAT_PERIOD;
                }
                else
                    ucKey_Repeat    = 0;

                ucNotify        = NOTIFY_LEFT_KEY;                      // Post left-key repeat message
            }
        }
        break;

#if (IRPOLLING)
    case IR_KEY_MASK :
        usOSD_Timer         = (unsigned int)stGUD1.OSD_TIMEOUT * 51; 
        ucKey_Issued    = 0;
        if ((ucP3_Prev ^ ucP3_Curr) & IR_KEY_MASK)
        {
            ucNotify        = Data[0];                                      // Post IR-key pressed message
            ucKey_Repeat    = KEY_REPEAT_COUNT;
            if (NOTIFY_IR_VOLINC == Data[0] || NOTIFY_IR_VOLDEC == Data[0] || NOTIFY_IR_CHINC == Data[0] || NOTIFY_IR_CHDEC == Data[0] || NOTIFY_IR_RIGHT_KEY== Data[0] || NOTIFY_IR_LEFT_KEY== Data[0])
                ucIR_Cmd[1] = 1;
        }
        else if(NOTIFY_IR_VOLINC == Data[0] || NOTIFY_IR_VOLDEC == Data[0] || NOTIFY_IR_CHINC == Data[0] || NOTIFY_IR_CHDEC == Data[0] || NOTIFY_IR_RIGHT_KEY== Data[0] || NOTIFY_IR_LEFT_KEY== Data[0])
        {
            if (ucKey_Repeat)
                ucKey_Repeat    -= 1;
            else
            {
                ucNotify        = Data[0];
                ucKey_Repeat    = KEY_REPEAT_PERIOD;
            }
        }
        break;
#endif
    
    default :
        // No key or more than 1 key pressed. Post no message and reset key-repeat.
        ucKey_Repeat    = KEY_REPEAT_COUNT;
        ucKey_Issued    = 0;

#if (HIDDEN_PAGE)        
        // For triggering the hidden page
        if (0 == ucOSD_Page_Index && (RIGHT_KEY_MASK | LEFT_KEY_MASK) == ucP3_Curr)
        {    
            ucNotify    = NOTIFY_LR_KEY;
#if(IRPOLLING)
    	    usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 34;
#else
    	    usOSD_Timer	= (unsigned int)stGUD1.OSD_TIMEOUT * 51;
#endif
        }
#endif
        break;
    }

    return ucNotify;
}

⌨️ 快捷键说明

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