I'm have a problem with a serial LCD driver circuit and program which is a combination of ideas from the AXE 133 and Mark's LCD driver info on this forum. It comprises of a 08m reading a DS18B20 and serial out to the 18m2 driver board . The 08m circuit using Marks "serial temp to 1 decimal place" program works correctly using the commented out line of code working into a NZ LCD serial board kit I purchased. But when connected to my circuit and using the "Marks initiating code" program (with the add on' s from axe133 etc.) I get Marks intro "Axe 132Picaxe" on the second line ok, but the serial temperature data which is supposed to write to the first line comprises of wrong characters with only the tenths of degree digit showing correctly and updating with the program as written in the attachments, which is the closest to a correct display so far. I have tried different board rate and Freq settings (on both the 08m and the 18m2). I've also tried small delays in the "main" program, all giving different combinations of characters and number of characters on the screen, some changing and some times fixed. I know I can buy serial driver boards, but I wanted to design my own to help keep the brain cells active. Any ideas appreciated
The driver code...
The serial temperature code...
The driver code...
Code:
;Modified for my Port C 18m2 board
;**************************
' COMMAND SUMMARY 4 BIT MODE
'( 1) Clear Display
'( 2) Cursor Home
'( 8) Display Off
'(12) Display On/Restore Cursor Off
'(128-147) Line 1 Cursor Position
'(192-211) Line 2 Cursor Position
'(148-167) Line 3 Cursor Position ~ continuation of line 1
'(212-231) Line 4 Cursor Position ~ continuation of line 2
'(13) Blinking Cursor
'(14) Underline Cursor
'(16) Move Cursor Left
'(20) Move Cursor Right
'(24) Shift Display Left
'(28) Shift Display Right
; Supported Commands
; 0-7, 8-15 CGRAM characters
; 16-252 normal ASCII characters, according to selected character map table
; 253, X display 16 character pre-saved message from EEPROM memory, X can be 0-15
; 254, X LCD command, X can be 0 to 255
; 255, X control outputs B.4,B.5,B.6,B.7 ($20 - $27)
; So, if using a backlit LCD with the active low transistor driver
; on output B.5, then 255,$22 switches backlight on and 255,$23 switches off
#picaxe 18m2 ' AXE132 4Bit marks
' DB7 = C.3
' DB6 = C.2
' DB5 = C.1
' DB4 = C.0
SYMBOL RX = B.2
SYMBOL E = B.0
SYMBOL RS = B.1
SYMBOL senddata = b1
SYMBOL index = b0
SYMBOL estart = b2
SYMBOL eend = b3
SYMBOL baud = N2400_16
SYMBOL line_length = 16
SETFREQ M16
dirsB = %11111011
dirsC = %11001111
EEPROM $10, (" www.picaxe.com ") ; store msg in the EEPROM memory
EEPROM $20, ("This is msg 2 ") ; store msg in the EEPROM memory
EEPROM $30, ("This is msg 3 ") ; store msg in the EEPROM memory
EEPROM $40, ("This is msg 4 ") ; store msg in the EEPROM memory
EEPROM $50, ("This is msg 5 ") ; store msg in the EEPROM memory
EEPROM $60, ("This is msg 6 ") ; store msg in the EEPROM memory
EEPROM $70, ("This is msg 7 ") ; store msg in the EEPROM memory
EEPROM $80, ("This is msg 8 ") ; store msg in the EEPROM memory
EEPROM $90, ("This is msg 9 ") ; store msg in the EEPROM memory
EEPROM $A0, ("This is msg 10 ") ; store msg in the EEPROM memory
EEPROM $B0, ("This is msg 11 ") ; store msg in the EEPROM memory
EEPROM $C0, ("This is msg 12 ") ; store msg in the EEPROM memory
EEPROM $D0, ("This is msg 13 ") ; store msg in the EEPROM memory
EEPROM $E0, ("This is msg 14 ") ; store msg in the EEPROM memory
EEPROM $F0, ("This is msg 15 ") ; store msg in the EEPROM memory
gosub Initialise
Main:
serin RX,baud,senddata ; wait for the next byte
; NB keep character mode test as first item in this list to optimise speed
IF senddata < 253 THEN
HIGH RS ; Character mode
GOSUB Send ; Send the data.
GOTO Main ; quickly loop back to top
ELSE IF senddata = 254 THEN
LOW RS ; change to command mode for next character
serin RX,baud,senddata ; wait for the command byte
GOSUB Send ; output the data
GOTO Main ; quickly loop back to top
ELSE IF senddata = 253 THEN
serin RX,baud,senddata ; wait for the next byte
GOSUB Msg ; do the 16 character message
GOTO Main ; back to top
ELSE ; must be 255
serin RX,baud,senddata ; wait for the next byte
GOSUB Control
GOTO Main ; back to top
END IF
Control:
SELECT CASE senddata
case $20 low b.4
case $21 high b.4
case $22 low b.5
case $23 high b.5
case $24 low b.6
case $25 high b.6
case $26 low b.7
case $27 high b.7
END SELECT
RETURN
Msg:
LET estart = senddata & %00001111 * line_length ; EEPROM start address is 0 to 15 multiplied by 16
LET eend = estart + line_length - 1 ; end address is start address + (line_length - 1)
FOR index = estart to eend ; for 16 times
READ index,senddata ; read next character from EEPROM data memory into b1
GOSUB Send ; output the data
NEXT index ; next loop
RETURN
Initialise:
FOR index = 0 to 6
LOOKUP index, ($33,$32,$28,$0C,$01,$02,$06),senddata : GOSUB Send ' Initialise LCD/OLED
'(WakeUp)*3(Set4Bit)(4Bit/2Line)(DisplayOn)(Clear Display)(Return Home)(Entry Mode Set)
NEXT index : PAUSE 10
Display:
LOW RS ' commandmode
senddata = $01 : GOSUB Send : PAUSE 10 ' Clear Display
senddata = 192 : GOSUB Send ' (192-211) Line 2 Cursor Position
HIGH RS ' charactermode
FOR index = 0 TO 12
LOOKUP index,("Axe132 Picaxe"),senddata : GOSUB Send ' sending characters
PAUSE 1000
NEXT index
PAUSE 1000
GOTO Main
Send:
pinsC = senddata / 16 : PULSOUT E,1 : pinsC = senddata : PULSOUT E,1 ' 4Bitmode to LCD (14.2per second)
RETURN
Code:
symbol degcelraw = w3
symbol degcel = b1
symbol degceldec = b0
eeprom 0,(9,8,7,6,5,4,3,2,1,0) 'lookup table for the negitive decimals
setfreq M8
main:
readtemp12 4,degcelraw
degcel = degcelraw/16 'calculate into deg celcius
degceldec = degcelraw//16*10/16
b3 = 43 'for positive temperatures default to show a plus sign
'negitive temperature code
if degcel >= $7F then ' if the degcel var is above 127 (max reading for +'ve is 125°C
;below zero "underflows" to 65535 @ -0.1 ish °C)
degcel = 255 - degcel 'take it from 255
b2 = degceldec
read b2, degceldec 'read the value of the decimal point from eeprom
b3 = 45 ' set b3 to show the minus character
end if
'end of negitive temperature processing
;serout 1, t4800_8, (00,192,"Temp = ",b3,#degcel,46,#degceldec,"°C") 'serial out the lot
serout 1, N2400_8, (254,128,"Temp = ",b3,#degcel,46,#degceldec,223,"C") 'serial out the lot
goto main
Attachments
-
12.1 KB Views: 28