Discussion in "8051 Discussion Forum" started by    shawn    Nov 13, 2007.
Tue Nov 13 2007, 08:16 PM
#1
Hi,
I'm trying to use an 8051 to display a stopwatch function on to 1602 LCD display. I did all the programing and it looks good. Debugged it in keil and I went through each step and it should work, but somehow isn't.
I'm using an AT89C51RD2 with the code below:
Please check and tell me what is wrong with my code.
I've already verified that the microcontroller and LCD display is working properly as I am able to get it to display a test message.

;p1	LCD data pins
;p2.0	connected to RS pin
;p2.1	connected to R/W pin
;p2.2	connected to E pin

	org 	0h
	ljmp	main
	org 	30h
main:
	
	mov	r0,#0			;initializing seconds
	mov	r1,#0			;initializing minutes
	mov	r2,#0			;initializing hours
		
	;command codes for LCD		

	mov	a,#38			;2 lines and 5*7 matrix	
	acall	command
	mov	a,#0eh			;display on cursor blinking
	acall 	command
	mov	a,#01h			;clear display screen
	acall 	command
	mov	a,#06			;move cursor to right
	acall 	command
	mov	a,#80			;cursor start on first line
	acall 	command
	
abc:	mov	a,r2			;Display hours
	acall 	datadisplay
	mov	a,#06			;moving cursor
	acall	command
	mov	a,#':'			;display semi colon
	acall 	datadisplay
	mov	a,#06			;moving cursor 
	acall	command
	mov	a,r1			;Display minutes
	acall	datadisplay
	mov	a,#06			;moving cursor
	acall	command	
	mov	a,#':'			;display semi colon
	acall 	datadisplay
	mov	a,#06			;moving cursor
	acall	command	
	mov	a,r0			;Display seconds
	acall 	datadisplay

	mov	a,#80			;cursor start on first line
	acall 	command
	
	
	jb	p0.0,abc		;check for stopping the watch
	jb	p0.1,main		;p0.1 for resetting clock
	
time: 	;for timer
	acall 	delay			;i second delay
	inc	r0			;increamenting seconds after 1 second
	cjne	r0,#60,abc		;check if seconds are 60 or not
	mov	r0,#0			;if 60 seconds past than increament minute and initialize seconds to zero
	inc	r1	
	cjne	r1,#60,abc		;check if 60 minutes have been past or not
	mov	r1,#0			;if 60 seconds past than increament hours and initialize minutes to zero
	inc	r2
	cjne	r2,#24,abc		;check if hours are 24 (you can make it 12 hourse mode)
	mov	r2,#0			;if 24 than initializa it ot 0
	sjmp 	abc
	
delay: 	;delay in timer for 1 sec
	mov	r3,#46			;we have to make a delay of 921600 instructions
lop:	mov	r4,#50			;djnz take 2 instruction cycles
loop:	mov	r5,#50
loop1:	djnz	r5,loop1
	djnz	r4,loop
	djnz	r3,lop
	ret

command: ;to use in LCD
	acall 	ready
	mov	p1,a	
	clr	p2.0			;make RS 0 to execute command code on LCD
	clr	p2.1			;make R/W 0 for writing
	setb	p2.2
	clr	p2.2
	ret
datadisplay: ;to display data on LCD
	acall 	ready
	mov	p1,a
	setb	p2.0			;make RS 1 to execute data display on LCD
	clr	p2.1			;make R/W 0 for writing
	setb	p2.2			;high-to-low pulse to E pin of LCD
	clr	p2.2
	ret
ready: 	;for LCD that if it is ready
	setb	p1.7
	clr	p2.0
	setb	p2.1
back:
	clr	p2.2			;low=to-high pulse to LCD
	setb	p2.2
	jb	p1.7,back
	ret
	
end


Thank you,


[ Edited Tue Nov 13 2007, 08:54 PM ]
Wed Nov 14 2007, 07:04 AM
#2
you need not to send this command

        mov     a,#06                   ;moving cursor
        acall   command

because lcd will auto increment the DDRAM address...

and you cannot display two digits just like that..
first you need to convert it to decimal from hex and then separate them as higher and lower nibble after convert them to ascii to display them one by one.. take my clock project as reference.. you will get code for small hex to dec function.
your datadisplay and command functions are correct..
So do as i explained above to display digits on LCD.. if you need anymore assistance do tell me.
Wed Nov 14 2007, 03:17 PM
#3
where is the clock project?
Wed Nov 14 2007, 05:46 PM
#4
he is asking about the doubt he is having in his project... the code is given above.. u can see.. if you want other clock projects.. then check the download section..
Thu Nov 15 2007, 03:50 PM
#5
Removed "mov" line, and removed "time" section to test to see if it will at least display " : : ", but didn't get anything. Can anyone tell me why i'm not getting anything out? I've check multiple time and all connections are right according to code.
Thu Nov 15 2007, 05:43 PM
#6
The reason you are not getting anything on display is.. you are not displaying it on correct location its really a minor mistake but.. it matters a lot...
you wrote this..
	mov     a,#80			;cursor start on first line
	acall   command


it should be
	mov     a,#80H			;cursor start on first line
	acall   command

you forgot 'H' at in the move statement.. so compiler take 80 as decimal instead of hex.. try if you get something on display now..
Thu Nov 15 2007, 06:02 PM
#7
After hours of troubleshooting, found out that one of the registers on my 8051 is somehow not responding to any inputs or outputs, thus further add to the problem. Will get another one and re-try it. Will let you know results. Thanks though Ajay!, I wouldn't caught it!

Get Social

Information

Powered by e107 Forum System

Conversation

ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html
ExperimenterUK
Thu Jul 11 2019, 07:44 PM
@praveen123. Can you give a link to the project ?

Downloads

Comments

auwal
Tue Nov 19 2019, 03:13 PM
ANKITPATEL
Mon Nov 18 2019, 11:00 AM
Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM
baoyen123
Fri Nov 08 2019, 10:06 AM
xiwang
Fri Nov 08 2019, 07:28 AM

Online

Guests: 22, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 38105
Newest member: auwal
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 19 2019, 10:44 PM
The 8051 has too little memory to do anything us...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 18 2019, 09:54 AM
0v7670 camera interfacing with stc 8051.using asse...
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...