KeyScan.c
上传用户:xhjmsc
上传日期:2019-09-13
资源大小:389k
文件大小:6k
源码类别:

传真(Fax)编程

开发平台:

C/C++

  1. /***************************************
  2. Program:     Key Scan
  3. Author:      Bryan Cai
  4. Date:        2007.04.11
  5. ***************************************/
  6. #include "includeH.h"
  7. void KeyScan(void)
  8. {
  9.     unsigned char ucKeyValue=0xff;
  10.     //unsigned char ucBlockCnt=0;
  11.     //unsigned char ucRxIndex=0;
  12.     //unsigned int wPageAddress=0;
  13.   //Ring Number+-
  14.       if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ||
  15.          ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
  16.          ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
  17.          ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode) )//||
  18.          //((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
  19.       {
  20.         //VIEWLEDPORT |= bitViewLED;
  21.         if ((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ucKeyValue=0;
  22.         if ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ucKeyValue=1;
  23.         if ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode)     ucKeyValue=2;
  24.         if ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode) ucKeyValue=3;
  25.         //if ((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal) ucKeyValue=4;
  26.         
  27.         switch (ucKeyValue)
  28.         {
  29.       //if ((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec)
  30.        case 0:
  31.        {
  32.          delay1us(0x0530);//300000);
  33.          if ((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec)
  34.          {
  35.           if (gucViewRingNum>0)--gucViewRingNum;//RingNumMax--
  36.           //ViewCommunicationTX(0x01);
  37.           //ViewCommunicationRX();
  38.          }
  39.           break;
  40.        }//case 0
  41.       
  42.         
  43.       //if ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd)
  44.         case 1:
  45.         {
  46.          delay1us(0x0530);
  47.          if ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd)
  48.           { 
  49.             if (gucViewRingNum<9)++gucViewRingNum;//RingNumMax++
  50.             //ViewCommunicationTX(0x01);
  51.             //ViewCommunicationRX();
  52.           }
  53.           break;
  54.          }//case 1
  55.       
  56.       //ModeSel Key scan: auto or manual send fax signal
  57.       //if ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode)//bitKeyAutoMode==0
  58.         case 2:
  59.         {
  60.            delay1us(0x0530);
  61.            if ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode)
  62.             {
  63.              gucViewStaticStatus |= bitViewAutoMode;//Auto Mode
  64.              gucViewStaticStatus &= ~bitViewManualMode;//
  65.              gucViewStaticStatus |= bitViewRingNum;
  66.             
  67.              //ViewCommunicationTX(0x01);
  68.              //ViewCommunicationRX();
  69.             }
  70.             break;
  71.         }//case 2
  72.       //if ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode)
  73.         case 3:
  74.         {
  75.            
  76.            delay1us(0x0530);
  77.            if ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode)
  78.             {
  79.              gucViewStaticStatus |= bitViewManualMode;//Manual Mode
  80.              gucViewStaticStatus &= ~bitViewAutoMode; //off atuo
  81.              gucViewStaticStatus &= ~bitViewRingNum;//off ring num
  82.             
  83.              //ViewCommunicationTX(0x01);
  84.              //ViewCommunicationRX();
  85.             }
  86.             break;
  87.         }//case 3
  88.         
  89.         }//switch
  90.       //Driver LCD screen
  91.       if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ||
  92.          ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
  93.          ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
  94.          ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode) )
  95.          //|| ((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
  96.        {
  97.           ViewCommunicationTX(0x01);
  98.           
  99.           ReadAndWriteViewDataMemory();
  100.         }   
  101.       
  102.       if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ||
  103.          ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
  104.          ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
  105.          ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode))
  106.          //|| ((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
  107.       { 
  108.       while (1)
  109.       {
  110.        if (((KEY_PORT_IN & bitKeyRingNumDec) == bitKeyRingNumDec) &&
  111.          ((KEY_PORT_IN & bitKeyRingNumAdd) == bitKeyRingNumAdd) &&
  112.          ((KEY_PORT_IN & bitKeyAutoMode) == bitKeyAutoMode) &&
  113.          ((KEY_PORT_IN & bitKeyManualMode) == bitKeyManualMode)) //&&
  114.          //((KEY_PORT_IN & bitKeySendFaxSignal) == bitKeySendFaxSignal))
  115.          {
  116.            delay1us(0x7530);
  117.            if (((KEY_PORT_IN & bitKeyRingNumDec) == bitKeyRingNumDec) &&
  118.                ((KEY_PORT_IN & bitKeyRingNumAdd) == bitKeyRingNumAdd) &&
  119.                ((KEY_PORT_IN & bitKeyAutoMode) == bitKeyAutoMode) &&
  120.                ((KEY_PORT_IN & bitKeyManualMode) == bitKeyManualMode))// &&
  121.                //((KEY_PORT_IN & bitKeySendFaxSignal) == bitKeySendFaxSignal))
  122.                break;
  123.          } 
  124.       }
  125.       //VIEWLEDPORT &= ~bitViewLED;
  126.       }
  127.       
  128.       }
  129. }
  130. void ReadAndWriteViewDataMemory(void)
  131. {
  132.           unsigned char ucBlockCnt=0;
  133.         unsigned char ucRxIndex=0;
  134.         unsigned int wPageAddress=0;
  135.         //ReadLast16BytesFromFlashMemoryArea(cstViewDataAreaStartBlockNum,cstViewDataAreaOverBlockNum);
  136.           ReadLastViewData();
  137.           if ((gwGeneralPageAddress>>6) > cstViewDataAreaOverBlockNum)
  138.          {
  139.           for (ucBlockCnt=0;ucBlockCnt<2;ucBlockCnt++)
  140.             {
  141.                wPageAddress=(cstViewDataAreaStartBlockNum+ucBlockCnt)<<6;
  142.               ROW_ADDRESS_LOW=wPageAddress & 0XFF;
  143.               ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF; 
  144.               ERASE_ONE_BLOCK();
  145.             }
  146.             gwGeneralPageAddress=cstViewDataAreaStartPage;
  147.             gwColumnAddress=0;
  148.           }
  149.            ucRxIndex=0; //write view data
  150.            aucUartRxBuf[ucRxIndex++]=gucViewRingNum;
  151.            aucUartRxBuf[ucRxIndex++]=gucViewStaticStatus;
  152.            aucUartRxBuf[ucRxIndex++]=gucViewDynamicStatus;
  153.            aucUartRxBuf[ucRxIndex++]=gucViewDceNewFaxNum;//gucIcon2;
  154.            for (ucBlockCnt=0; ucBlockCnt<12; ucBlockCnt++)
  155.             {
  156.              aucUartRxBuf[ucRxIndex++]=0x55;
  157.             }
  158.            Write16Bytes2FlashMemoryArea();