This program will read a complete line coming through my COM port in 8051.
This is the subroutine or function in c for accept line from serial port
void get_line(void)
{
char c, index=0;
while(c = getchar() != '\n')
{
buffer[index++] = c;
}
}
The main program
void main()
{
PCON = 0x80; // Double Baud Rate
SCON = 0x50; // SCON: mode 1, 8-bit UART, enable rcvr
TMOD |= 0x20; // TMOD: timer 1, mode 2, 8-bit reload
TH1 = BAUD_CONST; // TH1: reload value for desired baud. Calculate this for your crystal frequency
TR1 = 1; // TR1: timer 1 run
TI = 1;
RI = 0;
get_line(); //function call
}
REFERENCE BOOKS
No comments:
Post a Comment