// LCDKeypad.c // Program to test LCD and keypad. // For project using USB interface with Bootloader #include #include "lcd.h" #include "keypad.h" #include "delays.h" unsigned char outchar,key; unsigned char p1; char Message1 [ ] = "Option number : "; // Defining a 20 char string char Message2 [ ] = "Cooking.......... "; char Message3 [ ] = "Press 1 to 4 "; char Message4 [ ] = "Temperature "; void main(void) { int i; char decimal; long int num; lcd_init(); // Initialise LCD module { lcd_write_cmd(0x80); // Move cursor to line 1 position 1 for (i = 0; i < 20; i++) //for 20 char LCD module { outchar=Message1[i]; lcd_write_data(outchar); // write character data to LCD } lcd_write_cmd(0xC0); // Move cursor to line 2 position 1 for( i = 0; i < 1; i++) { key=getkey(); // waits and get an ascii key number when pressed p1=key; lcd_write_data(key); //display on LCD } if (p1 == '1' || p1== '2' || p1 == '3' || p1 == '4') { lcd_write_cmd(0x80); for (i=0;i < 20; i++) { outchar = Message2 [i]; lcd_write_data(outchar); } TRISA = 0b00000000; PORTA = 0b00000010; lcd_write_cmd(0x01); if(p1 == '1') { delay_ms(600000); } else { if(p1 == '2') { delay_ms(700000); } else { if(p1 == '3') { delay_ms(800000); } else { delay_ms(90000); } } } PORTA = 0b00000001; key=getkey(); // waits and get an ascii key number when pressed p1=key; if (p1 == '1') { PORTA = 0b00000000; } TRISD = 0x00; // Set PORTD to be output PORTD = 0x00; // Initialise PORTD LEDs to zeros /* Initialise analog to digital conversion setting */ ADCON0 = 0b00000010; // bit5-2 0000 select channel 0 conversion // bit1 A/D conversion status bit // 1- GO to starts the conversion // 0 - DONE when A/D is completed // bit0 Set to 1 to power up A/D ADCON1 = 0b00001100; // bit5 reference is VSS // bit4 reference is VDD // bit3-0 AN2 to AN0 Analog, the rest Digital ADCON2 = 0b00010110; // bit7 : A/D Result Format. 0 Left, 1 Right justified // bit5-3 : 010 acquisition time = 4 TAD // bit2-0 : 110 conversion clock = Tosc / 16 for (i=0;i < 20; i++) { lcd_write_cmd(0x01); outchar = Message4 [i]; lcd_write_data(outchar); } lcd_write_cmd(0xC0); // Move cursor to line 2 position 1 for (i=0;i < 20; i++) { lcd_write_cmd(0x01); outchar = ADRESH; lcd_write_data(outchar); } } else { lcd_write_cmd(0x80); for (i=0;i < 20; i++) { outchar = Message3 [i]; lcd_write_data(outchar); } } } }