Discussion in "8051 Discussion Forum" started by    Gastonio    Sep 9, 2010.
Mon Oct 11 2010, 11:06 am
#21
hi Gastonio
u have to use uart with rx interrupt when a 1 character is received from pc CPU get interrupt that charters has reached place it from sbuf register to any safe location otherwise it will be overwritten to next on coming character
when serial interrupt occur cpu goes to 223h location and execute code from that location

here is the sample code


org 0000h
jmp main

org 0023h
ajmp serial

main:
mov r0,#7fh          ;clear all ram location
zero:
mov @r0,#00h
djnz r0,zero
mov r0,#30h
mov tmod,#20h        ;timer mode
mov scon,#50h
mov th1,#0fdh        ;baud rate 9600 @ 11.0592mhz
mov tl1,#0fdh        ;baud rate 9600 using 8051
setb tr1
mov ie,#90h          ;interrupt enable register
setb f0
back:
jb f0,$              ; waiting here for end of string
setb f0              ; set it again for next cycle
; here u has to comparing or what u want 
; string first byte is at 30h next to 32 h and so on .....
; where null comes that mean nw reading has to be end 
; string finish
jmp back                
                

serial:
mov a,sbuf          ; move to save location
mov @r0,a
jz exit             ; check is it null (0) means end of string 
inc r0              ; next byte sav to next position
clr ri              ; clear flag for next time
reti                ; return from interrupt ISR

exit:               ; if last character is zero then point to string 1st location
mov r0,#30h
clr f0              ; clear to detect in main that complete string has reached in specific locations
clr ri              ; clear flag for next time
reti                ; return from interrupt ISR

end


 Gastonio like this.
Mon Oct 11 2010, 01:06 pm
#22
sory i want to clear on thing that is typing mistake
i write 223h location
that is infact 23h location
Tue Oct 12 2010, 11:55 pm
#23
Is there another way to do that? I mean without external interrupts. This is the fragment of program I tried to write. It's like receiving single character and storing it in the memory location then receiving another and storing it in INC R0 location till the A is 0.

BOUDRATE:
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1, #0FDH
SETB TR1
RET

RECEIVER:
CALL BOUDRATE
MOV R0, #30H
LOOP1: JNB RI, LOOP1
CLR RI
MOV A, SBUF
MOV @R0, A
INC R0
JNZ LOOP1
RET



[ Edited Tue Oct 12 2010, 11:56 pm ]
Wed Oct 13 2010, 12:08 am
#24
hi
u can do it using polling method as u do above but it is preferable to use interrupt
also it depend on ur application if u application is to wait for receive data then polling can be used if u have to done other tasks too along with reception of character than interrupt method is used

modify ur code a little
RECEIVER:
CALL BOUDRATE
MOV R0, #30H
LOOP1: JNB RI, LOOP1
MOV A, SBUF
MOV @R0, A
INC R0
CLR RI
JNZ LOOP1
CLR RI
RET
Wed Oct 13 2010, 12:34 am
#25
Well, don't have to do anything else, just receive string and send string. I am writing a username and password entering routine. First the string is send to the terminal asking for the username input and after username is entered, program sends a string "password". I wrote an echo program, however I can't receive anything.
CHECK:
CALL RECEIVER
CALL SENDER
AJMP CHECK

BOUDRATE:
MOV SCON,#50H
MOV TMOD,#20H
MOV TH1, #0FDH
SETB TR1
RET

RECEIVER:
CALL BOUDRATE
MOV R0, #30H
LOOP1: JNB RI, LOOP1
CLR RI
MOV A, SBUF
MOV @R0, A
INC R0
JNZ LOOP1
RET

SENDER:
CALL BOUDRATE
MOV R0, #30H
GO: MOV A, @R0
MOV SBUF, A
LOOP2: JNB TI, LOOP2
CLR TI
INC R0
JNZ GO
RET

END
Wed Oct 13 2010, 12:43 am
#26
hi Gastonio
code is correct u can also use Proteus to see it and change the receiver function as i mention above
u don't need to call baud rate again and again just call it 1 time in start up after that u don't need it in all over the main loop
Wed Oct 13 2010, 12:50 am
#27
I thought that the code is correct too, however I burned it in an MCU and tried to send a string, but there was no answer. Maybe I have to clear all RAM locations like you did in your code? I tried my code without increasing R0 and without waiting till A is 0 and it worked. I guess the problem is because of A not coming to 0.
Wed Oct 13 2010, 09:41 am
#28
in normal softwares u use for communication that send string mean in ascii format
that send 0 as 30h ascii
here is the software i make it u can use it it send null at the end of ur message
first select the port u want to open then send data at the end close that and exit

Attachment


[ Edited Wed Oct 13 2010, 09:41 am ]
Wed Oct 13 2010, 02:11 pm
#29
I use "Termite" terminal program, so I could not only send, but receive text. The problem is that the program I posted above does not send text back to the terminal and I can't figure out where the problem is.
Wed Oct 13 2010, 02:44 pm
#30
ok daer Gastonio
i send u again the program then send and recieve also just i have to add one instruction in the code

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Williamjef
Thu Apr 25 2024, 02:08 pm
SamuelSmise
Thu Apr 25 2024, 09:56 am
DustinErele
Thu Apr 25 2024, 08:44 am
ztaletpzca
Wed Apr 24 2024, 11:19 pm
IrardlPex
Wed Apr 24 2024, 08:42 pm
Charlestehed
Wed Apr 24 2024, 05:20 pm
Robertgurse
Wed Apr 24 2024, 02:43 pm
Richardedils
Wed Apr 24 2024, 04:07 am