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 - JRCX.pbp

PICBASIC PRO program for an LCD clock using the JRC6355 RTC.
01' Name        : JRCX.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    : SHIFTIN, SHIFTOUT, LCDOUT, RTC
08' Description : PICBASIC PRO program for an LCD clock using the
09' JRC6355 RTC.
10'
11 
12Include "MODEDEFS.BAS"  ' Include Shiftin/out modes
13 
14Define LCD_DREG  PORTD  ' Define LCD connections
15Define LCD_DBIT  4
16Define LCD_RSREG PORTE
17Define LCD_RSBIT 0
18Define LCD_EREG  PORTE
19Define LCD_EBIT  1
20 
21' Alias pins
22CE    Var PORTA.2
23CLK   Var PORTC.1
24SDATA Var PORTC.3
25IO    Var PORTC.5
26 
27' Allocate variables
28rtcyear  Var byte
29rtcmonth Var byte
30rtcdate  Var byte
31rtcday   Var byte
32rtchr    Var byte
33rtcmin   Var byte
34rtcsec   Var byte
35 
36   Low CE          ' Disable RTC
37   Low CLK
38   High IO
39   ANSEL = %00000000 ' Make AN0-AN7 digital
40   ANSELH= %00000000 ' Make AN8-AN13 digital
41   Low PORTE.2     ' LCD R/W low = write
42   Pause 100       ' Wait for LCD to startup
43 
44   ' Set initial time to 8:00:00AM 07/16/99
45   rtcyear = $99
46   rtcmonth = $07
47   rtcdate = $16
48   rtcday = 6
49   rtchr = $08
50   rtcmin = 0
51   rtcsec = 0
52   Gosub settime   ' Set the time
53   Goto mainloop   ' Skip subroutines
54 
55' Subroutine to write time to RTC
56settime:
57   IO = 1          ' Set RTC to input
58   CE = 1          ' Enable transfer
59 
60   ' Write all 7 RTC registers
61   Shiftout SDATA, CLK, LSBFIRST, [rtcyear, rtcmonth, rtcdate, rtcday\4, rtchr, rtcmin]
62   CE = 0          ' Disable RTC
63   Return
64 
65' Subroutine to read time from RTC
66gettime:
67   IO = 0          ' Set RTC to output
68   CE = 1          ' Enable transfer
69 
70   ' Read all 7 RTC registers
71   Shiftin SDATA, CLK, LSBPRE, [rtcyear, rtcmonth, rtcdate, rtcday\4, rtchr, rtcmin, rtcsec]
72   CE = 0          ' Disable RTC
73   Return
74 
75' Main program loop - in this case, it only updates the LCD with the time
76mainloop:
77   Gosub gettime   ' Read the time from the RTC
78 
79   ' Display time on LCD
80   Lcdout $fe, 1, hex2 rtcmonth, "/", hex2 rtcdate, "/" , hex2 rtcyear,_
81   "  ", hex2 rtchr, ":", hex2 rtcmin, ":", hex2 rtcsec
82 
83   Pause 300       ' Do it about 3 times a second
84   Goto mainloop   ' Do it forever
85 
86   End

Download the program file.