Hello,
I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the microcontroller should display in the LCD the value of the voltage applied to the input of the ADC.
The above procedure should only execute once the user has entered "1234" using a keypad that is attached to the 8051 microprocessor.
I think I can figure out the keypad entry function that will wait until the user has entered "1234" before proceeding. Here is what I have for that part so far...
I havent tested it with a micro-controller yet but this code compiled using the Bipom Micro-Ide compiler.
#include #include #include
#define MAX_ROWS 4 #define MAX_COLS 4
static char KeyTable[] = { '1', '2', '3', 'A', '4', '5', '6', 'B', '7', '8', '9', 'C', '*', '0', '#', 'D' };
static unsigned char RowTable[] = { 0xFE, 0xFD, 0xFB, 0xF7 };
char ScanKeypad();
main() { char key;
serinit(9600); for( ;; ) {
key = ScanKeypad();
if( key == "1234" ) { printf( "\nKey: '%c'", key ); //Proceed with the rest of the program from here }
printf ("\nIncorrect Code Entered\n"); } }
char ScanKeypad() { char row; char col;
col = 0;
for( row=0; row>4) & 7 ) ); delay(1); WriteCtrl(pos & 0x0F); delay(1); } void CursorHome() { /* Cursor home */ WriteCtrl(0); delay(1); WriteCtrl(2); delay(1); } void WriteLCD( unsigned char* message ) { unsigned char i; for( i=0; i> 4 ); WriteCommon( value ); } void WriteCommon( unsigned char value ) { clrbit(READ); value = value & 0x0F; value = value