#include <REG51KJ.h> #include <stdlib.h> void serial_init() { TMOD = 0x20; //set timer 1 mode to 8-bit-auto-reload SCON = 0x50; //enable reception , det serial port mode to 8-bit UART REN ENABLE PCON |= 0x80; //set mode 2 by seting SMOD TH1 = 0xF3; //set baudrate to 9600 at 24 MHZ crystal TL1 = 0xF3; TR1 = 1; //start Timer } void delay(unsigned int msec)//delay { int i,j; for(i=0;i<msec;i++); for(j=0;j<1275;j++); } void serial_send(unsigned char dat) { while(!TI); //wait for data to be send completely TI = 0; //clr Transmit interrupt flag SBUF = dat; //move data to send in SBUF } /********************************************/ void main(void) { serial_init() ; for(;;) { delay(10); serial_send('A'); //send char 'A' through rs232 across } }
This code has nothing specifically to do with Hyperterminal; so be sure to make it clear that Hyperterminal is just an example - not a particular requirement.
serial_send('A'); //send char 'A' through rs232 across
Similarly, this has nothing specifically to do with RS232 - that depends on external hardware, and has nothing to do with the code.