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

📄 keyboard.c

📁 以ST公司CPU为核心的彩色电视机的完整源程序。
💻 C
字号:
/********************** SGS-THOMSON MICROELECTRONICS ************************
FILENAME     : KEYBOARD.C
VERSION      : V1.0
DATE         : JAN 1999
AUTHOR(s)    : ASHISH RUDOLA/ DEEPAK DOSHI
PROCESSOR    : ST92195
DESCRIPTION  : This module contains functions for scanning the keyboard and
               decoding the results into a command.
MODIFICATION:
   -
*****************************************************************************/

#include "st92196.h"
#include "macro.h"
#include "command.h"
#include "io.h"
#include "keyboard.h"
#include "register.h"
#include "service.h"
#include "timer.h"
#include "utility.h"
#include "ad_c.h"


/*****************************************************************************
INPUTS     : none
OUTPUTS    : KEYBOARD_TIMER - Allow to scan the keyboard as soon as possible
                              to prevent false key on start-up
             keyboard_command - Set to no previous command
DESCRIPTION: This function initializes the keyboard handler.
*****************************************************************************/
void init_keyboard(void)
{
	/* Set the keyboard timer to zero to prevent false key on start-up */
	fast_timers[KEYBOARD_TIMER] = 0x00;

	/* Set to no previous command */
	keyboard_command = NO_KEYBOARD_COMMAND;
}

/*****************************************************************************
INPUTS     : none
OUTPUTS    : KEYBOARD_TIMER - Allow to scan the keyboard as soon as possible
                              to prevent false key on start-up
             keyboard_command - Set to no previous command
DESCRIPTION: This function initializes the keyboard handler.
*****************************************************************************/
unsigned char get_keyboard(void)
{

	volatile unsigned char AD_INT asm("R242");
	volatile unsigned char j;

	if (fast_timers[KEYBOARD_TIMER] == 0)
	{
	fast_timers[KEYBOARD_TIMER] = SCANNING_RATE;
    j = 0xFF;   

    /* Set A to D converter page */
    spp(FAD_PG);  /* PAGE 62 */

    /* Enable A to D converter------- channel 1 enable:001, fast:1 (slow),
    	ext_trigger disable:0, power disable:1, single mode:0, stop:0   */
    FAD_CLR = (FADm_channel_1 | FADm_fs_slow | FADm_pow_en | FADm_str_stop); /* control logic register */
	AD_INT &= ~0x00;  /* Disable AD interrupts from convertion */

	/* Wait ADC to stabilize */
	microsecond_delay(100);
    j = A_D_wait();
	
	if(j >= 0 && j < 235)
	{
     	if(j >= 0 && j < 15)
      {
      	keyboard_command = COMMAND_TV_AV;  /*0x01*/
      }
      else
         {
         if(j > 15 && j < 46)
            {
            keyboard_command = COMMAND_CHANNEL_DOWN;  /*0x02*/
            }
            else
               {
               if(j > 46 && j < 82)
                  {
                  keyboard_command = COMMAND_CHANNEL_UP;   /*0x03*/
                  }
                  else
                     {
                     if(j > 82 && j < 112)
                        {
                        keyboard_command = COMMAND_LEFT;   /*0x04*/
                        }
                        else
                           {
                           if(j > 112 && j < 143)
                              {
                              keyboard_command = COMMAND_RIGHT;   /*0x05*/
                              }
                              else
                                 {
                                 if(j > 143 && j < 176)
                                    {
                                    keyboard_command = COMMAND_OK;  /*0x06*/
                                    }
                                    else
                                       {
                                       if(j > 176 && j < 204)
                                          {
		                                          keyboard_command = COMMAND_MENU;   /*0x07*/
                                          }
                                          else
                                             {
                                             if(j > 204 && j < 235 )
                                                {
                                                keyboard_command = COMMAND_SERVICE;  /*0x08 DIGIT_INCREMENT;   \*0x08;*/
                                                }
                                             }
                                       }
                                 }
                           }
                     }
               }
           
         }


	}

	else
		{
			keyboard_command = NO_KEYBOARD_COMMAND; 

		}
	}
	return keyboard_command;
}

/*****************************************************************************
INPUTS     : none
OUTPUTS    :


DESCRIPTION: This function is wait until A to D process finished.
		It takes the average on 1 AD measures.
*****************************************************************************/
unsigned char A_D_wait(void)
{
	unsigned int j;

    /* Start first conversion and wait for the end of the conversion */
	j =0;
	FAD_CLR = FAD_CLR | 0x01;
    do 
	{
    }while (FAD_CLR & 0x01);

    /* save result of A/D CONVERT */
    j = FAD_DTR;

    /* Start second conversion and wait for the end of the conversion */
	FAD_CLR = FAD_CLR | 0x01;
	do
	{
    } while (FAD_CLR & 0x01);
    j = j + FAD_DTR;

	/* Start third conversion and wait for the end of the conversion */
	FAD_CLR = FAD_CLR | 0x01;
	do
	{
    } while (FAD_CLR & 0x01);
    j = j + FAD_DTR;

    /* AVERAGE OF A/D converter result      */
    j = (unsigned int) j/3;
    
	return ((unsigned char) j);
}

/*****************************************************************************
INPUTS     : none
OUTPUTS    :
DESCRIPTION: This function is triggered by the EOVBI it in order to treat
			the TELETEXT inside an IT, to avoid loosing time due to CHROMA
			and SOUND refresh..
*****************************************************************************/

⌨️ 快捷键说明

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