Stopwatch on 8051 to 1602 LCD display
Discussion in "8051 Discussion Forum" started by shawn Nov 14, 2007.
Wed Nov 14 2007, 01:46 am
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.
Thank you,
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 Wed Nov 14 2007, 02:24 am ]
Wed Nov 14 2007, 12:34 pm
you need not to send this 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.
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, 11:16 pm
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, 09:20 pm
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, 11:13 pm
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..
it should be
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..
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, 11:32 pm
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!
Powered by e107 Forum System