Possible binary maths problem..

mickm2au

Member
I've been playing around with LCD drivers for a while now...mainly to keep the brain working and am now using a 14M2 to drive a parallel 2 line LCD. The problem is when I have the RS and E control lines on the same output port as the data lines and try to use a bit of "binary maths" to preserve the RS line condition as per the attached code no data appears to get to the LCD, that is it won't initalise. When I move the RS and E lines to port C as per the commented out code all works fine. Is the problem in my "binary maths" or is it some other cause. Using the simulator all the data appears to be correct.

Mick

Code:
#picaxe 14m2  '  AXE132 4Bit marks


'       DB4  = B.0
'       DB5  = B.1
'       DB6  = B.2
'       DB7  = B.3      

 SYMBOL E    = B.4
 SYMBOL RS   = B.5
 'SYMBOL E    = C.0
 'SYMBOL RS   = C.1
 SYMBOL RX   = C.4
 SYMBOL Backlight = C.2
 SYMBOL senddata  = b1
 SYMBOL index     = b0
 SYMBOL estart    = b2
 SYMBOL eend      = b3
 SYMBOL RSdata = b4
 SYMBOL baud = N9600_32
 SYMBOL line_length = 16
      SETFREQ M32
      dirsB = %11111111
      dirsC = %11010111
LOW Backlight

Gosub Initialise


Initialise:
      
	FOR  index = 0 to 6                                             
          LOOKUP index, ($33,$32,$28,$0C,$01,$02,$06),senddata : GOSUB Send    ' Initialise LCD
                       '(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 13
              LOOKUP index,("Serial-LCD Axe"),senddata : GOSUB Send ' sending characters
	PAUSE 1000 
           NEXT index
	PAUSE 1000
	GOTO Main 

Send:
	RSdata = outpinsB & %00100000 	'RS is on pin B.5 Need to add this to pins data
	'pinsB = senddata / 16 : PULSOUT E,1 
	pinsB = senddata / 16 & %00001111 + RSdata : PULSOUT E,1   'MSB + RS pin out
      'pinsB = senddata : PULSOUT E,1
      PinsB = senddata & 00001111 + RSdata : PULSOUT E,1    'LSB + RS pin out
	     
             RETURN
 

Rick100

Senior Member
Is that all your code? When I do a syntax check in the editor, it gives a "label not defined - main" error.
 

Rick100

Senior Member
You forgot the % symbol in front of your binary number in this line.
"PinsB = senddata & 00001111 + RSdata : PULSOUT E,1 'LSB + RS pin out"
 

mickm2au

Member
You forgot the % symbol in front of your binary number in this line.
"PinsB = senddata & 00001111 + RSdata : PULSOUT E,1 'LSB + RS pin out"
Thanks Rick...Must have been a typo during my many changes, but it didn't fix the problem...still no initializing!!
 

Rick100

Senior Member
It's possible you have a timing problem. Your supposed to have a 4.1 millisecond delay between the 1st and second time you set 8 bit mode. You might try running the chip add 4 Mhz to see if it initializes.
 

marks

Senior Member
Hi mickm2au,
I havent had a good look at what your code is doing but Id would use the alternative pins method at post #36
ive just cut and paste this so no guarentees lol
Code:
'#picaxe 18m2  '  4Bit Using Alternative pins marks
#picaxe 14m2  '  4Bit Using Alternative pins mickm2au
 SYMBOL DB7  = outpinB.3  'B.5
 SYMBOL DB6  = outpinB.2  'B.4
 SYMBOL DB5  = outpinB.1  'B.3 
 SYMBOL DB4  = outpinB.0  'B.2 
 SYMBOL E    = B.4        'B.1  
 SYMBOL RS   = B.5        'B.0  
 SYMBOL senddata  = b0
 SYMBOL index     = b1
      'value of count    = W1    ' b3,b2
      'display  count    = b4,b5,b6,b7,b8

      
      EEPROM 25,("Picaxe18M2")
      SETFREQ M32
 	dirsB = %11111111
 	dirsC = %11001111
 
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
  
      DisplayHello:
            LOW  RS                                                                      ' commandmode
            senddata = 132 :                                     GOSUB Send              ' (128-147) Line 1 Cursor Position
           HIGH RS                                                                       ' charactermode
            senddata = "H" :                                     GOSUB Send
            senddata = "e" :                                     GOSUB Send
            senddata = "l" :                                     GOSUB Send
            senddata = "l" :                                     GOSUB Send
            senddata = "o" :                                     GOSUB Send
pause 10000
            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 = 25 to 34
           READ index, senddata :                                GOSUB Send              ' sending character    
 	     NEXT index 
