Newbie Question


Closed Thread
Results 1 to 15 of 15

Thread: Newbie Question

Hybrid View

  1. #1
    Join Date
    Feb 2006
    Posts
    89

    Default Newbie Question

    How do I make a RTC using tmr1 and 32 mhz crystal with out a dallas clock? I also need to be able to set time with buttons. Using pic 16f628a. Also can I send serial data on any port pin on only those labeled rx/tx? Not sure how to do all of that. I am new at this so please be gentle. Thanks for your help
    Last edited by Travin77; - 25th February 2006 at 01:14.

  2. #2
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Travin77,

    See this post

    http://www.picbasic.co.uk/forum/showthread.php?t=2129

    It describes how to make a “RTC” without a RTC chip using a 4.0MHz xtal and TMR0. The approach can easily be modified for other xtal frequencies and TMR1. The first program in the referenced post has some button routines for setting the initial time.

    The RX and TX Pins can be connected to the on-board hardware USART (via register settings). To use these two pins in this manner, you can use the HSERIN and HSEROUT commands. If you do not need the capabilities of the USART, you can use any pin that can be made an output (including the pins marked RX and TX) and the DEBUG, SEROUT, or SEROUT2 commands or any pin that can be made an input and the SERIN and SERIN2 commands. See the manual and datasheet for more information on this. Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

  3. #3
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Some advice: I do a lot of serial communications with pics. I always use the USART. The reason being is I don't have to constantly poll the pins to receive data. When data comes in the program is interrupted and I handle the data as needed. Also the USART buffers data, so I never lose anything.

    Here are the things you will need to get it to function:

    DEFINE HSER_BAUD 9600 ' 9600 Baud USART
    DEFINE HSER_RCSTA 90h ' Enable USART RX
    DEFINE HSER_TXSTA 24h ' Enable USART TX
    DEFINE HSER_CLROERR 1 ' Clear all USART errors as they happen

    ON INTERRUPT GoTo INTERRUPT_SUB
    PIE1.5=1 ' Enable USART RCIF interrupt flag


    INTERRUPT_SUB :
    IF PIR1.5=1 Then HSerin [Data] ' If RX flag is set retrieve serial data

    This should give you a running start if you use it.

  4. #4
    Join Date
    Feb 2006
    Posts
    89


    Did you find this post helpful? Yes | No

    Default Problems as usual

    Thanks for the code. I almost got it to work i think. The problem is I don't know how to adjust/configure my registers. I looked at both the 12f625 and 16f629a datasheets to compare the original code to the updated code but my pic has alot registries naturally. I am also not sure if I have the crystal pins setup correctly or not. Here is my code and schematic. The oscillator has built in caps. I also forgot to ask what code I would need to make something happen at a given time. Thanks for any help you all can give.
    Attached Files Attached Files
    Last edited by Travin77; - 26th February 2006 at 02:10.

  5. #5
    Join Date
    Jun 2005
    Location
    Wisconsin
    Posts
    382


    Did you find this post helpful? Yes | No

    Default

    Several things:

    1) First your crystal is connected incorrectly based on the text file. On a 16F628 the crystal needs to be tied to pins 15 and 16. (see datasheet for details)

    2) Depending on your baud rate you may want to move the speed of your crystal up. At 9600 baud I usually use 16 mhz crystal.

    3) Here is an example of a typical Device programming Options :

    @ DEVICE pic16F628, HS_OSC ' System clock Options
    @ DEVICE pic16F628, WDT_ON ' Watch Dog Timer
    @ DEVICE pic16F628, PWRT_ON ' Power-on timer
    @ DEVICE pic16F628, BOD_ON ' Brown-out detector
    @ DEVICE pic16F628, MCLR_OFF ' Master Clear Options
    @ DEVICE pic16F628, LVP_OFF ' Low-voltage programming
    @ DEVICE pic16F628, CPD_OFF ' Data Memory Code Protect
    @ DEVICE pic16F628, PROTECT_OFF ' Program Code Protections

    NOTE: If you noticed above I have clock option set to HS not XT. At 16mhz this is considered High-Speed.

    4) When using a crystal don't forget to define the speed:
    DEFINE OSC 16 ' 16mhz XTAL

    5) The word "SYMBOL" is unneeded when you are defining constants. Use the follwing instead:
    line1 CON 128

    6) TRISB=%11111111 ' PORTB all Inputs
    TRISB=%00000000 ' PORTB all Outputs
    TRISB = %00000001 ' PORTB.0 PIN input for button

    These things should help get you running.
    Last edited by DynamoBen; - 26th February 2006 at 05:58.

  6. #6
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    With your code posting, if you fix the crystal location as DynamoBen suggested (and makd sure to add the caps to GND) and delete the “INTCONB=0 'interrupts off”
    line, the clock portion with display should work great as is.

    Note - for the code you have, you need to use 4MHz xtal. You could adjust the algorithm for 16MHz xtal if desired. One last thing, to “use the clock”, you can put something like

    If HH = 4 then ‘ turn on portb.1 at 4:15 and turn it off at 4:30
    If MM = 15 then portb.1=1
    If MM = 30 then portb.1=0
    Endif

    In the section labeled “do something here”

    Again, Good Luck,

    Paul Borgmeier
    Salt Lake City, Utah
    USA

Similar Threads

  1. Newbie 74hc595 question
    By manjero in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 22nd January 2008, 22:22
  2. newbie with serial com question...
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 16th December 2006, 05:34
  3. Newbie Question - Info Please
    By ehoskins in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd October 2006, 14:50
  4. Greetings from Newbie and a question
    By ChrisHelvey in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 24th July 2006, 15:52
  5. Newbie question
    By senojlr in forum General
    Replies: 7
    Last Post: - 11th April 2006, 21:23

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