Hi .
I am doing a Project in 8052 McU.i need to have two serial port so i thought of writing soft UART with any two GPIO..i selected P3.2,P3.3 of 8052..can anyone help me...i got some rough idea about the Software..but for a fully complted one i need ur help..can any one have sample code..am confused with serial data controlling i mean how to mimic the functionalit of SCON regster..i dnt even knw wheter it s required or not..pls help someone..
Thanks a lot man..actually in between am in my way to finish my code my own.i just asked for code just to check whether its correct or not.am a bit confused with the SCON functionality since am a beginner only.i will post my half done code along with just check.
#include<reg52.h>
#define RX1 P1^2 #define TX1 P1^3
unsigned char data SBUFF; sbit data TFLG;
void external_interrupt(void) interrupt 0 {
//Function body }
void rev_fn(void) { unsigned char cp_dat,tr=0,rcd;
cp_dat=RX1; while(tr<8) { rcd=(0x80&RX1)?1:0; cp_dat=cp_dat<<1; tr++; } TFLG=1; SBUFF=rcd; } void tx_fn(void) { unsigned char cp_dat,tr=0,txd;
cp_dat=SBUFF; while(tr<8) { TX1=(0x80&dat)?1:0; cp_dat=cp_dat<<1; tr++; } TFLG=1; } void main() { TMOD=0x02; TH0=0xFD; SCON=?; TR0=1; IE=0x81; while(1); }
There are many examples available, just use 'google' or similar.
Like an 20 year old application note for the 80c751 derivative which can be found:
Duplex UART Routines for the 751/752" from 8/20/1992
smartdata.usbid.com/.../an446.pdf
That example works, but it is a little bit weak in concept, it could work at higher baudrate and more reliable; but you will locate these things yourself if you fully unserstand how that is done, won't you?
View all questions in Keil forum