Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

digital clock using picbasic pro

Status
Not open for further replies.

jojokatada

Full Member level 5
Joined
Jan 13, 2005
Messages
255
Helped
19
Reputation
38
Reaction score
4
Trophy points
1,298
Activity points
2,122
how to load tmr1 register with 3037

hi everyone i want to make digital clock using picmcu display on the lcd with time and date. i have found some website but it is not written in pbp and posted in hex file so i could not use the subroutine.
i also found in edaboard forums but mostly not sutiable for my project



http://hobby_elec.piclist.com/e_clock_v2.htm


**broken link removed**


please help the schematic and subroutine

appreciate
 

pic basic clock

Do you know how to use the timer/counters of the PIC?

If yes then now you can create a digital clock.

A digital clock is nothing but a loop adn an increment routines and reset routines.

I think PICBasic has ready routines for interfacing into an LCD and keypad.
 

picbasic clock

Hi !

Once I created a digital binary clock (with leds for time and day of the week) using a 16F628(A). Using LCDs with PBP is easier because you don´t have to worry about multiplexing leds, just use LCDOUT command and DEFINE the pins connected to LCD.

I think 16F628(A) is very suitable for your project. You can use PBP but the precision timing routine must be in assembly (inserted in the basic program). I used an interrupt from the TMR1. Load TMR1 registers with defined values and everytime TMR1 overflows 2 times (every 0.5s in my project) increase the seconds variable. The interrupt routine should be in assembly because basic has latency to interrupts, what can compromise the precision. No need of more than one xtal (I use 4MHz XT for the main oscillator), but the PIC oscillator must be Xtal, as ceramic resonator and RC or internal oscillators are not adequate for the clock.

In the basic routines, just create variables for hour, minutes, seconds and date. Increment and clear the variables when certain values are reached. Just it. A routine to adjust and set values must be done. Use 3 buttons to do it. One of them calls the adjustment routine, the two remaining select and set values. One option is to connect a buzzer to an I/O port to make an audible alarm.
 

accurate time base picbasic pro

hi rkodaira

could you share your code.
i mean the subroutine?
 

digital clock using picbasic

Hi Jojo !

Sure I can give you my interrupt code (insert it in beginning of the basic program):

ASM
Myint
MOVWF wsave
SWAPF STATUS,W
CLRF STATUS
MOVWF ssave
MOVF PCLATH,W
MOVWF psave
MOVLW 221
MOVWF TMR1L
MOVLW 11
MOVWF TMR1H
BCF PIR1,0
INC halfsec
BTFSS halfsec,1
GOTO xxx
CLRF halfsec
INC unsec
xxx MOVF psave,W
MOVWF PCLATH
SWAPF ssave,W
MOVWF STATUS
SWAPF wsave,F
SWAPF wsave,W
BSF interr,0
RETFIE

ENDASM

=============================================
And these basic lines:

INTCON = %11000000 'enable GIE and PEIE
T1CON = %00110101 'Configure TMR1 with clock/4 and prescaler 1/8
PIE1.0 = 1 'enable interrupt TMR1 overflow

================================================
wsave, psave, ssave are byte variables (system)
halfsec, unsec and interr are byte variables
interr is just a flag variable that says if the interrupt routine was run (useful if you are in a basic routine and need to go to interrupt inicialization lines)

Note that first of all, the interrupt routine saves the W, PCL and Status contents and restore them after the main routine is run.

The routine works with 4MHz main clock. So each instruction will spend 1us
I load the TMR1 registers with value 11*256+221 = 3037, so the TMR1 will overflow after 65536 - 3037 = 62499 counts. As I set the prescaler to 1/8, it means that 62499 counts will spend 62499*8 periods of clock/4 = 62499 * 8us = 499992 us, just add 8us spent until the MOVLW TMR1L and you have the 500000 us = 0.5s accurate counting. Just add an auxiliar variable (halfsec) and increment the unsec (unit of seconds) variable every two counts on halfsec. You have the unsec variable incremented every 1s. Unsec is the base for the rest of the clock. Each time unsec reaches 60, you clear it and increment minutes variable, the same with minutes variable. each time it reaches 60, you increment hours variable, and so on. Just send the variables to the LCD.
 

16f628 timer interrupt picbasic

appreciate for the sourcecode but i have a hardtime to understand its
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top