Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

16f84 lcd clock

Status
Not open for further replies.

Ricardoco

New Member
Hi All,
Does anyone have a sample basic program to simulate a digital clock on an lcd it dosnt have to be very accurate i just want to play with it a bit im using a 16f84a..Thanks :D :D (24hr format if possible but 12 hr is just as good) it is more the output to the lcd i want rather than the accuracy..thanks again.. :D
 
Ricardoco said:
Hi All,
Does anyone have a sample basic program to simulate a digital clock on an lcd it dosnt have to be very accurate i just want to play with it a bit im using a 16f84a..Thanks :D :D (24hr format if possible but 12 hr is just as good) it is more the output to the lcd i want rather than the accuracy..thanks again.. :D

Have a look at my tutorials, they give reliable fast LCD routines.

I've also got some simple code for using tmr2 (in a 16F628 or 16F876/6) generating a digital clock on an LCD - if you PM me your email address (or email from my website) I can send it you.

I would suggest, as I always do, that you drop the obselete 16F84A and use it's more modern replacement, the 16F628 - again, checking my tutorials will explain why!.
 
ok ive managed to get some output to the lcd that appears to look like time ticking away the thing im having a problem with is displaying the value "00" if i add 1 to a variable it displays "1" on the lcd i would like it to display "01" im using basic but i think i can work through an assembler reply thankyou. :)
 
Ricardoco said:
ok ive managed to get some output to the lcd that appears to look like time ticking away the thing im having a problem with is displaying the value "00" if i add 1 to a variable it displays "1" on the lcd i would like it to display "01" im using basic but i think i can work through an assembler reply thankyou. :)

In assembler you just decide to display the leading '0', in fact you would have to write extra code in order to supress it. Your BASIC compiler probably generates extra code to supress it, you may have to write your own display routines rather than using the BASIC ones - unless you can tell the compiler not to supress leading zero's, and also to only show two digits!.

You could always do it within BASIC though, something like this pseudo code:

Code:
IF Variable is less then zero THEN
  Print "0"
  Print Variable
ELSE
  Print Variable
 
ok well here is what i have
Code:
Set_Defaults PROTON_4	' board using a 4MHz crystal
Device = 16F84A
Declare LCD_TYPE 0 
Declare LCD_DTPIN PORTb.4 
Declare LCD_ENPIN PORTb.2 
Declare LCD_RSPIN PORTb.3 
DECLARE LCD_INTERFACE 4 
DECLARE LCD_lINES 2


DIM HOUR WORD
DIM MINS WORD
DIM SECS WORD
HOUR = 00
MINS = 1
SECS = 0
Main:
SECS=SECS + 1
IF SECS > 59 THEN 
   		  	 SECS = 00
			 MINS=MINS + 1
ENDIF
IF MINS > 59 THEN 
   		  	 MINS = 00
			 HOUR=HOUR + 1
ENDIF
IF HOUR > 23 THEN  
   		  	 HOUR = 00
ENDIF
CLS
PRINT AT 1,3, ":"
PRINT AT 1,6, ":"
PRINT AT 1,1,DEC HOUR
PRINT AT 1,4,DEC MINS
PRINT AT 1,7,DEC SECS
'PRINT AT 2,1, "ABCDEFGH"

DELAYMS 1000

goto Main

i think you are right again i will try it
 
Ok nigel you were right and it works a treat. could be a nice example for someone should they want to see how the clock is working and displays on the lcd i had to do a bit of jiggling to move the digits to the right when it was only a single figure but it works yee haa :) Please remember this is only a simulation and i in no way suggest you use it to tell the time in its current format lol :D

Code:
Device = 16F84A
Declare LCD_TYPE 0 
Declare LCD_DTPIN PORTb.4 
Declare LCD_ENPIN PORTb.2 
Declare LCD_RSPIN PORTb.3 
DECLARE LCD_INTERFACE 4 
DECLARE LCD_lINES 2
DIM ZERO WORD
DIM HOUR WORD
DIM MINS WORD
DIM SECS WORD

HOUR = 0
MINS = 0
SECS = 0
ZERO = 0
Main:
SECS=SECS + 1

IF SECS > 59 THEN 
   		  	 SECS = 0
			 MINS=MINS + 1
ENDIF
IF MINS > 59 THEN 
   		  	 MINS = 0
			 HOUR=HOUR + 1
ENDIF
IF HOUR > 23 THEN  
   		  	 HOUR = 0
ENDIF

PRINT AT 1,3, ":"
PRINT AT 1,6, ":"
IF HOUR < 10 THEN
             PRINT AT 1,2,DEC HOUR
             PRINT AT 1,1, "0"
ELSE
             PRINT AT 1,1,DEC HOUR
ENDIF

IF MINS < 10 THEN
             PRINT AT 1,5,DEC MINS
             PRINT AT 1,4, "0"
ELSE 
             PRINT AT 1,4,DEC MINS
ENDIF

IF SECS < 10 THEN
             PRINT AT 1,7, "0"
             PRINT AT 1,8,DEC SECS
ELSE
             PRINT AT 1,7,DEC SECS
ENDIF

DELAYMS 1000

goto Main

:D :D
 
this program will display clock on 7-segs
its very very simple may be helpful for you :)
Code:
#include <16F877.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=10000000)
#byte hr=6
#byte min=7
#byte s=8




main()
{

set_tris_b(0b00000000);
set_tris_c(0b00000000);
set_tris_d(0b00000000);

while(1)
{
int l1,l2,l3;
int har[12]={1,2,3,4,5,6,7,8,9,16,17,18};
int sar[60]={0,1,2,3,4,5,6,7,8,9,16,17,18,19,20,21,22,23,24,25,32,33,34,35,36,37,38,39,40,41,48,49,50,51,52,53,54,55,56,57,64,65,66,67,68,69,70,71,72,73,80,81,82,83,84,85,86,87,88,89};

for(l1=0;l1<12;l1++)
{
hr=har[l1];

for(l2=0;l2<60;l2++)
{
min=sar[l2];



for(l3=0;l3<59;l3++)
{
s=sar[l3];
delay_ms(1000);
s=sar[59];
 }
}
}



}
}
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top