C51 COMPILER V7.09   MAIN                                                                  06/15/2006 17:47:33 PAGE 1   


C51 COMPILER V7.09, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE main.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          /*
   2          *********************************************************************************************************
   3          *                                                               KEYPAD AND UART DEBUG DEMONSTRATION PROGRAM
   4          *
   5          * File name             : main.c
   6          * Programmer    : John Leung, TechToys. Hong Kong
   7          * Web presence  : www.TechToys.com.hk
   8          * Note                  : 
   9          * Language              : Keil C 7.09 2K limited version under uVision2 IDE
  10          * Hardware              : AT89S52-gLCD-STK1
  11          * Date                  : Version 1.0 (7th June 2006)
  12          *********************************************************************************************************
  13          *                                                                                       DESCRIPTION
  14          *
  15          * This program checks for any key press on S1 (5-way navigator switch).
  16          * Key debounce achieved by simple software delay function DelayMs(xKEY_SCAN_TASK_DLY).
  17          * If key UP or DOWN pressed, the corresponding text message is transmitted via UART for debug purpose. 
  18          * Auto-repeat feature is enabled with UP/DOWN, so holding these keys would repeat sending text messages.
  19          * Similarly, text messages debug feature included for keys RIGHT, LEFT, and CENTRE, with auto-repeat
  20          * disabled. At the same time, an LED is blinked at a rate of 1/50ms (20Hz) to show the software loop
  21          * is running under the extreme conditions of a key hold.
  22          * Baud rate is 9600bps, Timer 1 is used as the baud rate generator
  23          * Standard library stdio.h is also included for printf function.
  24          * Code size is 1664 bytes is printf is used, else, the code is around 494 bytes
  25          *********************************************************************************************************
  26          */
  27          
  28          
  29          #include <REGX52.h>
  30          #include "xKey.h"
  31          #include "delay.h"
  32          #include <stdio.h>
  33          
  34          sbit LED = P2^0;
  35          
  36          /*
  37          *********************************************************************************************************
  38          *                                                               UART INITIALIZATION
  39          *
  40          * Description : This function initialize the UART port of 89S52. Timer 1 is used as the baud rate
  41          *                               generator with an external crystal frequency of 11.0592MHz onboard.
  42          *
  43          * Arguments   : none
  44          *                       
  45          * Returns     : none
  46          *********************************************************************************************************
  47          */
  48          void uartInit(void)
  49          {
  50   1              SCON  = 0x52;           //UART in 8 bit mode
  51   1              TMOD  = TMOD|0x20;  //Timer 1 configured for 8-bit auto-reload timer mode, Timer 0 unchanged
  52   1              TH1   = 0xfd;           //TH1 value for a baud rate 9600bps
  53   1              TR1   = 1;                      //Timer 1 is turned ON
  54   1      }
  55          
C51 COMPILER V7.09   MAIN                                                                  06/15/2006 17:47:33 PAGE 2   

  56          /*
  57          *********************************************************************************************************
  58          *                                                                                                       MAIN
  59          *********************************************************************************************************
  60          */
  61          void main (void){
  62   1              
  63   1                      unsigned char keyCode;
  64   1      
  65   1                      xKeyInit();
  66   1                      uartInit();
  67   1      
  68   1                      for(;;){
  69   2                      DelayMs(xKEY_SCAN_TASK_DLY);
  70   2                      xKeyScanTask();
  71   2                      if(xKeyHit())
  72   2                      {
  73   3                              keyCode = xKeyGetKey();
  74   3                              switch (keyCode)
  75   3                              {
  76   4                                      case xKEY_UP_FLAG:      xKeyRptEn=TRUE; 
  77   4                                                                              printf("Key Up Pressed \n");
  78   4                                                                              break;
  79   4                                      case xKEY_DN_FLAG:      xKeyRptEn=TRUE; 
  80   4                                                                              printf("Key Down Pressed \n");
  81   4                                                                              break;
  82   4                                      case xKEY_RT_FLAG:      xKeyRptEn=FALSE; 
  83   4                                                                              printf("Key Right Pressed \n");
  84   4                                                                              break;
  85   4                                      case xKEY_LT_FLAG:      xKeyRptEn=FALSE; 
  86   4                                                                              printf("Key Left Pressed \n");
  87   4                                                                              break;
  88   4                                      case xKEY_CTR_FLAG: xKeyRptEn=FALSE; 
  89   4                                                                              printf("Key Center Pressed \n");
  90   4                                                                              break;
  91   4                                      default:                        ;//inform user of an error, optional
  92   4                              }
  93   3                      }
  94   2                      LED = ~LED;
  95   2                      }
  96   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    108    ----
   CONSTANT SIZE    =     96    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)
