free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
oreo
Wed Jun 25 2008, 08:54AM
 User Offline
Registered Member #5492
Joined: Tue Jan 15 2008, 09:40AM

Posts: 4
Thanked 0 times in 0 posts
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


Back to top


Arun Kumar V
Wed Jun 25 2008, 06:13PM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 521
Thanked 218 times in 185 posts
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
 
Back to top



This post has been thanked 1 time
 oreo 
oreo
Thu Jun 26 2008, 04:06AM
 User Offline
Registered Member #5492
Joined: Tue Jan 15 2008, 09:40AM

Posts: 4
Thanked 0 times in 0 posts
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?
Back to top


Arun Kumar V
Thu Jun 26 2008, 06:11AM

 User Offline
Registered Member #426
Joined: Sun Jan 28 2007, 11:50PM

Posts: 521
Thanked 218 times in 185 posts
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
Back to top



This post has been thanked 1 time
 oreo 
oreo
Fri Jun 27 2008, 08:17PM
 User Offline
Registered Member #5492
Joined: Tue Jan 15 2008, 09:40AM

Posts: 4
Thanked 0 times in 0 posts
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.
Back to top


oreo
Mon Jun 30 2008, 08:49AM
 User Offline
Registered Member #5492
Joined: Tue Jan 15 2008, 09:40AM

Posts: 4
Thanked 0 times in 0 posts
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
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems