8 bit LCD Initialization string

JSDL

Senior Member
Hi everyone, I've worked with the HD44780 parallel LCD's a few years back and had good results in 4 bit mode using a shift register. I am now revisiting the topic (and trying to re-learn everything I forgot) and am building a circuit with an HD44780 compatable display and Picaxe 20M2 with idrect connection using 8 bit mode, however, I cannot seem to get anything to display at all. I don't know if it is my initialization routine, code, or both. Can anyone point me in the right direction? I've included the schematic (DS1307 is currently not connected). I've always found this forum extremely helpful. Thanks!

Code:
pause 100
'low c.4

i2cslave %11010000, i2cslow, i2cbyte	 'Set slave address for DS3231 module
let dirsB = %11111111

'###################Define Sysmbols for 74HC595 and HD44780 pins

symbol LCD_ENABLE=c.4		'Enable pin on HD44780 LCD module
symbol LCD_RS=c.3		'Register Select pin on HD77480, HIGH=Data, LOW=Command

symbol outbyte =b0
symbol counter = b1


'############Initialization sequence for HD44780 Module#############

for counter = 0 to 7
	lookup counter ,($30, $30, $30, $38, $10, $01, $06, $0C), outbyte
	gosub lcd_cmd
	pause 5
next counter

'#####################################################################


'readi2c 0, (seconds, mins, hour, day, date, month, year)
'writei2c 0, (seconds, mins, hour, day, date, month, year)	'Write Time to RTC

TABLE 0,("Time: ")
TABLE 6, ("Date: ")


MAIN:


outbyte=$80: gosub lcd_cmd

for counter = 0 to 5
	readtable counter, outbyte: gosub lcd_data
next counter

goto main



lcd_cmd:	'Write Commands to LCD

low LCD_RS
let pinsB=outbyte
pulsout LCD_ENABLE, 1
return

lcd_data:	'Write Data to LCD
high LCD_RS
outpinsB=outbyte
pulsout LCD_ENABLE, 1
return

[ATTACH=CONFIG]20522.vB[/ATTACH]
 

Janne

Senior Member
Hi, this code snippet might help;

Code:
InitialiseLcd:

FOR i = 0 TO 5
	READ i,temp
	GOSUB SendInitCmdbyter
NEXT i

' Nibble commands - To initialise 4-bit mode

EEPROM 0,( $33 )    ; %0011---- %0011----   8-bit / 8-bit
EEPROM 1,( $32 )    ; %0011---- %0010----   8-bit / 4-bit

' byter commands - To configure the LCD

EEPROM 2,( $28 )    ; %00101000 %001LNF00   Display Format
EEPROM 3,( $0C )    ; %00001100 %00001DCB   Display On
EEPROM 4,( $06 )    ; %00000110 %000001IS   Cursor Move

                            ; L : 0 = 4-bit Mode    1 = 8-bit Mode
                            ; N : 0 = 1 Line        1 = 2 Lines
                            ; F : 0 = 5x7 Pixels    1 = N/A
                            ; D : 0 = Display Off   1 = Display On
                            ; C : 0 = Cursor Off    1 = Cursor On
                            ; B : 0 = Cursor Steady 1 = Cursor Flash
                            ; I : 0 = Dec Cursor    1 = Inc Cursor
                            ; S : 0 = Cursor Move   1 = Display Shift

EEPROM 5,( $01 )    ; Clear Screen

RETURN
 

hippy

Technical Support
Staff member
My guesses would be -

1) Not setting RS an E as Output Low at start-up

2) Not long enough pauses between initialisation bytes and especially not after the $01 clear screen. I would put the clear screen last so you can add a pause after the NEXT.
 

AllyCat

Senior Member
Hi,

Also, you have a conflict between the 8-bit data bus and the dedicated I2C pins (b.5 and b.7). You may not have connected the I2C chip yet, but AFAIK you have configured the pins with the i2cslave command (try commenting it out). That command is now deprecated, see manual 2 or the on-line help.

Cheers, Alan.
 

Flenser

Senior Member
Looking at the 20M2 pinout in the Picaxe manual #2 the I2C SDA pin is B.5 and the I2C SCL pin is B.7 but in your code and circuit you have posted the LCD data bus is connected to pins B.0 to B.7.

Your call to i2cslave _will_ setup pins B.5 and B.7 to be driven by the PIC I2C hardware instead of the contents of the port B buffer. Depending upon what the default levels were for these two I2C pins it could stuff up the commands you think you are sending to the LCD as the ouputs on pins B.4 and B.7 would always be those default I2C levels and not the values you write to port B for those pins.

As AllyCat has already suggested, try commenting out your call to i2cslave, so that the I2C hardware does not take over pins B.5 and B.7, and see if your LCD gets correctly initialized to a blank screen with the cursor at line 1 column 1.
 
Last edited:

marks

