;********************************************************************************* ; gpspeed-test-display GpSpeed display interface test ; Louise@RotaryRacer, Terry@RotaryRacer ;********************************************************************************* ; ; This tests writing information onto the LCD display. ; This assumes a PicAxe AXE033 LCD display, configured for I2C mode, ; is connected to the GpSpeed's display port. ; ; 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 lcdInit ; Setup I2C hardware mainLoop: readadc A.0, b0 ; Reads the ADC throttle input b2 = 0 gosub lcdPutDecimalByte b2 = 8 w0 = 1234 gosub lcdPutDecimalWord100 b2 = 64 gosub lcdSetPos hi2cout 0,("Hello!123", 255) toggle pinLed ; Turns LED on pause 500 ; Delays for 500ms goto mainLoop ;****************************************************************************** ; 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