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.

problem with serial port interfacing

Status
Not open for further replies.

froten

Member level 3
Joined
Jun 17, 2006
Messages
56
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,798
Hello,

Im tring to write a program for AT89C51 that can send a stream of one character (which is 5) to the computer, I wrote this program but it doesn't work because I didn't see any signal going out from the Tx pin using the osciloscope. the program is as follows:

mov TMOD,#20
mov TH1,#-3
mov SCON,#50
SETB TR1
AGAIN:
mov a,"5"
acall TRANS
sjmp AGAIN
TRANS:
mov SBUF,a
HERE:
jnb TI,HERE
CLR TI
ret
end

the buad rate should be 9600 bps. I didn't actually connect the circuit to the computer because when I use the osciloscope I don't see any signal on the Tx pin. I have attached both the asm and hex files for more information.

Please any help on this issue is appreciated as it is very important for me to get it working.
 

budhy

Advanced Member level 3
Joined
Oct 21, 2006
Messages
828
Helped
218
Reputation
436
Reaction score
31
Trophy points
1,308
Location
Indonesia
Activity points
5,265
Try thos code :

Code:
   mov   TMOD,#$20
   mov   TH1,#-3
   mov   SCON,#$50
   SETB  TR1
AGAIN:
   mov   a,#"5"
   acall TRANS
   sjmp  AGAIN

TRANS:
   mov SBUF,a
HERE:
   jnb   TI,HERE
   CLR   TI
   ret
   end
 

froten

Member level 3
Joined
Jun 17, 2006
Messages
56
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Activity points
1,798
do you think that this code will work as is cost me to reprogram the MCU.
 

mmohamed15

Advanced Member level 4
Joined
Mar 23, 2005
Messages
112
Helped
5
Reputation
10
Reaction score
0
Trophy points
1,296
Activity points
2,116
what do you mean by it will cost you , r u paying money for programming tha mc?!
 

budhy

Advanced Member level 3
Joined
Oct 21, 2006
Messages
828
Helped
218
Reputation
436
Reaction score
31
Trophy points
1,308
Location
Indonesia
Activity points
5,265
do you think that this code will work
do you think that this code will not work?

Bassically your code is right, the problem is you don't put the hexadecimal prefix($), and immediate data prefix (#)

Here is the list of mistake you made :
Code:
   mov TMOD,#20
the purpose of this instruction is define TIMER1 as mode 2 (auto reload), but without $ prefix this instruction is define TIMER1 as mode 1 (and other TIMER0 setup bits).
It mean you don't have Baudrate Generator for the UART, so the serial port doesn't functioned.
Code:
   mov SCON,#50
the same error, cause wrong setup of UART!
Code:
 mov a,"5"
mean : move the content of memory number $35 to A
 

yali

Newbie level 6
Joined
Dec 31, 2006
Messages
12
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,346
why you don't use keil and c codes. it will solve a lot of your problems easily
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top