Senior Member
Hi JSDL,
I did something similiar with the axe132 (18m2) posts #7 and #8
http://www.picaxeforum.co.uk/showthread.php?18694-DS3231-Code-examples
just changed a bit to suit your circuit in post #1
its basic just shows time but will hopefully get you started
Code:
'#picaxe 20m2 ' cut from axe132 should work for ds1307 also 8Bit marks
'     SCL   DB7  = B.7
'           DB6  = B.6
'     SDA   DB5  = B.5
'           DB4  = B.4
'           DB3  = B.3
'           DB2  = B.2
'           DB1  = B.1
'           DB0  = B.0
      SYMBOL  E  = C.4
      SYMBOL RS  = C.3           
 SYMBOL senddata = pinsb
 SYMBOL index    = b0       : SYMBOL halfsecond  =b0
 SYMBOL dot      = b1       : SYMBOL CRC         =b1
 SYMBOL hours    = b2
 SYMBOL mins     = b3
 SYMBOL secs     = b4  
 SYMBOL day      = b5       ' not used 
 SYMBOL date     = b6  
 SYMBOL month    = b7   
 SYMBOL year     = b8
 SYMBOL AM_PM    = b9
 SYMBOL D0       = b10       
 SYMBOL D1       = b11
 SYMBOL D2       = b12 
 SYMBOL D3       = b13
 SYMBOL D4       = b14
 SYMBOL D5       = b15      : SYMBOL Sign       = b15
 SYMBOL Temperature   = W10 : SYMBOL TempMsb    = B21 : SYMBOL TempLsb = B20 
 
      SETFREQ M32
 	dirsB = %11111111
 	dirsC = %11001111
	
 ;;;;   Collect  date and time from the PICAXE Editor 6.0.7.5 (BETA) 
          bptr=28
          FOR  index = 2 TO 18	
 	      LOOKUP index,(ppp_datetime),@bptrinc      '  ("2015-01-31 10:00:25")
          NEXT index
 ;;;;    Entering date and time in $BCD  convert from ASCII   
 bptr =28
 year  = @bptrinc*$10+@bptrinc-$30 :inc bptr
 month = @bptrinc*$10+@bptrinc-$30 :inc bptr
 date  = @bptrinc*$10+@bptrinc-$30 :inc bptr
 hours = @bptrinc*$10+@bptrinc-$30 :inc bptr          ' $0 to $23
 mins  = @bptrinc*$10+@bptrinc-$30 :inc bptr
 secs  = @bptrinc*$10+@bptrinc-$30 +$16               ' add 16 seconds (how long it takes for PC to program)         
     
InitialiseOLED: 	
	FOR  index = 0 to 6 
          LOOKUP index, ($38,$38,$38,$0C,$01,$02,$06),senddata : PULSOUT E,1 ' Initialise LCD/OLED
          '(8bit/2line/5x8)*3(Display On)(Clear Display)(Return Home)(Entry Mode Set)
 	NEXT index : PAUSE 10 

InitialiseTime:  
   hours = hours /$10 *250 +hours                            ' Convert ($00 to $23) BCD to Decimal
    
   AM_PM = hours /12 *$20 +$40                               ' Convert to 12hour 
   hours = hours //12 : IF hours =0 THEN : hours =12 : ENDIF ' Convert to 12hour
   hours = hours /10 *6 +hours +AM_PM                        ' hoursAM 1-12 ($41 to $52) hoursPM 1-12 ($61 to $72)
    
    READ  255,CRC : IF CRC <> 0 THEN Main                    ' Skip if time already programmed 
     HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte     ' Set  DS3231 to 400kbps 
      HI2Cout $0 , (secs,mins,hours,day,date,month,year)     ' Write to DS3231 
    WRITE 255,53                                             ' we can make use of an existing eeprom entry if any

  MAIN:
      HI2Csetup I2Cmaster, %11010000, I2Cslow_32, I2Cbyte     ' Set  DS3231 to 400kbps   
       HI2Cin  $0 , (secs,mins,hours,day,date,month,year)     ' Read DS3231
        HI2CIN $11, (TempMsb,TempLsb)                         ' Read DS3231 Temperature -40 C to +85 C
      HI2Csetup OFF : dirsB = %11111111                       ' Restore Outputs after using HI2Cin
      
  ClockDisplay:
        AM_PM = "A" : IF hours > $60 THEN : AM_PM ="P": ENDIF '  Indicate AM or PM 
  
   D5 = hours  &$10 /$10 +$30 : IF D5 = "0" THEN : D5 = " " : ENDIF 'Zero blanking    
   D4 = hours //$10 +$30
   D3 = mins   /$10 +$30
   D2 = mins  //$10 +$30
  
   halfsecond = time //2 
          dot ="." : IF halfsecond =0 THEN : dot =" " : ENDIF ' Dot idicating second seperator
  
    LOW  RS : senddata = 128 : PULSOUT E,1              	  ' CommandMode (128-147)  Line 1 Cursor Position  
    HIGH RS                                                   ' CharacterMode
      FOR  index = 0 TO 7                                     ' sending characters to LCD line one 
 	  LOOKUP index,(D5,D4,dot,D3,D2," ",AM_PM,"M"),senddata : PULSOUT E,1            
 	NEXT index	
 		 
GOTO Main
 
Top