Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

serial communication in Atmel 89c51

Status
Not open for further replies.

Peter Nabil

New Member
Hi all,,,
I just wanted to inquire about the serial communication in Atmel 89c51,
In fact I wrote a simple program to communicate with a GPS module, and then display the data on a LCD, the longitude is…., the latitude is…, the altitude is …., blah blah blah,
The weird action is I forgot to connect the MC with the module, and guess what ?!!
I found the LCD display the longitude is …….., the latitude is ….., the altitude is …., blah blah blah ,
So? How that happened? I think the MC couldn't pass the serial communication part if it didn't get any data at the Rx pin,
Am I right or what?!!
Please somebody help me !

 
It sounds like there's a problem with your code. If you use the flags RI and TI you should be able to make it wait to receive something before it displays.
 
bmcculla said:
It sounds like there's a problem with your code. If you use the flags RI and TI you should be able to make it wait to receive something before it displays.

:lol: that's why i went crazy , i was using RI and TI flags !!!! :shock:
 
Dear bmcculla here is the code and thx for your support

Mov A, # 40 H ; Transfer “@”
Lcall Trans
Mov A, #40 H ; Transfer “@”
Lcall Trans
Mov A, # 45H ; Transfer “E”
Lcall Trans
Mov A, #71H ; Transfer “q”
Lcall Trans
Mov A, # 00H ; Transfer “r” output rate
Lcall Trans
Mov A, # 34 H ; Transfer checksum
Lcall Trans
Mov A, # 0D H ; Transfer < SR >
Lcall Trans
Mov A, # 0A H ; Transfer < LF>
Lcall Trans

Mov R2, #96 ; Load counter
Mov R0, # 30 H ; Load pointer R0 =30 RAM address
Nina: JNB RI, Nina ; Wait for char. to come in
Mov A, SBUF ; Save incoming byte in A
Mov @R0, A ; Copy A to RAM location R0 points to
INC R0 ; Increment R0 pointer
CLR RI ; Get ready to receive next byte
DJNZ R2, Nina ; decrement and jump to Nina if it is not Zero






Mov A, #38 H ; Init LCD 2 lines, 5*7 Matrix
LCALL Command ; Issue command
LCALL Sarah ;

Mov A, # 'D' ; Display letter D
LCALL Romeo
Mov A, # ' a'
LCALL Romeo
Mov A, #'t'
LCALL Romeo
Mov A, #' e'
LCALL Romeo
LCALL Is

Mov R2, #09 ; Load counter
Mov R0, #35 H ; Load pointer R0= 35H RAM address
LCALL Juliet
LCALL Sarah

Mov A, #'T' ; Display letter T
LCALL Romeo
Mov A, #'i'
LCALL Romeo
Mov A, #'m'
LCALL Romeo
Mov A, #'e'
LCALL Romeo
LCALL Is

Mov R2, #09 ; Load counter
Mov R0, 3E H ; Load pointer R0 = 3E RAM address
LCALL Juliet
LCALL Sarah

Mov A, #'L' ; Display letter L
LCALL Romeo
Mov A, #'a'
LCALL Romeo
Mov A, #'t'
LCALL Romeo
Mov A, #'i'
LCALL Romeo
Mov A, #'t'
LCALL Romeo
Mov A, #'u'
LCALL Romeo
Mov A, #'d'
LCALL Romeo
Mov A, #'e'
LCALL Romeo
LCALL Is
Mov R2, #13 ; Load counter
Mov R0, #47H ; Load pointer R0= 47 RAM address
LCALL Juliet
LCALL Sarah

Mov A, #'L'
LCALL Romeo
Mov A, #'o'
LCALL Romeo
Mov A, #'n'
LCALL Romeo
Mov A, #'g'
LCALL Romeo
Mov A, #'i'
LCALL Romeo
Mov A, #'t'
LCALL Romeo
Mov A, #'u'
LCALL Romeo
Mov A, #'d'
LCALL Romeo
Mov A, #'e'
LCALL Romeo
LCALL Is
Mov R2,# 14 ;Load counter
Mov R0, #54H ; Load pointer
LCALL Juliet
LCALL Sarah


