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

Thu Jun 11 2020, 06:27 AM
anudee
sir could please send the code for I2C and wifi interfacing with 8051
scena
Tue May 19 2020, 10:29 PM
Does anyone have microcontroller programming software for STC15F104W (core 8051, 4 k, 128 byte, 6 I/O pin, UART ... DIL8), that works?
Sat May 02 2020, 07:38 PM
Tamu Gurung
Hi I am looking for a assembly language program for a digital decimal counter. Time counts max limit of 2 mins starting from 2.00 mins and ending at 0.00. time is to be displayed on 4 7-segment LED displays. Edsim51 simulator to be used. Thanks
Wed Mar 25 2020, 01:39 PM
Tajammul
Sir kindly send the code file i2c for 8051
ExperimenterUK
Fri Mar 13 2020, 10:36 PM
@ Rohitnani,ABEBE..which project ?
Fri Mar 13 2020, 12:55 PM
ABEBE
how can get hadwere of this project
Rohitnani
Sat Mar 07 2020, 05:11 PM
Sir, Could you please send me the zip file input password....
Wed Feb 26 2020, 04:58 PM
Peter Parker
Is it possible to send multiple messages using only 1 GSM module?
Sat Feb 01 2020, 10:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 06:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.

Downloads

Comments

Mirza123
Thu Jun 25 2020, 03:46 PM
eunicelove124
Mon Jun 22 2020, 03:03 PM
cerouno
Tue Jun 16 2020, 05:10 PM
Marce
Sat Jun 13 2020, 09:43 PM
Davidthils
Thu May 21 2020, 12:44 PM
Jakeror
Thu May 21 2020, 01:28 AM
motorCar
Wed May 20 2020, 07:05 PM
Vordrync
Wed May 20 2020, 11:52 AM

Online

Guests: 46, Members: 0 ...

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

Members: 38215
Newest member: Mirza123
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jul 01 2020, 11:07 PM
PS: I am a new learner thats why my question may s...
Mirza123 Avatar
Posted By Mirza123
Wed Jul 01 2020, 02:05 PM
Thanks for the assistance. I have read the data sh...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jul 01 2020, 10:12 AM
See section 15 (Ports) of the data sheet. ...
wimac Avatar
Posted By wimac
Tue Jun 30 2020, 10:05 AM
How did you know that it is not 8051. Mirza123It i...
Mirza123 Avatar
Posted By Mirza123
Tue Jun 30 2020, 08:39 AM
It seems ports on the AT89LP2052 is not like on th...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Jun 30 2020, 08:34 AM
It seems ports on the AT89LP2052 are not like on t...
Mirza123 Avatar
Posted By Mirza123
Thu Jun 25 2020, 04:07 PM
Hello!i am trying to use AT89LP2052 ( AT89LP2052 h...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jun 17 2020, 09:42 PM
It is about capacitor? i should put it between Vcc...
cerouno Avatar
Posted By cerouno
Wed Jun 17 2020, 10:37 AM
Take another look at the power supply to the LCD.A...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Jun 17 2020, 02:01 AM
Take another look at the power supply to the LCD.A...