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.
01' Name        : RTCX.pbp
02' Compiler    : PICBASIC PRO Compiler 2.60
03' Assembler   : PM or MPASM
04' Target PIC  : 40-pin 16F887
05' Hardware    : LAB-X1 Experimenter Board
06' Oscillator  : 4MHz external crystal
07' Keywords    : LCDOUT, SHIFTIN, SHIFTOUT
08' Description : PICBASIC PRO program for LCD clock using the
09' Dallas 1202/1302 RTC ICs.
10'
11 
12' Define LOADER_USED to allow use of the boot loader.
13' This will not affect normal program operation.
14Define LOADER_USED 1
15 
16Include "MODEDEFS.BAS"  ' Include Shiftin/out modes
17 
18Define LCD_DREG  PORTD  ' Define LCD connections
19Define LCD_DBIT  4
20Define LCD_RSREG PORTE
21Define LCD_RSBIT 0
22Define LCD_EREG  PORTE
23Define LCD_EBIT  1
24 
25' Alias pins
26RST  Var PORTA.2
27IO   Var PORTC.1
28SCLK Var PORTC.3
29 
30' Allocate variables
31rtcyear    Var byte
32rtcday     Var byte
33rtcmonth   Var byte
34rtcdate    Var byte
35rtchr      Var byte
36rtcmin     Var byte
37rtcsec     Var byte
38rtccontrol Var byte
39 
40   Low RST         ' Reset RTC
41   Low SCLK
42   ANSEL = %00000000 ' Make AN0-AN7 digital
43   ANSELH= %00000000 ' Make AN8-AN13 digital
44   Low PORTE.2     ' LCD R/W low = write
45   Pause 100       ' Wait for LCD to startup
46 
47   ' Set initial time to 8:00:00AM 07/16/99
48   rtcyear = $99
49   rtcday = $06
50   rtcmonth = $07
51   rtcdate = $16
52   rtchr = $08
53   rtcmin = 0
54   rtcsec = 0
55   Gosub settime   ' Set the time
56   Goto mainloop   ' Skip subroutines
57 
58' Subroutine to write time to RTC
59settime:
60   RST = 1         ' Ready for transfer
61 
62   ' Enable write
63   Shiftout IO, SCLK, LSBFIRST, [$8e, 0]
64   RST = 0         ' Reset RTC
65   RST = 1         ' Ready for transfer
66 
67   ' Write all 8 RTC registers in burst mode
68   Shiftout IO, SCLK, LSBFIRST, [$be, rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, 0]
69   RST = 0         ' Reset RTC
70   Return
71 
72' Subroutine to read time from RTC
73gettime:
74   RST = 1         ' Ready for transfer
75   Shiftout IO, SCLK, LSBFIRST, [$bf] ' Read all 8 RTC registers in burst mode
76   Shiftin IO, SCLK, LSBPRE, [rtcsec, rtcmin, rtchr, rtcdate, rtcmonth, rtcday, rtcyear, rtccontrol]
77   RST = 0         ' Reset RTC
78   Return
79 
80' Main program loop - in this case, it only updates the LCD with the time
81mainloop:
82   Gosub gettime   ' Read the time from the RTC
83 
84   ' Display time on LCD
85   Lcdout $fe, 1, hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear,_
86   "  ", hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec
87 
88   Pause 300       ' Do it about 3 times a second
89   Goto mainloop   ' Do it forever
90 
91   End

Download the program file.