Google

Jul 26, 2008

A C program for serial communation with pc using 8051

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

}

You might be also interested in:

:: options available for int 21h instruction
:: Answers of Microprocessor(8085) & Electronics FAQ
:: The 8085 Microprocessor Architecture Microprocessors & Interfacing

No comments: