ME Labs, Inc.
719-520-5323
 
Home:
  Developer Resources:

Programming Clues
    Sample Programs
   
    PICBASIC PRO™
Compiler Manual
    PICBASIC™ Compiler
Manual
    Serin2/Serout2 Modes
    ASCII Character Set
    Number Conversion
    Floating Point
Routines
    PBP Debug Monitor
    Articles and Tutorials

Hardware Clues
    Parts / Vendor List
    PICPROTO™ Boards
    LAB-X1 Docs
    LAB-X2 Docs
    LAB-X20 Docs
    LAB-X3 Docs
    LAB-X4 Docs
    LAB-XUSB Docs
    LAB-XT Docs
     
 

ME Labs, Inc. | 1-719-520-5323 | Example Program - RTCX.pbp

PICBASIC PRO program for LCD clock using the Dallas 1202/1302 RTC ICs.
' Name        : RTCX.pbp
' Compiler    : PICBASIC PRO Compiler 2.60
' Assembler   : PM or MPASM
' Target PIC  : 40-pin 16F887
' Hardware    : LAB-X1 Experimenter Board
' Oscillator  : 4MHz external crystal
' Keywords    : LCDOUT, SHIFTIN, SHIFTOUT
' Description : PICBASIC PRO program for LCD clock using the
' Dallas 1202/1302 RTC ICs.
'

' Define LOADER_USED to allow use of the boot loader.
' This will not affect normal program operation.
Define LOADER_USED 1

Include "MODEDEFS.BAS"  ' Include Shiftin/out modes

Define LCD_DREG  PORTD  ' Define LCD connections
Define LCD_DBIT  4
Define LCD_RSREG PORTE
Define LCD_RSBIT 0
Define LCD_EREG  PORTE
Define LCD_EBIT  1

' Alias pins
RST  Var PORTA.2
IO   Var PORTC.1
SCLK Var PORTC.3

' Allocate variables
rtcyear    Var byte
rtcday     Var byte
rtcmonth   Var byte
rtcdate    Var byte
rtchr      Var byte
rtcmin     Var byte
rtcsec     Var byte
rtccontrol Var byte

   Low RST         ' Reset RTC
   Low SCLK
   ANSEL = %00000000 ' Make AN0-AN7 digital
   ANSELH= %00000000 ' Make AN8-AN13 digital
   Low PORTE.2     ' LCD R/W low = write
   Pause 100       ' Wait for LCD to startup

   ' Set initial time to 8:00:00AM 07/16/99
   rtcyear = $99
   rtcday = $06
   rtcmonth = $07
   rtcdate = $16
   rtchr = $08
   rtcmin = 0
   rtcsec = 0
   Gosub settime   ' Set the time
   Goto mainloop   ' Skip subroutines

' Subroutine to write time to RTC
settime:
   RST = 1         ' Ready for transfer

   ' Enable write
   Shiftout IO, SCLK, LSBFIRST, [$8e, 0]
   RST = 0         ' Reset RTC
   RST = 1         ' Ready for transfer

   ' Write all 8 RTC registers in burst mode
   Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
   RST = 0         ' Reset RTC
   Return

' Subroutine to read time from RTC
gettime:
   RST = 1         ' Ready for transfer
   Shiftout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
   Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
   RST = 0         ' Reset RTC
   Return

' Main program loop - in this case, it only updates the LCD with the time
mainloop:
   Gosub gettime   ' Read the time from the RTC

   ' Display time on LCD
   Lcdout $fe, 1, hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear,_
   "  ", hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec

   Pause 300       ' Do it about 3 times a second
   Goto mainloop   ' Do it forever

   End

           

Download the program file.