LCD initialising problem

mickm2au

Member
I've been away from picaxe for several years and have just had the need to program another 14m2 with one of my working programs using a standard LCD in 4 bit mode. The LCD refused to initialize using code that I've used plenty of times before, in fact I reprogrammed a working temperature monitor with the original code and it refused to work. My picaxe editor has updated to 6.1.0.0 and I'm not sure what version the original code was written on. The chips program ok with no errors, but I now have a non working temperature monitor loaded with the exact same code as it was initially. Has PE 6.1.0.0 changed? I don't get any syntax errors.
The code below is the same initializing code I have used in several LCD projects with no problem until now.
I've programed the chip to flash a couple of leds which works with no problem.

Mike
 

Attachments

Last edited:

hippy

Technical Support
Staff member
I can't see anything which would have changed the way the code operated over the last few years so can't explain why it doesn't work or why the code you thought you had previously loaded into an existing project doesn't work now.

I would suspect the code you have isn't exactly the same as the code you had working and it's not clear how the code you posted matches with what you were using or are trying to use.

There are some things about it which don't look right to me; the GOSUB into Initialisation which then jumps back to 'main' and repeats. The multiple $33 initialisation codes, the $01 in that which is a clear screen which should have a delay before sending other commands which doesn't, lack of delay after sending initialisation nibbles and bytes.

Perhaps the best course would be to run some alternative test code and see if that works. This should work according to the pin allocation in your code -
Code:
#Picaxe 14M2
#No_Data

Symbol pinE  = pinB.4 : Symbol dirE  = dirB.4   ; 0 = Idle      1 = Active
Symbol pinRS = pinB.5 : Symbol dirRS = dirB.5   ; 0 = Command   1 = Data

Symbol pinD4 = pinB.0 : Symbol dirD4 = dirB.0   ; LCD Data Line 4
Symbol pinD5 = pinB.1 : Symbol dirD5 = dirB.1   ; LCD Data Line 5
Symbol pinD6 = pinB.2 : Symbol dirD6 = dirB.2   ; LCD Data Line 6
Symbol pinD7 = pinB.3 : Symbol dirD7 = dirB.3   ; LCD Data Line 7

PowerOnReset:

  Gosub InitialiseLcd

DisplayTopLine:

  For bPtr = 0 To 4
    LookUp bPtr, ( "Hello" ), b0 : Gosub SendDataByte
  Next

  Do : Loop

InitialiseLcd:

  dirE  = 1             ; Set LCD control lines as outputs
  dirRS = 1
  dirD4 = 1
  dirD5 = 1
  dirD6 = 1
  dirD7 = 1

  For bPtr = 0 To 5
    LookUp bPtr, ( $33, $32, $28, $0C, $06, $01 ), b0 : Gosub SendInitCmdByte
  Next
  Return

SendInitCmdByte:

  Pause 15              ; Delay 15mS

SendCmdByte:

  pinRS = 0             ; Send to Command register

  Gosub SendDataByte

  If b0 <= 3 Then       ; Pause to allow Home or Clear to complete
    Pause 10
  End If

  Return

SendDataByte:

  pinD7 = bit7          ; Put MSB out first
  pinD6 = bit6
  pinD5 = bit5
  pinD4 = bit4

  pinE  = 1             ; Give a pulse on E
  pinE  = 0

  pinD7 = bit3          ; Put LSB out second
  pinD6 = bit2
  pinD5 = bit1
  pinD4 = bit0

  pinE  = 1             ; Give a pulse on E
  pinE  = 0

  pinRS = 1             ; Send to Data register next

  Return
 

The bear

Senior Member
Mike,
Next time you program a Picaxe, Include a Sertxd to describe the project and date.
One of mine; Sertxd("TEST2 LDR Blinds K Mk5 v1.5 24.06.17",13,10)
You can then read your Picaxe via the Terminal. Hope that makes sense.
Good luck.......
 

mickm2au

