- CODE: SELECT_ALL_CODE
void store_EEPROM(unsigned char data, unsigned char location); //eeprom
unsigned char get_EEPROM(unsigned char location);
unsigned char reverse=0;
unsigned char blackspot=0x00; //location in eeprom//memory map
unsigned char crack;
unsigned char y;
unsigned char z=0;
unsigned char thousand;
unsigned char hundred;
unsigned char tenth;
unsigned char unit;
void main(void)
{
TRISA = 0b00000011; //configure PORTA I/O direction
TRISB = 0b00000000; //configure PORTB I/O direction
TRISC = 0b00000000;
TRISD = 0b00000000;
TRISE = 0b00000000;
PORTA = 0x00; //clearing all ports before use
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PORTE = 0x00;
CMCON = 0x07; //disable all the comparators
ADCON1 = 0x06; //configure PORTA as digital I/O
send_config(0b00000001); //clear display at lcd
send_config(0b00000010); //lcd return to home
send_config(0b00000110); //entry mode-cursor increase 1
send_config(0b00001100); //display on, cursor off and cursor blink off
send_config(0b00111000);
thousand = countAB / 1000;
countAB = countAB % 1000;
hundred = countAB / 100;
countAB = countAB % 100;
tenth = countAB / 10;
unit = countAB % 10;
CCP1CON = 0b00001100;
CCP2CON = 0b00001100;
PR2 = 0xFF; //PWM Period Setting (4.88KHz)
T2CON = 0b00000101;
While(1)
{
if(LSS05==1 && reverse ==0) //when LSS05 detects black spot
{
store_EEPROM(thousand,blackspot);
store_EEPROM(hundred,blackspot+1);
store_EEPROM(tenth,blackspot+2);
store_EEPROM(unit,blackspot+3);
buzzer=1; //buzzer will make noise for 100Us then off
DelayUs(1000);
buzzer=0;
blackspot+=0x10;
}
if(countAB==0) //when countAB reaches 0
{
lcd_clr();
for(y=0x00;y<0x04;y++)
{
crack=get_EEPROM(y);
lcd_goto(z);
send_char(crack);
z+=1;
}
z+=1;
for(y=0x10;y<0x14;y++)
{
crack=get_EEPROM(y);
lcd_goto(z);
send_char(crack);
z+=1;
}
z+=1;
for(y=0x20;y<0x24;y++)
{
crack=get_EEPROM(y);
lcd_goto(z);
send_char(crack);
z+=1;
}
}
//============================================================================================================================
// EEPROM FUNCTION
//============================================================================================================================
//store data into specified loaction in EEPROM
void store_EEPROM(unsigned char data, unsigned char location)
{
EEPROM_WRITE(location,data); //write data
while(WR) //wait until it finish
continue;
}
//============================================================================================================================
//access EEPROM to retrieve data
unsigned char get_EEPROM(unsigned char location)
{
unsigned char value;
value= EEPROM_READ(location); //read eeprom and assign the data to variable
return value; //return data
}
//============================================================================================================================