Mov A, #'H'
LCALL Romeo
Mov A, #'e'
LCALL Romeo
Mov A, #'i'
LCALL Romeo
Mov A, #'g'
LCALL Romeo
Mov A, #'h'
LCALL Romeo
Mov A, #'t'
LCALL Romeo
LCALL Is
Mov R2,# 09 ;Load counter
Mov R0, #62H ; Load pointer
LCALL Juliet
LCALL Sarah
Mov A, #'S'
LCALL Romeo
Mov A, #'p'
LCALL Romeo
Mov A, #'e'
LCALL Romeo
Mov A, #'e'
LCALL Romeo
Mov A, #'d'
LCALL Romeo
LCALL Is
Mov R2,# 05 ;Load counter
Mov R0, #6BH ; Load pointer
LCALL Juliet
LJMP Again;
Sarah: Mov A, #0E H ; LCD on, cursor on
LCALL Command ; issue command
Mov A, #01 H ; Clear LCD command
LCALL Command ; issue command
Mov A, #06 H ; Shift cursor right
LCALL Command ; issue command
Mov A, #80 H ; Force cursor at the beginning of the 1st
;line
LCALL Command ; issue command
RET

Is: Mov A, #' '
LCALL Romeo
Mov A, #'i'
LCALL Romeo
Mov A, #'s'
LCALL Romeo
Mov A, #':'
LCALL Romeo
Mov A, # 40 H ; Force cursor at the beginning of the2nd line
LCALL Command
RET

Juliet: Mov A, @R0 ; Move contents of RAM location @R0 to A
LCALL Romeo
INC R0 ; increment pointer
DJNZ R2, Juliet ;
LCALL LCD_Delay
RET

Command: ACALL Ready
Mov P1, A
CLR P2.5
CLR P2.6
SETB P2.7
CLR P2.7
RET

Romeo: ACALL Ready
Mov P1, A
SETB P2.5
CLR P2.6
SETB P2.7
CLR P2.7
RET

Ready: SETB P1.7
CLR P2.5
SETB P2.6
Back: CLR P2.7
SETB P2.7
JB P1.7, Back
RET

Delay:Mov R4,#230
Here:Nop
Nop
DJNZ R4, Here
RET

DDelay: Mov R5, #02
Delayy: Mov R4, # 230
Hero: Nop
Nop
DJNZ R4, Hero
DJNZ R5, Delayy
RET

LCD_Delay: Mov R4, #07
Pet: Mov R5, #255
Mag: Mov R6, #255
Hera: NOP
NOP
DJNZ R6, Hera
DJNZ R5, Mag
DJNZ R4, Pet
RET

Delai: Mov R4, #114
Herb: NOP
NOP
DJNZ R4, Herb
RET
Thx again
 
iam sorry here is the Trans subroutine

Trans: Mov SBUF, A ; Load SBUF
Robert: JNB TI, Robert ; Wait for last bit to transfer
CLR TI ; Get ready for next bit
RET
 
Try clearing RI before the receive segment.

It's very hard to understand your code. It's a good idea to name your labels names that relate to what they do. It makes it easier for some one else to understand what the label is for. It also helps if you comment segments of code with information about what the segment does. If you rename all your people labels and put a short comment about what each subroutine does it will be much easier to help you.
 
Peter Nabil said:
iam sorry here is the Trans subroutine

Trans: Mov SBUF, A ; Load SBUF
Robert: JNB TI, Robert ; Wait for last bit to transfer
CLR TI ; Get ready for next bit
RET
You should wait for TI to be a 1 before you write to SBUF. If the baud rate is correctly programmed it should be a one before the first character is sent. If it's not then you can set it to a 1, one time only at initialization. When you find that it is equal to 1 then clear it and write to SBUF.
Code:
Trans: jnb  TI,Trans
       clr  TI
       mov  SBUF,A
       ret
 
Last edited:
Please Help

Hi Dear

I`m also working on a project in which i have to display GPS data on an LCD.but uptil now i`m unable to do this.can u help me ???
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top