Sonsivri

Electronics => Pic Basic Languages => Topic started by: Leonardo on November 11, 2008, 04:38:08 16:38



Title: Clock, hours, minutes, seconds
Post by: Leonardo on November 11, 2008, 04:38:08 16:38
Hello friendly,

I want to do a clock with pic16f628 or some other pic that marks the hours, minutes and seconds. ¿Somebody of the forum has some example realized in picbasic pro?.

Thanks for its aid.


Title: Re: Clock, hours, minutes, seconds
Post by: bbarney on November 11, 2008, 05:21:35 17:21
Do your own searching,there are ton's of examples here and all over the internet if you just tried searching!
but here's a good one to start your lazy ass ;)



Title: Re: Clock, hours, minutes, seconds
Post by: fernandodiaz on November 12, 2008, 03:53:01 03:53
'here some sample clock timer0  proton plus   xtal 4mhz  output LCD   remplace   all  dims   Dim ticks   as     byte   for  var 
' and some directives lcd remplace print  for lcdout $fe read manual pbp   
 
Code:
'DECLARE WATCHDOG = off ' xtal 4mhz

      DEVICE = 16F877

       'device = 16f874a

        XTAL = 4

LCD_DTPIN = PORTb.4       

LCD_RSPIN = PORTb.2

LCD_ENPIN = PORTb.3

LCD_INTERFACE = 4 ' 4-bit Interface

LCD_LINES = 2

LCD_TYPE = 0



SCL_PIN = PORTe.0

        SDA_PIN = PORTe.1

SERIAL_BAUD = 9600

RSOUT_PIN = PORTb.0

RSOUT_MODE = INVERT

RSOUT_PACE = 1

'   dim contador as dword           

Dim MINUTO  as     byte    ' Define MINUTO variable

Dim SEGUNDO as     byte    ' Define SEGUNDO variable

Dim ticks   as     byte    ' Define pieces of seconds variable

Dim update  as     byte    ' Define variable to indicate update of LCD

Dim i       as     byte    ' Debounce loop variable



        Delayms 100        ' Wait for LCD to startup

                          ' Set initial time to 00:00:00

        MINUTO = 0

        SEGUNDO = 0

        ticks = 0

        update = 1      ' Force first display



        OPTION_REG = %1010111        ' Set TMR0 configuration and enable PORTB pullu

        INTCON = $A0            ' Enable TMR0 interrupts

            Cls       

       

        On Interrupt Goto Tickint '_________________Interrupcion___________________________ 



 

'____________________________

mainloop:

 

    If update = 1 Then

           ' Clear screen

Print AT 1,1,    dec2 MINUTO, ":", dec2 SEGUNDO

     update = 0      ' Screen updated           

    Endif





Goto mainloop    ' Do it all forever

       

 '______________________________   

        Disable          ' Disable interrupts during interrupt handler



Tickint:

tmr0 = 12 ' .0625s * 16 = 1 seg   36 microseg de error por tick o 576 microseg x seg

   

  ticks = ticks + 1          ' Count pieces of seconds

        If ticks < 16 Then tiexit       ' 16 ticks per SEGUNDO (.0625 per tick)





        ticks = 0

        SEGUNDO = SEGUNDO + 1

        If SEGUNDO >= 60 Then

           SEGUNDO = 0

MINUTO = MINUTO + 1

If MINUTO >= 60 Then

   MINUTO = 0             

    Endif

        Endif



        update = 1      ' Poner en lcd  update LCD



Tiexit: INTCON.2 = 0    ' Borrar bandera timer interrupt flag

        Resume


best regards


Title: Re: Clock, hours, minutes, seconds
Post by: Shinta on November 15, 2008, 11:11:59 23:11
Why you don't try the ds1307 ic commanded via I2C bus with 16f628. is too much easy an exactly.


Title: Re: Clock, hours, minutes, seconds
Post by: Biggles on November 16, 2008, 08:57:37 20:57
Many clocks on Google search for PIC Basic Pro, but here is a nice one I have used myself:


3 Button adjustment of a DS1307 RTC

"The circuit uses a PIC16F84 and a standard 16*2 LCD.
.. tested the program on the following Pic chips, 16F84, 16F628(7), 18F1320(1220) and 18F452(252). "

http://anonym.to/?http://wiki.picbasic.org/index.php?n=ThreeButtonadjustmentofaDS1307RTC.RTC (http://anonym.to/?http://wiki.picbasic.org/index.php?n=ThreeButtonadjustmentofaDS1307RTC.RTC)

Also easy to modify to SPI bus. I used it on a clock with good results using DS1305.

For clock only, a RTC is a little overkill. My application had a time display function when in standby, so I had to use a RTC. Very easy!