#include <main.h>

#include <2408.C>

#define LCD_ENABLE_PIN PIN_B2
#define LCD_RS_PIN PIN_B0
#define LCD_RW_PIN PIN_B1
#define LCD_DATA4 PIN_B4
#define LCD_DATA5 PIN_B5
#define LCD_DATA6 PIN_B6
#define LCD_DATA7 PIN_B7
#include <lcd.c>
 
 
unsigned int keys;
void main()
{
	setup_adc_ports(NO_ANALOGS, VSS_VDD);
	init_ext_eeprom();

    lcd_init();
	output_low(pin_c1);																	// set this pin low
	while(TRUE)
	{
		keys=input_a();																		// wait for key to be pressed
		if( keys>0 )
			{
				while (input_a());															// wait for button to be released
				while(input(pin_c2));																// wait for memory busy to clear
				output_high(pin_c1);														// set memory busy this end
				write_ext_eeprom( 0x00, keys);													// write the data value to memory in byte 0;
			    delay_ms(12);																// allow eeprom to store
				output_low(pin_c1);														// clear memory busy this end
				printf(lcd_putc,"\f 0= %2X ", keys);								// display keys value
			}

		if(input(pin_c2))																	// memory busy signal
			{
				while(input(pin_c2));														// wait for memory busy to clear
				lcd_gotoxy(1,2);															// display on line 2
			    delay_ms(12);																// allow eeprom to store
     		    printf(lcd_putc," 1= %2X ", read_ext_eeprom(0x01));	// show memory byte 1 value			
			}


	}
 
}
