;********************************************************************************* ; gpspeed-test-rtc GpSpeed real time clock test ; Louise@RotaryRacer, Terry@RotaryRacer ;********************************************************************************* ; ; This tests writing information onto the LCD display. ; ; For: PICAXE-28X2 (PIC18F25K22) ; ; GpSpeed pins are: ; B.1 LED ; C.2 Motor PWM ; C.1 Fan PWM ; A.0 Analogue Input 0, I0, throttle ; A.1 Analogue Input 1, I1, misc ; A.2 Analogue Input 2, Voltage measurement ; A.3 Analogue Input 3, Current measurement (Hall effect) ; B.4 Analogue/Digital Input, I2 ; ; B.2 Analogue Input 8, Current measurement (Mosfet) ; B.0 Error, error from Motor PWM ; C.3 I2C Clk ; C.4 I2c Dat ; C.0 User 0, I2c Int ; B.3 User 1 ; C.6 SER1 TX ; C.7 SER1 RX ; ; Symbols for pin names and variables symbol pinLed = B.1 ; The LED pin init: let adcsetup = %000000000001111 ; Initialises ADC inputs ; gosub rtcInit ; Sets up RTC with particular date/time gosub lcdInit ; Setup I2C hardware mainLoop: gosub rtcRead ; Read the time from the RTC b0 = 0 gosub lcdSetPos b0 = b10' ; Print time gosub lcdPutDecimal2 hi2cout 0,(":",255) b0 = b9 gosub lcdPutDecimal2 hi2cout 0,(":",255) b0 = b8 gosub lcdPutDecimal2 toggle pinLed ; Turns LED on pause 500 ; Delays for 500ms goto mainLoop ;****************************************************************************** ; LCD Subroutines ;****************************************************************************** ; Initialises the RTC with a set date/time rtcInit: hi2csetup i2cmaster, $D0, i2cslow, i2cbyte hi2cout 0, ($00, $15, $11, $01, $07, $06, $14, $00) return ; Reads the current date/time as integers into b13/b12/b11 b10:b9:b8 rtcRead: hi2csetup i2cmaster,$D0, i2cslow, i2cbyte hi2cin 0, (b8, b9, b10) ;‘ read sec, min, hour hi2cin 4, (b11, b12, b13) ;‘ read day, month, year ; Convert BCD values to integers b1 = b8 & $0F ; Get the units b8 = b8 / 16 * 10 + b1 ; Get tens and add units b1 = b9 & $0F ; Get the units b9 = b9 / 16 * 10 + b1 ; Get tens and add units b1 = b10 & $0F ; Get the units b10 = b10 / 16 * 10 + b1 ; Get tens and add units b1 = b11 & $0F ; Get the units b11 = b11 / 16 * 10 + b1 ; Get tens and add units b1 = b12 & $0F ; Get the units b12 = b12 / 16 * 10 + b1 ; Get tens and add units b1 = b13 & $0F ; Get the units b13 = b13 / 16 * 10 + b1 ; Get tens and add units hi2csetup i2cmaster,$C6,i2cslow,i2cbyte ; Put back to LCD mode return bcdToNum: b1 = b0 & $0F ; Get the units b0 = b0 / 16 * 10 + b1 ; Get tens and add units return ;****************************************************************************** ; LCD Subroutines ;****************************************************************************** ; Initialise the LCD display lcdInit: pause 500 hi2csetup i2cmaster,$C6,i2cslow,i2cbyte hi2cout 0,(254,1,255) hi2cout 0,(254,128,255) return ; Set the print position to the position defined in b2. Line 1 = +64 lcdSetPos: b2 = 128 + b2 hi2cout 0,(254,b2,255) return ; Print a single chracher that is in b0 at the position defined in b2. Line 1 = +64 lcdPutChar: b2 = 128 + b2 hi2cout 0,(254,b2,b0,255) pause 10 return ;Print the value in b0 as a decimal at the position defined in b2. Line 1 = +64 lcdPutDecimalByte: b2 = 128 + b2 b3 = b0 / 100 + 48 b0 = b0 // 100; b4 = b0 / 10 + 48 b0 = b0 // 10; b5 = b0 + 48 hi2cout 0,(254,b2,b3,b4,b5,255) pause 10 return ;Print the value in w0 as a decimal at the position defined in b2. Line 1 = +64 lcdPutDecimalWord: b2 = 128 + b2 b3 = w0 / 10000 + 48 w0 = w0 // 10000; b4 = w0 / 1000 + 48 w0 = w0 // 1000; b5 = w0 / 100 + 48 w0 = w0 // 100; b6 = w0 / 10 + 48 w0 = w0 // 10; b7 = w0 + 48 if b3 = "0" then b3 = " " if b4 = "0" then b4 = " " if b5 = "0" then b5 = " " if b6 = "0" then b6 = " " endif endif endif endif writei2c 0,(254,b2,b3,b4,b5,b6,b7,255) ; pause 10 return ;Print the value in w0 as a decimal scaled by 100 at the position defined in b2. Line 1 = +64 lcdPutDecimalWord100: b2 = 128 + b2 b3 = w0 / 10000 + 48 w0 = w0 // 10000; b4 = w0 / 1000 + 48 w0 = w0 // 1000; b5 = w0 / 100 + 48 w0 = w0 // 100; b6 = w0 / 10 + 48 w0 = w0 // 10; b7 = w0 + 48 if b3 = "0" then b3 = " " if b4 = "0" then b4 = " " endif endif writei2c 0,(254,b2,b3,b4,b5,".",b6,b7,255) pause 10 return ;Print the value in b0 as a decimal. Only two digits at current position lcdPutDecimal2: b4 = b0 / 10 + 48 b0 = b0 // 10; b5 = b0 + 48 hi2cout 0,(b4,b5,255) pause 10 return