Hi.
I am new to picaxe, and working on a project where the 18M2 is controlling a PWM fan depending on temperature. It's all good so far, but now I want to be able to send commands to the 18M2 to change the behavior of the fan.
My plan is to send a byte with two different qualifiers to adjust the MIN_temp and the MAX_temp and store them i EEPROM.
For now I am testing this code by sending and receiving using the picaxe terminal, storing the variables in b2 and b3, display them on my LCD and sending them to the terminal. It works, but I get a lot of errors. I have tried with and without the "add <CR>" in the terminal
Below is the output from a test.
DEDEDEDE3E3E3E3E3E3E3E3E383838383838383838383838383838ðððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððð¥+DEðððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððð¥+DEDED5D5D5D5
* First the program terminal receives the expected "DE" as the MIN and MAX is set to 68 and 69 (ASCII D and E)
* Then I enter MN3 in the terminal and we can see the MIN value changes to "3" on both my LCD and the terminal output.
* Then I enter MX8 in the terminal and we can see the MAX value changes to "8" on both my LCD and the terminal output.
* -THEN- when I enter MX9 to change the MAX value again to "9" everything goes tits up... we can see that a lot of "ð" characters are sent and it seems that the 18M2 resets because the next two values are are "DE"
* I try to send a "MN5" and now it works again, and I abort the program.
This happens in a random fashion. Sometimes i can enter many values before things go wrong. If I decrease the serrxd timeout to 100 it get the error almost all the time... Anyone who can shed some lights on what is going on?
Another thing is that I dont want to have long timeouts because that would slow down the program code too much. Any tip of how to solve that without using a digital input?
Here is my code:
I am new to picaxe, and working on a project where the 18M2 is controlling a PWM fan depending on temperature. It's all good so far, but now I want to be able to send commands to the 18M2 to change the behavior of the fan.
My plan is to send a byte with two different qualifiers to adjust the MIN_temp and the MAX_temp and store them i EEPROM.
For now I am testing this code by sending and receiving using the picaxe terminal, storing the variables in b2 and b3, display them on my LCD and sending them to the terminal. It works, but I get a lot of errors. I have tried with and without the "add <CR>" in the terminal
Below is the output from a test.
DEDEDEDE3E3E3E3E3E3E3E3E383838383838383838383838383838ðððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððð¥+DEðððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððððð¥+DEDED5D5D5D5
* First the program terminal receives the expected "DE" as the MIN and MAX is set to 68 and 69 (ASCII D and E)
* Then I enter MN3 in the terminal and we can see the MIN value changes to "3" on both my LCD and the terminal output.
* Then I enter MX8 in the terminal and we can see the MAX value changes to "8" on both my LCD and the terminal output.
* -THEN- when I enter MX9 to change the MAX value again to "9" everything goes tits up... we can see that a lot of "ð" characters are sent and it seems that the 18M2 resets because the next two values are are "DE"
* I try to send a "MN5" and now it works again, and I abort the program.
This happens in a random fashion. Sometimes i can enter many values before things go wrong. If I decrease the serrxd timeout to 100 it get the error almost all the time... Anyone who can shed some lights on what is going on?
Another thing is that I dont want to have long timeouts because that would slow down the program code too much. Any tip of how to solve that without using a digital input?
Here is my code:
Code:
symbol CHAR = b0
symbol INST = b1
symbol MIN_temp = b2
symbol MAX_temp = b3
Init:
MIN_temp = 68
MAX_temp = 69
let dirsc = %11000000
let dirsb = %01011111
gosub initLCD
Main:
pause 500
sertxd (MIN_temp,MAX_temp) ;Send value to PC
pause 50
disconnect
serrxd [1000],("MN"),MIN_temp ;Read MIN value from PC with MN qualifier
serrxd [1000],("MX"),MAX_temp ;Read MAX value from PC with MX qualifier
reconnect
CHAR = MIN_temp ;Put the MIN value into CHAR for display on LCD
gosub wrchr
CHAR = 32 ;Put 32 (space) into CHAR for display on LCD
gosub wrchr
CHAR = MAX_temp
gosub wrchr
INST = 128 ;Go to start of line 1 on LCD
gosub wrins
goto Main
;=======================================================================
;==== Subroutines ======================================================
;=======================================================================
;This code is standard initialization of a LCD display in 4-bit mode
initLCD:
low c.7
let pinsb = 0 ; Clear all output lines
pause 200 ; Wait 200 ms for LCD to reset.
let pinsb = 3 ; Set to 8-bit operation.
pulsout c.6,1 ; Send data by pulsing ;enable’
pause 10 ; Wait 10 ms
pulsout c.6,1 ; Send data again
pulsout c.6,1 ; Send data again
let pinsb = 2 ; Set to 4-bit operation.
pulsout c.6,1 ; Send data.
pulsout c.6,1 ; Send data again.
let pinsb = 16 ; Set to two line operation
pulsout c.6,1 ; Send data.
let INST = 12 ; Screen on, cursor off instruction
gosub wrins ; Write instruction to LCD
return
;This code puts bits 0-7 out to the pins connected to DB4-DB7 on the LCD
;Note that we first send the four highest bits, and then the four lowest.
;bits 0-7 are the 8 bits in the first byte (b0) we have renamed to CHAR in our code.
wrchr:
high c.7 ; Make sure RS is high to set the LCD in character mode
let pinb.4 = bit7
let pinb.2 = bit6
let pinb.1 = bit5
let pinb.0 = bit4
pulsout c.6,1 ; Pulse the enable pin to send data.
let pinb.4 = bit3
let pinb.2 = bit2
let pinb.1 = bit1
let pinb.0 = bit0
pulsout c.6,1 ; Pulse the enable pin to send data.
return
;This code puts bits 8-15 out to the pins connected to DB4-DB7 on the LCD
;Note that we first send the four highest bits, and then the four lowest.
;bits 0-7 are the 8 bits in the first byte (b0) we have renamed to CHAR in our code.
wrins:
low c.7 ; Make sure RS is low to set the LCD in instruction mode
let pinb.4 = bit15
let pinb.2 = bit14
let pinb.1 = bit13
let pinb.0 = bit12
pulsout c.6,1 ; Pulse the enable pin to send data.
let pinb.4 = bit11
let pinb.2 = bit10
let pinb.1 = bit9
let pinb.0 = bit8
pulsout c.6,1 ; Pulse the enable pin to send data.
return