unsigned short counter=0;
void interrupt() {
if (INTCON.TMR0IF) {
if (counter >= 20) {
Soft_UART_Break();
counter = 0; // reset counter
}
else
counter++; // increment counter
INTCON.TMR0IF = 0; // Clear Timer0 overflow interrupt flag
}
}
void main(){
unsigned char error, datain, byte_read=0, i, k=100, j=9, l=200;
TRISB.F3=0;
TRISA=0;
PORTB=0;
PORTA=0;
ANSEL=0;
CMCON=7;
OSCCON=0B01001100;
OPTION_REG = 0x04; // TMR0 prescaler set to 1:32
TMR0=0;
INTCON.TMR0IE = 0; // Enable Timer0 overflow interrupt
for(i=0; i<3; i++){
PORTA=255;
Delay_ms(100);
PORTA=0;
Delay_ms(100);
}
error = Soft_UART_Init(&PORTB, 4, 5, 9600, 0);
Eeprom_Write(0x00, error);
if (error > 0) {
Eeprom_Write(0x01, error);
delay_ms(10);
/*PORTA=error; Delay_ms(30);
PORTA=0; Delay_ms(30);*/
while(1); // Stop program
}
Delay_ms(100);
while(1) { // Endless loop
INTCON.GIE = 1; // Global interrupt enable
INTCON.TMR0IE = 1; // Enable Timer0 overflow interrupt
byte_read = Soft_UART_Read(&error); // Read byte, then test error flag
INTCON.GIE = 0; // Global interrupt disable
INTCON.TMR0IE = 0; // Disable Timer0 overflow interrupt
if(error==0){
Eeprom_Write(j, byte_read); //save data in Eeprom
j+=1; if(j>200) j=9;
PORTA=3; Delay_ms(30);
Eeprom_Write(0x04, j); ////save number of characters in Eeprom
PORTA=0; Delay_ms(30);
PORTA = byte_read;
//Eeprom_Write(j, byte_read);
}
else Eeprom_Write(0x05, error); //save error message in Eeprom
}
}