- /***************************************
- Program: Key Scan
- Author: Bryan Cai
- Date: 2007.04.11
- ***************************************/
- #include "includeH.h"
- void KeyScan(void)
- {
- unsigned char ucKeyValue=0xff;
- //unsigned char ucBlockCnt=0;
- //unsigned char ucRxIndex=0;
- //unsigned int wPageAddress=0;
- //Ring Number+-
- if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ||
- ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
- ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
- ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode) )//||
- //((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
- {
- //VIEWLEDPORT |= bitViewLED;
- if ((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ucKeyValue=0;
- if ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ucKeyValue=1;
- if ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ucKeyValue=2;
- if ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode) ucKeyValue=3;
- //if ((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal) ucKeyValue=4;
- switch (ucKeyValue)
- {
- //if ((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec)
- case 0:
- {
- delay1us(0x0530);//300000);
- if ((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec)
- {
- if (gucViewRingNum>0)--gucViewRingNum;//RingNumMax--
- //ViewCommunicationTX(0x01);
- //ViewCommunicationRX();
- }
- break;
- }//case 0
- //if ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd)
- case 1:
- {
- delay1us(0x0530);
- if ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd)
- {
- if (gucViewRingNum<9)++gucViewRingNum;//RingNumMax++
- //ViewCommunicationTX(0x01);
- //ViewCommunicationRX();
- }
- break;
- }//case 1
- //ModeSel Key scan: auto or manual send fax signal
- //if ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode)//bitKeyAutoMode==0
- case 2:
- {
- delay1us(0x0530);
- if ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode)
- {
- gucViewStaticStatus |= bitViewAutoMode;//Auto Mode
- gucViewStaticStatus &= ~bitViewManualMode;//
- gucViewStaticStatus |= bitViewRingNum;
- //ViewCommunicationTX(0x01);
- //ViewCommunicationRX();
- }
- break;
- }//case 2
- //if ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode)
- case 3:
- {
- delay1us(0x0530);
- if ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode)
- {
- gucViewStaticStatus |= bitViewManualMode;//Manual Mode
- gucViewStaticStatus &= ~bitViewAutoMode; //off atuo
- gucViewStaticStatus &= ~bitViewRingNum;//off ring num
- //ViewCommunicationTX(0x01);
- //ViewCommunicationRX();
- }
- break;
- }//case 3
- }//switch
- //Driver LCD screen
- if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ||
- ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
- ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
- ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode) )
- //|| ((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
- {
- ViewCommunicationTX(0x01);
- ReadAndWriteViewDataMemory();
- }
- if (((KEY_PORT_IN & bitKeyRingNumDec) != bitKeyRingNumDec) ||
- ((KEY_PORT_IN & bitKeyRingNumAdd) != bitKeyRingNumAdd) ||
- ((KEY_PORT_IN & bitKeyAutoMode) != bitKeyAutoMode) ||
- ((KEY_PORT_IN & bitKeyManualMode) != bitKeyManualMode))
- //|| ((KEY_PORT_IN & bitKeySendFaxSignal) != bitKeySendFaxSignal))
- {
- while (1)
- {
- if (((KEY_PORT_IN & bitKeyRingNumDec) == bitKeyRingNumDec) &&
- ((KEY_PORT_IN & bitKeyRingNumAdd) == bitKeyRingNumAdd) &&
- ((KEY_PORT_IN & bitKeyAutoMode) == bitKeyAutoMode) &&
- ((KEY_PORT_IN & bitKeyManualMode) == bitKeyManualMode)) //&&
- //((KEY_PORT_IN & bitKeySendFaxSignal) == bitKeySendFaxSignal))
- {
- delay1us(0x7530);
- if (((KEY_PORT_IN & bitKeyRingNumDec) == bitKeyRingNumDec) &&
- ((KEY_PORT_IN & bitKeyRingNumAdd) == bitKeyRingNumAdd) &&
- ((KEY_PORT_IN & bitKeyAutoMode) == bitKeyAutoMode) &&
- ((KEY_PORT_IN & bitKeyManualMode) == bitKeyManualMode))// &&
- //((KEY_PORT_IN & bitKeySendFaxSignal) == bitKeySendFaxSignal))
- break;
- }
- }
- //VIEWLEDPORT &= ~bitViewLED;
- }
- }
- }
- void ReadAndWriteViewDataMemory(void)
- {
- unsigned char ucBlockCnt=0;
- unsigned char ucRxIndex=0;
- unsigned int wPageAddress=0;
- //ReadLast16BytesFromFlashMemoryArea(cstViewDataAreaStartBlockNum,cstViewDataAreaOverBlockNum);
- ReadLastViewData();
- if ((gwGeneralPageAddress>>6) > cstViewDataAreaOverBlockNum)
- {
- for (ucBlockCnt=0;ucBlockCnt<2;ucBlockCnt++)
- {
- wPageAddress=(cstViewDataAreaStartBlockNum+ucBlockCnt)<<6;
- ROW_ADDRESS_LOW=wPageAddress & 0XFF;
- ROW_ADDRESS_HIGH=(wPageAddress>>8) & 0XFF;
- ERASE_ONE_BLOCK();
- }
- gwGeneralPageAddress=cstViewDataAreaStartPage;
- gwColumnAddress=0;
- }
- ucRxIndex=0; //write view data
- aucUartRxBuf[ucRxIndex++]=gucViewRingNum;
- aucUartRxBuf[ucRxIndex++]=gucViewStaticStatus;
- aucUartRxBuf[ucRxIndex++]=gucViewDynamicStatus;
- aucUartRxBuf[ucRxIndex++]=gucViewDceNewFaxNum;//gucIcon2;
- for (ucBlockCnt=0; ucBlockCnt<12; ucBlockCnt++)
- {
- aucUartRxBuf[ucRxIndex++]=0x55;
- }
- Write16Bytes2FlashMemoryArea();
- }