Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

89C51 serial programming HELPL...

Status
Not open for further replies.

hussain_kiet

Full Member level 5
Joined
Mar 15, 2007
Messages
262
Helped
45
Reputation
90
Reaction score
28
Trophy points
1,308
Location
Karachi, Pakistan
Activity points
2,813
89c51 serial programmer

hi i am using AT89C51 uc with KIEL microvision 2 compiler i want to write to and read from serial port
i ve made the required circuit but still having problems (cant see the data written)
can anyone plzz tell me how could i write on serial port and how can i see the data written to serial port..??

this is my code

#include <reg51.h>
void sertx(unsigned char);
void main(void)
{

unsigned char z;
unsigned char aa[] = "MHWSQ";
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
while(1)
{
for(z=0;z<5;z++)
{
SBUF = aa[z];
while(TI == 0);
TI = 0;
}
}
}
 

ckshivaram

Advanced Member level 5
Joined
Apr 21, 2008
Messages
5,070
Helped
2,149
Reputation
4,304
Reaction score
2,089
Trophy points
1,393
Location
villingen (Germany) / Bangalore
Activity points
30,086
89c51 programming

Your program is correct and you get the output on the serial window. But you need MAX 232 IC. Connect TX and RX of controller to MAX232 and connect MAX 232 to PC with a serial cable. Use hyperterminal to see the output. Your program will work.
 

t_maggot

Member level 3
Joined
Nov 9, 2006
Messages
57
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
1,282
connect max232 to 89c51

I agree with ckshivaram you cant connect cmos or ttl levels direct to RS232.
RS232 is also a physical protocol working with +-15V. So be careful as you can easily blow-up UART pins of mcu's if you connect them directly! Take a look:
https://www.lammertbies.nl/comm/info/RS-232_specs.html#phys
 

hussain_kiet

Full Member level 5
Joined
Mar 15, 2007
Messages
262
Helped
45
Reputation
90
Reaction score
28
Trophy points
1,308
Location
Karachi, Pakistan
Activity points
2,813
well i ve used max232 ic but still cant see the output on the hyper terminal..
when i will connect my circuit then the hyper terminal will directly show the output
or i have to receive the file...???

and when i receive the file it shows garbage value..
 

t_maggot

Member level 3
Joined
Nov 9, 2006
Messages
57
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
1,282
First of all you have to configure the communications options in ht. For example 8bit data, 1 stop, no-parity, 9600 b/s, etc and ofcource select the right port. This have to match with your configurations on the mcu exactly. If this is ok, the input is shown directly in the ht screen. (receiving garbage probably means wrong configurations)
Anyway you can always check with an oscilloscope the tx pin of your mcu before and after the max232, so you can easy verify the levels and frequency of the signal
 

faraj

Member level 1
Joined
Feb 22, 2005
Messages
40
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Azarbaijan/ Tabriz
Activity points
1,600
hussain_kiet said:
#include <reg51.h>
void sertx(unsigned char);
void main(void)
{

unsigned char z;
unsigned char aa[] = "MHWSQ";
TMOD = 0x20;
TH1 = 0xFD;
SCON = 0x50;
TR1 = 1;
TI = 1;
while(1)
{
for(z=0;z<5;z++)
{
SBUF = aa[z];
while(TI == 0);
TI = 0;
}
}
}

hi. all the replyies are correct about serial communication and must be done before sending data. but there is some more thing. you must set the TI flag at the start of the program like I have corrected for you in your own code.
and beside this you can simply use printf instruction to send data to PC. like this:
printf ("MHWSQ\n");
hope that works.
Regards.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top