18F25J11 RTCC & remappable pin options


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Posts
    2,405

    Default 18F25J11 RTCC & remappable pin options

    I have received several emails asking for PBP code examples for using some of the newer 18F series with independent I/O mapping of onboard hardware peripherals, and for working with the new built-in RTCC hardware, so I'm posting a simple example here showing how to use the RTCC, and how to assign PWM to several pins.

    These newer PICs that allow you to assign onboard peripherals like hardware PWM, USART, and a lot more, to different pins, are really nifty, and a lot like using the higher-end 24 series.

    Code:
    '****************************************************************
    '*  Name    : TST_25J11_RTC.BAS                                 *
    '*  Author  : B. Reynolds                                       *
    '*  Notice  : Copyright (c) 2009 http://www.Rentron.com         *
    '*          : All Rights Reserved                               *
    '*  Date    : 1/25/2010                                         *
    '*  Version : 1.0                                               *
    '*  Notes   : Testing 18F25J11 RTCC & remappable pin options.   *
    '*          :                                                   *
    '****************************************************************
    
      ' NOTE: CONFIG options below are placed in the PBP 18F25J11.INC file with
      ' default config options commented out.
    
      ' CONFIG OSC=INTOSC, LPT1OSC=OFF, CP0=OFF, WDTEN=ON, XINST=OFF, IOL1WAY=OFF
      ' CONFIG STVREN=OFF, T1DIG=ON, FCMEN=OFF, WDTPS=512, RTCOSC=T1OSCREF
    
      ' Connect a 32.768 kHz watch crystal between pins 11 & 12 T1CKI & T1OSI
      ' with caps to match your crystal load capacitance.
      ' 11        12
      '  |---||---|
      '  |  xtal  |
      ' _|_      _|_
      ' ___      ___  2 x 12pF caps
      '  |        |
      ' gnd      gnd
       
      DEFINE DEBUG_REG PORTB
      DEFINE DEBUG_BIT 3      ' RB3 sends serial data to PC
      DEFINE DEBUG_BAUD 19200 ' 19200 bps
      DEFINE DEBUG_MODE 0     ' 1 = inverted, 0 = true
    
      DEFINE OSC 8
      
      X       VAR BYTE
      Hours   VAR BYTE
      Minutes VAR BYTE
      Seconds VAR BYTE
      Year    VAR BYTE
      Month   VAR BYTE
      Day     VAR BYTE
      Weekday VAR BYTE
      Duty    VAR WORD
      
      OSCCON = %01110000   ' using 8MHz internal osc
      
      ' // A/D disable & setup Timer1 for RTCC //
      ANCON0 = $ff
      ANCON1 = $1f         ' disable A/D on all analog pins
      T1CON = %10001001    ' external xtal, 1:1 prescale, no synch, 8-bit, timer1 on
      
      ' // PWM & port setup //
      Duty = 400           ' 50-50 PWM duty-cycle
      T2CON = %00000100    ' timer2 on, 1:1 prescale 
      PORTA = 0
      PORTB = 8            ' RB3 debug pin idles high
      PORTC = 0            ' PWM outputs low at POR 
      TRISA = 0
      TRISB = 0
      TRISC = 0
      CCP1CON = %00001100  ' setup for single-ended PWM output 
      PR2 = 199            ' setup for 10kHz 
      PSTR1CON = %00000001 ' P1A is driven by PWM
      CCP1CON.4 = Duty.0   ' load 10-bit duty cycle into
      CCP1CON.5 = Duty.1   ' duty registers
      CCPR1L = Duty >> 2
      
      ' // re-map PWM output to RA0, RC4 and RC3 pins //
      RPOR0 = 14        ' RA0, RP0 = P1A output
      RPOR15 = 14       ' RC4. RP15 = P1A output
      RPOR14 = 14       ' RC3, RP14 = P1A output
      
      ' // set initial time/date at POR // 
      GOSUB WRT_Enable  ' run unlock sequence to enable RTCC writes
      GOSUB LoadTime    ' setup RTCC time/date
      GOSUB WRT_Disable ' disable RTC writes after initial time & date setup
    
    Main:
      RTCCFG = 3        ' set pointer to Year
      Year = RTCVALL    ' read Year
      RTCCFG = 2        ' set pointer to Month & Day
      Day = RTCVALL     ' read Day
      Month = RTCVALH   ' read Month & decrement pointer
      Hours = RTCVALL   ' read Hours
      Weekday = RTCVALH ' read Weekday & decrement pointer
      Seconds = RTCVALL ' read Seconds
      Minutes = RTCVALH ' read Minutes (pointer already at 0)
      PAUSE 990
      
    ' // date/time serial output format //
    ' Time: 03:33:00
    ' Monday: 
    ' Date: 01:25:2010
      
      ' // display Hours, Minutes, Seconds //
      DEBUG "Time: ",DEC (Hours>>4),DEC Hours & $0F,":", DEC (Minutes>>4),_
      DEC Minutes & $0F,":", DEC (Seconds>>4),DEC Seconds & $0F,13,10
      
      ' // display day of week //
      SELECT CASE Weekday
        CASE 0
          DEBUG "Sunday: ",13,10
        CASE 1 
          DEBUG "Monday: ",13,10
        CASE 2
          DEBUG "Tuesday: ",13,10
        CASE 3 
          DEBUG "Wednesday: ",13,10
        CASE 4
          DEBUG "Thursday: ",13,10
        CASE 5
          DEBUG "Friday: ",13,10
        CASE 6    
          DEBUG "Saturday: ",13,10
      END SELECT
       
      ' // display Month, Day, Year //
      DEBUG "Date: ",DEC2 Month & $1F,":", DEC (Day>>4), DEC Day & $0F,":",_
      "20",DEC (Year>>4), DEC Year & $0F,13,10,13,10,13,10
    
      GOTO Main
    
    LoadTime:  ' // NOTE: time & date is in BCD format //
      RTCCFG = %00100011  ' set pointer to Year
      RTCVALL = %00010000 ' set Year to 2010
      RTCCFG = %00100010  ' set pointer to Month & Day
      RTCVALL = %00100101 ' set Day to the 25rd
      RTCVALH = 1         ' set Month to Jan (decrements pointer to Weekday & Hours)
      RTCVALL = %00000011 ' set Hour to 3
      RTCVALH = 1         ' 0=Sun, 6=Sat. set Weekday (decrements pointer to Minutes & Seconds)
      RTCVALL = 0         ' set Seconds to 0
      RTCVALH = %00110011 ' set Minutes to 33
      RTCCFG.7 = 1        ' RTCC enabled
      RETURN
    
    WRT_Enable:           ' enable writes to RTCC registers
      EECON2 = $55        ' unlock sequence
      EECON2 = $AA        ' 
      RTCCFG.5 = 1        ' write enable RTCC register
      RETURN
      
    WRT_Disable:          ' disable writes to RTCC registers
      EECON2 = $55
      EECON2 = $AA
      RTCCFG.5 = 0
      RETURN
          
      END
    This shows how to re-map PWM output to RA0, RC4 and RC3 pins, and use the built-in
    RTCC clock functions. These PICs are definitely worth looking at, so have fun...;o)

    It does take a bit of time to learn how to use these guys, but it's very cool. You can re-
    map almost every onboard hardware peripheral to work on any pin.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  2. #2
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Yes, these newer PIC18's are really nice and they do give you a small hint as to the power and flexibility of the 24-bit core devices. Pity, they do not get more interest here.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    I'm waiting on a few 24 samples. Figured I would give them a whirl.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    I started using PIC24/dsPIC33 (in particular the PIC24F's for their rich peripheral set) 2 years ago and am really pleased with their power and flexibility - they are pretty much all I use these days. I have used PIC18's occasionally due to the excellent Swordfish compiler which isn't available yet for the 24-bit core devices. They only time I used a PIC16 in the last 2 years was when the app called for a small physical package and settled on an 8-pin MSOP.

  5. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Which compiler are you using for the PIC24F's ?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  6. #6
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    If you wan't to stay with BASIC (like me), I believe your only option for now is mikroBASIC Pro for dsPIC. Otherwise, there is the free C30 compiler from MicroCHIP. Also, Dave Barker says that he is working on a 24-bit version of Swordfish.
    Last edited by rmteo; - 28th January 2010 at 23:13.

Similar Threads

  1. Is this a K Type sensor?
    By jessey in forum mel PIC BASIC Pro
    Replies: 20
    Last Post: - 21st November 2009, 13:55
  2. DS1820 with 16f688
    By jessey in forum mel PIC BASIC Pro
    Replies: 13
    Last Post: - 23rd May 2009, 05:07
  3. Advice-scrutiny for my serial controller
    By kevlar129bp in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 13th December 2008, 17:11
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 17:27
  5. Another RTC, DS1287
    By DavidK in forum Code Examples
    Replies: 0
    Last Post: - 12th December 2006, 17:07

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