Mikroc, Library example – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 230

Advertising
background image

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

222

MikroElektronika: Development tools - Books - Compilers

page

Library Example

unsigned short

error, ErrorCount, IdleCount, temp, LetterCount;

void

main() {

ErrorCount = 0;

TRISC = 0;

// Error indicator

PORTC = 0;

Man_Receive_Config(&PORTD, 6);

// Synchronize receiver

Lcd_Init(&PORTB);

// Initialize LCD on PORTB

while

(1) {

// Endless loop

IdleCount = 0;

// Reset idle counter

do

{

temp = Man_Receive(error);

// Attempt byte receive

if

(error)

ErrorCount++

else

PORTC = 0;

if

(ErrorCount > 20) {

// If there are too many errors

ErrorCount = 0;

// syncronize the receiver again

PORTC = 0xAA;

// Indicate error

Man_Receive_Init(&PORTD);

// Synchronize receiver

}

IdleCount++;

if

(IdleCount > 18) {

// If nothing received after some time

IdleCount = 0;

// try to synchronize again

Man_Receive_Init(&PORTD);

// Synchronize receiver

}

} while (temp != 0x0B);

// End of message marker

if

(error != 255) {

// If no error then write the message

Lcd_Cmd(LCD_CLEAR);

LetterCount = 0;

while

(LetterCount < 17) {

// Message is 16 chars long

LetterCount++;

temp = Man_Receive(error);

if

(error != 255)

Lcd_Chr_Cp(temp)

else

{

ErrorCount++; break;

}

}

temp = Man_Receive(error);

if

(temp != 0x0E)

ErrorCount++;

}

// end if

}

// end while

}

//~!

Advertising
This manual is related to the following products: