#include #include "io.h" #include "eeprom.h" unsigned char serialActivity; unsigned char messageType; unsigned char receiveCount; // Delay function void timeDelay(int num) { int i,j; for(i=0; i> 8); // 65000 RCAP2L = (unsigned char)(65223); //65000 T2CON = 0x34; SCON = 0x40; P3 |= 0x03; REN = 1; } unsigned char receiveData() { RI = 0; while( 1 ) { if( RI == 1 ) { return SBUF; } } } void sendChar(unsigned char c) { TMOD = 0x20; /* configure timer for the correct baud rate */ TH1 = 0xe6; /* 1200 bps for 12 MHz clock */ TCON = 0x00; /* Set timer to not running */ SCON = 0x40; /* "0100_0000" indicates sending data*/ TR1 = 1; /* start timer */ SBUF = c; /* write character to SBUF */ while( (SCON & 0x02) == 0 ) { } return; } // Routine to scan the key pressed unsigned char key_scan() { unsigned char i, j; while( 1 ) { if(serialActivity == 1) return 1; for(i=0; i<4; i++) { // Set each row to 0 P1 = 0xff & ~(1< 57 ); PutChar('*'); timeDelay(5000); } ClearScreen(); //checks user password if( checkPassword(password,passTotal) == 0 ) { messageCount = 1; messageIndex = 0; getMessage(mydata, messageCount); displayMessage(mydata,messageIndex); //wait here till a message is selected while(wait) { do { keyPressed = conv_table[key_scan()]; } while(keyPressed != 101 && keyPressed != 102 && keyPressed != 103); timeDelay(5000); //view next message if( keyPressed == 101 ) { if(messageCount == messTotal) { messageCount = 1; } else { messageCount++; } messageIndex = 0; getMessage(mydata,messageCount); displayMessage(mydata,messageIndex); } //scroll message on screen else if( keyPressed == 102 ) { messageIndex++; displayMessage(mydata,messageIndex); } //send message else { wait = 0; ClearScreen(); displayMessage("Sending..... ",0); sendChar(messageCount); timeDelay(1000); sendChar(messageCount); timeDelay(10000); timeDelay(10000); timeDelay(10000); } } } //if user enters a invalid password else { PrintString("Invalid"); timeDelay(10000); timeDelay(10000); } } //if no message in storage else { displayMessage("No Messages",0); timeDelay(10000); } wait = 1; } //This means a serial interrupt occurred. else { //checks to see if interrupt is junk if(messageType != 3) { //getting the message number if(messageType == 1) { address = receiveData(); } //receiving data for(i=0; i messTotal) { messTotal++; updateTotals(messTotal,0); } } //if password else { newPassword(mydata,passTotal); passTotal++; updateTotals(passTotal,1); } } } } } }