Member
Thanks Hippy, the code was just a snippet containing the initializing and a bit of text. The extra $33,s are extra wake ups in case that was the problem. The "main:" at this point was just a delay to see if the text was written to the LCD and once that was working I could then add the main program. The test code you provided does work (as expected) so if I can't work out why mine dosn't work now, I'll use yours as its all getting pretty frustrating as to what or how my code has changed to not working.

To Bear, thanks for the suggestion. I do name my projects but usually not the developing variations as I'm going, good tip.

Mike
 

mickm2au

Member
Well I got my basic initializing code and a display of text working with a couple of minor changes. I must have lost the final version of my temperature monitor code, but that is now working with the modified initializing code, so all good. I'll attach the working initializing and display code snippet for anyone who's interested, as its pretty simple.
Thanks again for the help.
Mike
 

Attachments

hippy

Technical Support
Staff member
I must have lost the final version of my temperature monitor code
It happens. You either forget to save your code when it is finally working or it gets saved somewhere else by accident. Or it's working and you decide to try to improve something but never get it working which then appears to be the latest code but isn't.

Glad it's now working again.
 

marks

Senior Member
hi mickm2au,
I just finished making a new project board.
I have a 14m2 so writing some code for a lcd will be a good test for it!

It's a pity the 14m2 remaps its ports it could have been a little quicker.
a sneaky rewrite of initialization so we don't need to include some pauses.
from memory $30 *5 will cause shutdown *3 is enough to wake up!
sometimes dodgy supplies require delays at start and longer pauses.
(it's not a bad idea to include a pause at the start or halt code until say 4.7v is reached.)

hopefully your hardware is similar standard to mine lol (not fully tested but seems to work ok)

Rich (BB code):
#picaxe 14m2  '  AXE132 4Bit marks
#no_data
'      DB4 =    B.0
'      DB5 =    B.1
'      DB6 =    B.2
'      DB7 =    B.3 
 SYMBOL E  =    B.4
 SYMBOL RS =32' B.5 charactermode
  'SYMBOL RS =16' B.4 charactermode
  'SYMBOL E  =    B.5
 SYMBOL RX   = C.4
 SYMBOL Backlight = C.2
 
 SYMBOL index     = b0
 SYMBOL senddata  = b1
 
      SETFREQ M32
      dirsB = %111111
      dirsC = %010111
    
LOW Backlight

InitialiseLCD:
    ' ($3,$3,$3)  ' ($30,$30,$30) 3*(wakeup) parrallel interface expects 8bit data first
    ' ($2)        ' ($20) sets to 4bit ,will now allow data too be received in two nibbles
    ' ($2,$8)     ' data in two parts Msb first ($28)2lineControllers/5x8font/Eng-Jap)
    ' ($0,$C)     ' Display On
    ' ($0,$1)     ' Clear Display
    ' ($0,$2)     ' Return Home
    ' ($0,$6)     ' Entry Mode
    FOR  index = 0 to 13                                             
             LOOKUP index, ($3,$3,$3,$2,$2,$8,$0,$C,$0,$1,$0,$2,$0,$6),senddata     ' Initialise LCD 4bit
        pinsB = senddata :PULSOUT E,1        
      NEXT index 
    
Main:    
   Display: 
     senddata = 132                              : GOSUB SendCMD ' (128-147) Line 1 Cursor Position
   
     FOR  index = 0 TO 7
          LOOKUP index,("mickm2au") ,senddata : GOSUB SendCHR      
     NEXT index
     
  pause 14000 
   
           senddata = 128                            : GOSUB SendCMD  ' (128-147) Line 1 Cursor Position
          
      FOR  index = 0 TO 14
           LOOKUP index,(" Serial-LCD Axe"),senddata : GOSUB SendCHR  ' sending characters     
      NEXT index

  pause 14000
           senddata = $1                       : GOSUB SendCMD ' ClearDisplay

GOTO Main 

  SendCMD:  pinsB = senddata /16 :pause 5:PULSOUT E,1 : pinsB = senddata &$0F :PULSOUT E,1 : RETURN 

  SendCHR:  pinsB = senddata /16 +RS :PULSOUT E,1 : pinsB = senddata &$0F +RS :PULSOUT E,1 : RETURN
 
Top