pause 4000

      Count1:
            LOW  RS                                                                      ' commandmode 
            senddata = 202 :                                     GOSUB Send              ' (192-211) Line 2 Cursor Position
      HIGH RS                                                                            ' charactermode 
      INC W1                                                                             ' add to W1
           BinToAscii W1,b8,b7,b6,b5,b4
           FOR  index = 0 TO 5                                                           ' sending characters
 	     LOOKUP index,(" ",b8,b7,b6,b5,b4),senddata :          GOSUB Send                 
           NEXT index
      PAUSE 8000                                                                         ' 1 second (M32)   
            
goto count1

       Send:
         DB7 =   bit7    	
         DB6 =   bit6    	
         DB5 =   bit5    	
         DB4 =   bit4   	
        PULSOUT E,1 
         DB7 =   bit3   	
         DB6 =   bit2    	
         DB5 =   bit1    
         DB4 =   bit0   	
        PULSOUT E,1        :                                     RETURN
 

mickm2au

Member
Hi Marks,

Most of the code is from your posts anyhow....Thanks. I can't get the syntax for the "DB7 = bit7" etc. The data is in variable "senddata" but I've tried all sorts of combinations senddata and bit7 etc but always get a syntax error ???

Rick,
I've just tried it with the reduced speed with the same result...
 
Last edited:

westaust55

Moderator
Can you not swap around the variables senddata and index as marks has done ?
SYMBOL senddata = b0
SYMBOL index = b1

otherwise with Marks code and your variable allocation
DB7 = bit7
needs to become
DB7 = bit15
etc
 

mickm2au

Member
Thanks Westy, now I can see how the bit variable works...bit0-7 on b0, bit8-15 on b1 etc, but I still get the same problem even with Marks code. I've a feeling that something else must be wrong if marks code should work.
 

mickm2au

Member
Well you wouldn't read about it...I decided to check all connections from my breadboard to the LCD again and they all proved correct, so then I thought I'd just check the connections directly from the 14M2 pins to the LCD and found pin8 B.5 was open circuit to the breadboard, so in effect RS on the LCD was open circuit when using port B for all the LCD lines. The breadboard is a "pebble" type and has been in use for quite some time so it appears that the contact strips beneath the row of 5 holes in that particular row has probably spread too far to make contact with the thin IC pins. I've moved the chip to a different section of board until I replace it.
My original code now works fine as does Marks code.
Thanks Guys...sorry to have wasted your time, but at least I've learned a bit more on different ways of doing things.
Mick
 

marks

Senior Member
Hi mickm2au,
we've all been down that road .
I haven't used a 14m2 so its good that you've proven your code to work as each beast can be different
and are sure others will find that information useful.
 

mickm2au

Member
Here's the complete code for my 14M2 serial N9600 LCD driver for anyone interested. As I said before, a lot of the code is thanks to Marks..

Code:
'14M2 serial LCD driver running at N9600
'Text is any ascii value < 254
'A command string must be preceded with 254
'255 will toggle a PNP backlight driver on C.2 




#picaxe 14m2  '  AXE132 4Bit marks


 SYMBOL E    = B.4
 SYMBOL RS   = B.5
 SYMBOL RX   = C.4
 SYMBOL Backlight = C.2
 SYMBOL senddata  = b0
 SYMBOL index     = b1
 SYMBOL estart    = b2
 SYMBOL eend      = b3
 SYMBOL RSdata = b4
 SYMBOL baud = N9600_32
 SYMBOL line_length = 16
      SETFREQ M32
      dirsB = %11111111
      dirsC = %11010111
LOW Backlight

GOSUB Initialise

Main:
Do
	bptr = 28
  serin Rx, baud, @bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc,@bptrinc 'Quicker than loop
	
  @bptr = 0             	' We're using 0 as an end of transmission marker
  bptr = 28             	' Reset the byte pointer to the first location.
	
  do until @bptr = 0          ' loop until we reach the EOT character
    senddata = @bptrinc       ' get each byte
    If senddata  < 254 THEN
      HIGH RS
	GOSUB send
      
    ELSE If senddata = 254 THEN
      LOW RS       	     ' change to command mode for next character 
      senddata = @bptrinc
	GOSUB send
	
    ELSE IF senddata = 255 THEN     'If 255 is received it will toggle a backlight switch transistor on C.2
	Toggle Backlight
			
		End If
        
  loop                        ' do loop
loop                          ' main loop
	
GOTO Main	
	
Initialise:
      
	FOR  index = 0 to 6                                             
          LOOKUP index, ($33,$32,$28,$0C,$01,$02,$06),senddata : GOSUB Send    ' Initialise LCD
                       '(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 13
              LOOKUP index,("Serial-LCD Axe"),senddata : GOSUB Send ' sending characters
	PAUSE 1000 
           NEXT index
	PAUSE 1000
	GOTO Main 

Send:    
	RSdata = outpinsB & %00100000 	'RS is on pin B.5 Need to add this to pins data
	
	pinsB = senddata / 16 & %00001111 + RSdata : PULSOUT E,1   'MSB + RS pin out
      
      PinsB = senddata & %00001111 + RSdata : PULSOUT E,1   	'LSB + RS pin out

Return
 
Top