You are on page 1of 3

Error Correction Program

The following error correction program is developed using C language:

sbit LCD_RS at RB4_bit;

sbit LCD_EN at RB5_bit;

sbit LCD_D4 at RB0_bit;

sbit LCD_D5 at RB1_bit;

sbit LCD_D6 at RB2_bit;

sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;

sbit LCD_EN_Direction at TRISB5_bit;

sbit LCD_D4_Direction at TRISB0_bit;

sbit LCD_D5_Direction at TRISB1_bit;

sbit LCD_D6_Direction at TRISB2_bit;

sbit LCD_D7_Direction at TRISB3_bit;

int fault, watchdog, sum, n;

unsigned int set_time = 20;

sum = 0;

char display[7];

void main() {

ADCON1 = 0x00;

TRISA = 0xFF;

TRISB = 0;
TRISD = 0;

PORTD = 0;

Lcd_Init();

Delay_ms(500);

while(1){

fault = ADC_READ(0);

if (fault > 100){

PORTD = 0xFF;

watchdog = set_time * fault;

for (n = 0; n < watchdog; n++){

sum = sum + watchdog – fault;

if (sum > = set_time){

sum = 0;

break;

} else {

sum ++;

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(1,1, "Fault detected....");

Delay_ms(10000);

Lcd_Out(2,1, "Identify fault.....");


Delay_ms(10000);

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(1,1,"Error correction");

Delay_ms(10000);

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(1,1,"Done....");

Delay_ms(5000);

Lcd_Out(1,1,"Resume");

Delay_ms(5000);

PORTD = 0;

else{

Lcd_Cmd(_LCD_CLEAR);

Lcd_Cmd(_LCD_CURSOR_OFF);

Lcd_Out(1,1, "Alarm OK");

Delay_ms(500);