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..
hi,
Thanks for ur reply,
first of all my need is to create a half duplex virtual UART for my 8052.this code is not a full version,i know its not even close.am a fresher in MCU programming.i got 2 days time from my senior to complete this,and my time will end by this Saturday evening.am a bit desperate to complete it on time.am giving timer 0 to put delay in between individual bits.and setting up baud rates i also need the TH0 of timer 1 i believe.i have googled it but i was a bit misguided.
1.taking one interrupt 2.setting one timer for delay 3.sending individual bits 4.start stop condition
is this much necessary for it.
This is a duplicate of another therad, which school do yu attend? e-mail address, please
Thanks for ur reply you do not need a microresistor (ur) for a soft UART
Erik
namees.majeed@gmail.com this is my email id..wat u mean by my school?see am just in a begning stage
#include<reg52.h> #include<stdio.h>
sbit TX1=P3^3;
unsigned char SBUFF; bit TFLG;
void delay(unsigned char num) { unsigned char i,j; for(i=0;i<num;i++) for(j=0;j<1275;j++) ; } void transmit_vir(unsigned char dat) { unsigned char tx=0,cp_data;
cp_data=dat; TX1=0; TR0=1; while(TF0==1); TR0=0; while(tx<8) { TX1=(0x80&dat)?1:0; TR0=1; while(TF0==1); TR0=0; cp_data=cp_data<<1; tx++; } TFLG=1; TR0=1; while(TF0==1); TR0=0; TX1=1; } void main() { TMOD=0x02; TH0=0xFD; while(1) { delay(25); transmit_vir('a'); while(TFLG==1); TFLG=0; delay(25); }
}
Half duplex communication for virtual serial port..only TX is being implemented.is this correct
www.danlhenry.com/.../keil_code.png
ok i wil do it here after.
No, your code isn't correct.
Do you really feel that you are fulfilling what you see if you read this link? en.wikipedia.org/.../RS-232
hi, thanks for u r response,i read the link u provided.Am actually a bit confused collecting data bit wise.am suing only 3 line from serial to USB connector. 1.a sample data collection UART algorithm,sub routine after listening to External interrupt pin(P3.2)
void recev() routine to recieve { unsigned char r=0; bit sbuff[8]; if(P3.2==0) //start bit detection while(r<8) { sbuff[r]=P3.2; r++; TR0=1; while(TF0==1); //delay in between bits Timer 0 is used TR0=0; } if(P3.2==1) //stop bit condition achieved TFLG=1; //flag to indicate the receive has completed } void transmit_vir(unsigned char dat) //a simple transmisson algorithm { unsigned char tx=0,cp_data; cp_data=dat; TX1=0; //start bit TR0=1; //timer start while(TF0==1); TR0=0; while(tx<8) { TX1=(0x80&dat)?1:0; //8-bit data TR0=1; while(TF0==1); TR0=0; cp_data=cp_data<<1; tx++; } TFLG=1; //transmission flag TR0=1; //baud rate while(TF0==1); TR0=0; TX1=1; //stop bit }
while transimisson which only i copiled and burned to my MCU i got a 'FC' data on my hyper-terminal..read so many articles in google they are telling for a simple communication handshaking is not required. that's y i developed like this since my need is urgent Tomorrow is my dead line..
If your dead line is to morrow then may be you should consi der stop bits.
And another thing - are you sure your code uses the same bit order as the other side for your data bits?
i need result rather than time.i have provided stop bits there...then one more thing is hyper terminal has a specific code to accept data.i mean whether LSB or MSB which should go out first.is my logic correct which i implemented here..any comments..since no one here to guide me as well
Why you ask? Did you read the link I posted?
You really have stop bits? And how many bit times do you hold your stop bits? And what is your delay after the while loop, but before your "stop bit" line?
while transimisson which only i copiled and burned to my MCU i got a 'FC' this could be the result of badly mismatched send and receive. set it to transmit 'U' (uppercase U) continously and scope the output.
No, I am not going to tell you what to look for, If you can't figure that out, you should not have started this project.
eric am not asking to any one to help me in my code..am askng about for exper opinion..do architechture play any role in it..
now i rewrote my code:
here i took ACC^0 to store LSB and send it out..and so on finally MSB.. and a delay with timer0 in 8 bit auto reload mode..to get bit gap in between..and for start and stop bits as well...
i referd bit bagging in wiki and followed the same procedure..and implemented in my code..
is this delay genration relable or i have to put a couple of loops to generate one..
am askng about for exper opinion you got that read the replies above