Home - Search - Members
Full Version: serial interfacing doubt.
oreo
Jun 25 2008, 8:54 AM
hi, i'm trying to learn how to programme a simple serial interfacing using 8051. I found this programme from a site that uses 8051 and visual basic. before implementing the real hardware i would like to try in a simulator. I'm using EdSim51 simulator to try the programme, but it doesn't look like the programme is working. This programme is used to ON/OFF the LED in port 1.7. This is the programme that i modified a litttle bit to suits the EdSim51 simulator. Can anyone help me with this problem?

ORG 00H
MOV TMOD,#20H
MOV TH1,#0FDH
MOV TL1,#0FDH
MOV SCON,#50H
SETB TR1

READ: JNB RI,READ
MOV A,SBUF
CJNE A,#0FFH,CLEAR
CLR RI

WAIT: JNB RI,WAIT
MOV A,SBUF
CJNE A,#00H,NXT
CLR P1.7
SJMP DOWN

NXT: CJNE A,#01H,DOWN
SETB P1.7

CLEAR: CLR RI
SJMP HERE
END
Arun Kumar V
Jun 25 2008, 6:13 PM
Hello Oreo,

in your program you are comparing the incoming characters to some fixed ones and switching LED on/off.

you have defined some labels/segments which are not present in your code like :

ORG 00H
MOV TMOD,#20H
MOV TH1,#0FDH
MOV TL1,#0FDH
MOV SCON,#50H
SETB TR1

READ: JNB RI,READ
MOV A,SBUF
CJNE A,#0FFH,CLEAR
CLR RI

WAIT: JNB RI,WAIT
MOV A,SBUF
CJNE A,#00H,NXT
CLR P1.7
SJMP DOWN

NXT: CJNE A,#01H,DOWN
SETB P1.7

CLEAR: CLR RI
SJMP HERE
END


data sent over serial port will be in ASCII format, so its better to compare with known ASCII letters than HEX values for eg: a b c


a modified code looks like this:

CODE:
ORG 00H

MOV TMOD,#20H
MOV TH1,#0FDH
MOV TL1,#0FDH
MOV SCON,#50H
SETB TR1

SETB P1.7

READ: JNB RI,READ
MOV A,SBUF
CLR RI
CJNE A,#'A',NOTA       ;  if it is "A" then the LED glows
CLR P1.7
SJMP READ

NOTA: CJNE A,#'B',READ
SETB P1.7                   ; if its "B"  LED is off
SJMP READ                 ; if you enter any other letters/nums it just ignores

END
 
oreo
Jun 26 2008, 4:06 AM
thank u so much for replying. one question is, the data transmitted is in ASCII right? So should i send an 'A' or 41H instead? i try it in Edsim51 simulator. It is a free simulator that i downloaded.It has quite an interesting diaplay to use. But it does'nt seem to work in both data that I transmitted in the external UART panel. Am i doing it all wrong?
Arun Kumar V
Jun 26 2008, 6:11 AM
Hello Oreo,

you can either use 'A' or 41H, because the compiler ultimately converts all Ascii, Decimal, binary values into hex.

i had used Edsim51 last year,it looked good but not very flexible. the code i gave works well and has been tested on some other sim called 80513 Simulator. here are the test results:

When 'A' is pressed - P1.7 is 0






When 'B' or any other letter is pressed P1.7 is 1




i'll try it on Edsim51 tonight..........

one more thing, in our forum we have a Thanks giving Button, if you find the replies helpful you can press the Thanks button


Arun
oreo
Jun 27 2008, 8:17 PM
hai arun. i did'nt notice the thanks button. hehehe anyway i have downloaded the simulator u mentioned and i will i try it. Once again thanks.
oreo
Jun 30 2008, 8:49 AM
hai. this the vb source code that i mentioned before. I have modified a little bit based on your given code. Do you think it's ok?

Private Sub Form_Load()
On Error Resume Next
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.DTREnable = False
MSComm1.PortOpen = True
End Sub

Private Sub cmdsend_Click()
Dim LED As Long
If opton.Value = True Then
LED = A
Else
LED = B
End If
MSComm1.Output = Char$(LED)
End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Rickey's World © 2003 - 2007