Accurate 32.768 k clock


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    peterk's Avatar
    peterk Guest


    Did you find this post helpful? Yes | No

    Default

    1. Arm yourself with the PICs Datasheet.

    ' Done

    2. Have a look at Section 5 - Timer1 Module

    ' Yep

    3. Have a look at section 5-1 T1CON... see if you can figure why I would set it to...

    T1CON=%00000001

    ' You enable Timer 1, allow it work

    4. Find TMR1H, TMR1L anf PIR1... see why I would load them thus...

    TMR1H=$E0
    TMR1L=$00
    PIR1.0=0

    ' You preload the timer with the hex value of E000
    ' You reset the Timer Overflow flag

    5. Read section 5.6 it might interest you...

    ' Very interesting that I can run the clok with the device in sleep
    ' mode, thus even less consumption

    6. Have a look at Bit 0 of PIR1 (Datasheet 2-5) what would this piece of code do?...

    While PIR.0=0:Wend

    ' It will will wait until PIR bit 0 = 1, or when the timer roll's over

    Answers to these questions will qualify you as a Timer1 expert, and gain you the appropriate shoulder badge...

    ' OK, so I will try the code....

    Very brief example (assuming your 32kHz clock)...

    code:--------------------------------------------------------------------------------
    LED var GPIO.0 ' Assign Led name to GPIO port 0

    TRISIO=%00000000 ' Set all ports as outputs

    ' Question..... does this affect the xtal ports 4,5 ?

    T1CON=%00000001 ' Set bit 0 High in T1Con

    Loop:
    TMR1H=$E0 ' Preload the High Byte with E0
    TMR1L=$00 ' Preload the Low Byte with 00
    PIR1.0=0 ' Reset the interupt flag
    Toggle LED ' Change the LED status, ie from on
    ' to off or off to on
    While PIR1.0=0:Wend ' wait for the roll over
    Goto Loop redo the whole process

    End
    --------------------------------------------------------------------------------

    *smiles*

    ' No smiles I' afraid
    ' I believe there are a few more things to do
    ' Some more registers to set
    ' I'll keep digging, and reading
    ' However, the above may help other persons as well

    Next step will be the Interrupt Navigators badge.... however, I think I've mentioned before that interrupts on a 12 series PIC are a bit limited...

    ' Woooha, interupts! Lots to learn, nice to get help!
    ' Will keep on
    ' Thanks, Peter
    Last edited by peterk; - 14th July 2004 at 23:10.

Similar Threads

  1. Single digit 7 Seg LED clock - PIC16F88
    By thirsty in forum Code Examples
    Replies: 4
    Last Post: - 17th July 2009, 08:42
  2. EM4095 Chip, get Clock and Data signals?
    By mindthomas in forum mel PIC BASIC Pro
    Replies: 14
    Last Post: - 19th August 2008, 06:27
  3. Accurate clock using 12C508
    By srob in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 28th September 2007, 09:19
  4. Shiftout/in
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 23rd August 2007, 11:48
  5. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts