SkiMask - thanks for your speedy reply. The code is below. The problem variable is
called 'LoopCounter' and is set at WORD length. THe loop does not increment.
If LoopCounter is made a BYTE all works as it should. Help?
'File...... Test Program
'
' Philips PCF8583 I2C RTC gives the time/date
' PIC16F877A on Mikro board is run @ 20 MHz
' After amendment to pbppic14.lib - now works at 20 MHz
'
' PIC LCD RS232 RTC DS1820 EEPROM
' --- --- ----- --- ------ ------
' C3 SCL ' I2C device, TRC clock
' C4 SDA ' I2C device, RTC data
' D2 RS ' LCD reset
' D3 EBIT ' LCD enable
' D4 DB4 ' LCD data 4
' D5 DB5 ' LCD data 5
' D6 DB6 ' LCD data 6
' D7 DB7 ' LCD data 7
'
' ----[ Variables ]---------------------------------------------------
'
DataPin var PORTC.4 ' RTC data
ClockPin var PORTC.3 ' RTC clock
Mins var byte ' Minutes on RTC
Hours var byte ' Hours on RTC
Days var byte ' Days on TTC
Months var byte ' Months on RTC
Time var byte[3] ' Holds months,days,hours,mins read from RTC
Dtime var byte[3] ' Holds months,days,hours,mins in HEX format
Units var byte ' Derived from Time
Tens var byte ' Derived form Time
CControl var byte ' Control byte for RTC
'
LoopCounter var word ' The 'problem' loop counter
J var byte ' Loop counter for RTC read/write
'
' ----[ Includes / Defines ]------------------------------------------
'
define OSC 20 'Now works at 20 MHz
DEFINE LCD_DREG PORTD 'Define PIC port used for LCD Data lines
DEFINE LCD_DBIT 4 'Define first pin of portb connected to LCD DB4
DEFINE LCD_RSREG PORTD 'Define PIC port used for RS line of LCD
DEFINE LCD_RSBIT 2 'Define Portb pin used for RS connection
DEFINE LCD_EREG PORTD 'Define PIC prot used for E line of LCD
DEFINE LCD_EBIT 3 'Define PortB pin used for E connection
DEFINE LCD_BITS 4 'Define the 4 bit communication mode to LCD
DEFINE LCD_LINES 2 'Define using a 2 line LCD
DEFINE LCD_COMMANDUS 2000 'Define delay time between sending LCD commands
DEFINE LCD_DATAUS 50 'Define delay time between data
'
' -----[ Initialization ]--------------------------------------------------
'
LoopCounter = 0 'EEPROM address counter - when I get it working!!!
J = 0 'Time[x] loop counter
CControl = %10100000 'Control word for RTC
'
' -----[ Main Program ]----------------------------------------------------
Start:
lcdout $fe,1,"Test Program"
Pause 1000
lcdout $fe,1
' -----[ Set Time ]-------------------------------------------------------
TimeSet
i2cwrite DataPin, ClockPin, CControl, $0, [%00001000]
'Control register for RTC, sets bit 3 to mask unwanted bits in time/date registers
i2cwrite DataPin, ClockPin, CControl, $2, [%00000000,%01011001,%00100011,%00110000,%00010001]
'BCD code, sets time registers to 0 Sec, 59 Min, 23 Hr, 30 Day, Month 11
' -----[ Main Program ]-----------------------------------------------------
Run:
' Time Read
i2cread DataPin, ClockPin, %10100000, $3, [Time[0], Time[1], Time[2], Time[3]]
Pause 20
'Time[0] = Min, Time[1] = Hr, Time[2] = Day, Time[3] = Month
' Time Show
for J = 0 to 3 'this works because the 'mask' is set and Time[x] bytes are all in BCD format.
Tens = Time[J] & %11110000
Tens = Tens>>4
Tens = Tens * 10
Units = Time[J] & %00001111
DTime[J] = Tens + Units 'Dtime is used to "Display Time"
next j
LCDout $FE, 1, "Mth: ", Dec DTime[3], " Day: ", dec DTime[2]
lcdout $FE, $C0, "Hrs: ", dec Dtime[1], " Min: ", DEC Dtime[0]
pause 1000
' Loop Counter
lcdout $FE,1,"Loop Ctr: ", DEC LoopCounter
pause 1000
LoopCounter = LoopCounter + 1
goto run
END
Sorry - the code has come out in a rather messy layout?
Bookmarks