‘************************************************************** ‘——LCD Prop Generator project—————————— ‘************************************************************** ‘picaxe 28×2 chip ‘LCD 20×4 display ‘Hall-I-sensor WCS1800 and TLE4005L , 25V voltage sensor and DS18B20 temp sensor ‘measurement prop generator current, voltage and temperatur in voltage control unit. ‘this program is about 1050/4096 bytes ‘*************************************************************** ‘———MAKE SURE LCD_ADR IS CORRECT————————– ‘*************************************************************** ‘Symbol LCD_ADR = $40 ‘I2C address of lcd ‘ PCF8574A, A0-A2 ilmassa: %01111110 ‘ PCF8574, A0-A2 ilmassa: %01001110 Symbol LCD_ADR = %01001110 ‘I2C address of lcd Symbol RSCMD = 0 ‘ Select Command register Symbol RSDAT = 1 ‘ Select Data register Symbol LCDData = b0 ‘used for hi2cout LCDData port ‘change the following 4 symbols to match display Symbol LCDData_RS = bit0 ‘ bit0 of LCDData register (0 = Command 1 = Data bit) Symbol LCDData_RD = bit1 ‘ bit1 of LCDData register (0 = Write 1 = Read) Symbol LCDData_E = bit2 ‘ bit2 of LCDData register (0 = Idle 1 = Active) Symbol LCDData_BL = bit3 ‘ bit3 of LCDData register (backlight) ‘Symbol ptr = b1 Symbol cnt = b15 Symbol tmp2 = b3 Symbol mitta_apu = b4 Symbol ByteToLCD = b5 Symbol nibReg = b6 ‘Symbol temp = b7 Symbol V1 = b8 Symbol V2 = b9 Symbol V3 = b10 Symbol V4 = b11 Symbol V5 = b12 Symbol lcd_current = b13 Symbol lcd_voltage = b27 Symbol lcd_temp = b41 Symbol lcd_rpm = b51 Symbol adc = b14 Symbol J1 = b22 Symbol J2 = b23 Symbol J3 = b24 Symbol J4 = b25 Symbol J5 = b26 Symbol T1 = b36 Symbol T2 = b37 Symbol T3 = b38 Symbol T4 = b39 Symbol T5 = b40 Symbol R1 = b46 Symbol R2 = b47 Symbol R3 = b48 Symbol R4 = b49 SymBol R5 = b50 Symbol current = w1 Symbol rpm = w22 Symbol voltage = w16 Symbol temp = w17 #no_data ‘——————————————————————————- ‘——————————————————————————- ‘************ ROWS************** ‘ 128 + 0 + (situation, how many free from begining) = 1. row ‘ 128 + 64 + situation = 2. row ‘ 128 + 20 + situation = 3. row ‘ 128 + 84 + situation = 4. r0w ‘******************************* ‘Initialization gosub InitLCD LCDData_BL = 1 ‘backlight on ByteToLCD = 1 ‘clear screen gosub SendCmdByte pause 20 ‘pause after clear screen ByteToLCD = 128 + 0 + 0 ‘128= write command, 0= 1. row, last 0= how many empty from begining Gosub SendCmdByte ptr = 0 prt1: lookup ptr,(“* Prop Gen rpm *~”),ByteToLCD if ByteToLCD = “~” then goto prt1_end gosub SendDataByte:inc ptr:goto prt1 prt1_end: ByteToLCD = 128 + 64 + 0 Gosub SendCmdByte ptr = 0 prt2: lookup ptr,(“* Current a *~”),ByteToLCD if ByteToLCD = “~” then goto prt2_end gosub SendDataByte:inc ptr:goto prt2 prt2_end: ByteToLCD = 128 + 20 + 0 Gosub SendCmdByte ptr = 0 prt3: lookup ptr,(“* Voltage v *~”),ByteToLCD if ByteToLCD = “~” then goto prt3_end gosub SendDataByte:inc ptr:goto prt3 prt3_end: ByteToLCD = 128 + 84 + 0 Gosub SendCmdByte ptr = 0 prt4: lookup ptr,(“* Temp C *~”),ByteToLCD if ByteToLCD = “~” then goto prt4_end gosub SendDataByte:inc ptr:goto prt4 prt4_end: main: gosub measurement_rpm ‘measuring hall-sensor TLE4905L gosub measurement_current gosub measurement_voltage gosub measurement_temp gosub Display_rpm ‘showing rules gosub Display_current gosub Display_voltage gosub Display_temp goto main ‘debug ‘——————————————————————————- InitLcd: ‘make sure I2CSLOW_X matches clock speed HI2cSetup I2CMASTER, LCD_ADR, I2CSLOW_32, I2CBYTE ‘LCDData_RS/RW/LCDData_E/LCDData_BL LCDData = %00110000 ‘ 8-bit mode LCDData_RS = RSCMD ‘ Send to Command register LCDData_RD = 0 temp = LCDData LCDData_E = 1 for cnt = 0 to 2 HI2cOut(temp,LCDData,temp ) ‘ Pulse LCDData_E 1X Pause 10 next cnt LCDData = %00100000 ‘ 4-bit mode LCDData_RS = RSCMD ‘ Send to Command register LCDData_RD = 0 temp = LCDData LCDData_E = 1 HI2cOut(temp,LCDData,temp ) ‘ Pulse LCDData_E LCDData_E = 0 pause 10 ‘now we can use 4 bit interface for rest of initialization ByteToLCD = $28 ‘ %00101000 %001LNF00 Display Format Gosub SendInitCmdByte ByteToLCD = $0C ‘ %00001100 %00001DCB Display On Gosub SendInitCmdByte ByteToLCD = $06 ‘ %00000110 %000001IS Cursor Move Gosub SendInitCmdByte ByteToLCD = 1 ‘Clear Screen Gosub SendInitCmdByte pause 20 ‘important beacuse last command was clear screen Return ‘InitialiseLcd SendInitCmdByte: Pause 60 ‘ Delay 15mS SendCmdByte: LCDData_RS = RSCMD ‘ Send to Command register LCDData_RD = 0 ‘ Write to the display SendDataByte: ‘high nibble of char or instruction first nibReg = ByteToLCD & %11110000 ‘high nibble of ByteToLCD LCDData = LCDData & %00001111 ‘low nibble contains control signals LCDData = LCDData | nibReg temp = LCDData LCDData_E = 1 HI2cOut(temp,LCDData,temp ) ‘Pulse LCDData_E LCDData_E = 0 ‘lo nibble nibReg = ByteToLCD * 16 ‘low nibble of ByteToLCD into high nibble of nibReg LCDData = LCDData & %00001111 ‘low nibble contains control signals LCDData = LCDData | nibReg temp = LCDData LCDData_E = 1 HI2cOut(temp,LCDData,temp ) ‘Pulse LCDData_E LCDData_E = 0 LCDData_RS = RSDAT ‘Send default to Data register Return ‘SendDataByte , SendCmdByte , SendInitCmdByte PrintFromRAM: ‘0: pituus, 1: sijainti, 2…: printattavat merkit… What is this???? peek 64, cnt peek 65, ByteToLCD gosub SendCmdByte for tmp2 = 2 to cnt ptr = 64 + tmp2 peek ptr, ByteToLCD gosub SendDataByte next tmp2 return ‘————————————————————————————————- measurement_rpm: ‘pulsin C.6, 1, w14 ‘readADC C.6, w14 ‘for b17 = 1 to 30 count C.6, 6000, rpm ‘read Hall-sensor TLE4905L rpm = b44*20 ‘w23 = b28 ‘next b17 debug pause 200 return measurement_current: readADC10 13, current ‘measurement Hall-I-sensor WCS1800 current = 15-current ‘negative will changes to positive b2=b2/14 ‘given change to current A b2=b2-2 if b2>17 then ‘remove unwanted numbers out b2=0 endif pause 200 return measurement_voltage: for b18 = 1 to 10 readadc10 11 ,voltage voltage=voltage*99/375 next b18 pause 200 return measurement_temp: readtemp C.2,temp ‘ read temperature, bintoascii temp,T1,T2,T3,T4,T5 ‘ bin to ascii if T4=48 then ‘ blank digit if zero T4=32 endif pause 100 return Display_rpm: lcd_rpm = 128 + 0 + 12 gosub print_rpm return Display_current: lcd_current = 128 + 64 + 13 ; current = b2 gosub print_current return Display_voltage: lcd_voltage = 128 + 20 + 13 gosub print_voltage return Display_temp: lcd_temp = 128 + 84 + 13 gosub print_temp return ‘————————————————————————————————– print_rpm: BinToAscii rpm,R1,R2,R3,R4,R5 if R2 = “0” and R3 = “0” and R4 = “0” then R4 = ” ” ‘blank zeros endif if R2 = “0” and R3 = “0” then R3 = ” ” ‘blank zeros endif if R1 = “0” and R2 = “0” then R2 = ” ” ‘blank zeros endif if R3 = “0” and R4 = “0” then R4 = ” “ endif if R3 > “0” and R4 = “0” then ‘blank zeros R4 = “0” endif poke 64, 4, lcd_rpm, R3, R4, R5 gosub PrintFromRAM return print_current: BinToAscii current, V1, V2, V3, V4, V5 if V4 = “0” then V4 = ” “ endif poke 64, 3, lcd_current, V4, V5 gosub PrintFromRAM return print_voltage: BinToAscii voltage, J1, J2, J3, J4, J5 if J3 = 48 then J3 = 32 endif poke 64, 5, lcd_voltage, J3,J4,”.”,J5 gosub PrintFromRAM return print_temp: BinToAscii temp, T1, T2, T3, T4, T5 poke 64, 4, lcd_temp, T4,T5,$DF gosub PrintFromRAM return