Using a 4 bit LCD.

mega

New Member
I have been working on a bit of a project for myself, I want to balance the carburettors on my 1982 1100 Suzuki Katana, I could buy the factory tool, but hey, where is the fun in that....

I decided to use the MAP sensors from a Ford, an 18X Picaxe and a 16x2 LCD in 4 bit mode.

At the moment, the display is a little slow in updating due to my using Count, the MAP sensors have a frequency output that appear to be very close to a 50% duty cycle, I have used pulsin and may go with that, but I thought I'd post up my code so far, most is Hippy's LCD code with some input from George Sephton, thread here, http://www.picaxeforum.co.uk/showthread.php?t=12680&highlight=lcd

It's not finished yet, but is working, I have only partially commented my code, but I think that the general idea of how to use an LCD screen and a few other commands is fairly evident.

I have no circuit diagram for it.... yet.... I used Hippy's LCD diagram, works good.

Any comments and suggestions are welcomed.

Cheers.
Reg.

Code:
; Four cylinder motorcycle carburettor balancing tool using 4 map sensors

;Manifold Absolute Pressure Sensor data
;Using a Ford MAP sensor (frequency output)
;29.92 inHg= Sea Level
;100 kPa = Sea Level

;Manifold Vacuum    MAP Frequency
;inHg 	kPa 	     Hz
;0 		0.00 	    159
;3 		10.2	    150
;5 		16.2 	    146
;6 		20.3      141
;8 		25.7	    134
;9 		30.5 	    133
;11 		36.7 	    126
;12 		40.6 	    125
;13 		45.4 	    121
;14 		47.2 	    119
;15 		50.8      117
;16 		54.0 	    114
;17 		57.0 	    111
;18 		61.0 	    109
;19 		76.3      107
;20 		70.0 	    104
;21 		71.1 	    102
;23 		78.1 	    97
;24 		81.3 	    95
;27 		91.5 	    88
;30 		101.6     80


#picaxe 18x


        SYMBOL  MAP1      = b7
        SYMBOL  MAP2      = b8
        SYMBOL  MAP3      = b9
        SYMBOL  MAP4      = b10
  
        SYMBOL  REVS      = W2
        
        
        SYMBOL  RS        = 2         ; 0 = Command   1 = Data
        SYMBOL  E         = 3         ; 0 = Idle      1 = Active
        SYMBOL  DB4       = 4         ; LCD Data Line 4
        SYMBOL  DB5       = 5         ; LCD Data Line 5
        SYMBOL  DB6       = 6         ; LCD Data Line 6
        SYMBOL  DB7       = 7         ; LCD Data Line 7

        SYMBOL  RSCMDmask = %00000000 ; Select Command register
        SYMBOL  RSDATmask = %00000100 ; Select Data register

        SYMBOL  get       = b11
        SYMBOL  tbyte     = b12
        SYMBOL  rsbit     = b13
               
        
    PowerOnReset:

        GOSUB InitialiseLcd

    DisplayTopLine:

        EEPROM 6,(" 1  2  3  4 REVS")

        FOR get = 6 TO 22
          READ get,tbyte
          GOSUB SendDatatbyte
        NEXT
  
        
 main:       
        debug
        
        
        count 0, 500, MAP1   ' count pulses in 0.5 seconds
        count 1, 500, MAP2
        count 2, 500, MAP3
        count 6, 500, MAP4
        count 7, 1000, REVS  ' count pulses in 1 second
        
        REVS = REVS * 60     ' convert revs per second to revs per minute
        
       
      bintoascii MAP1,b0,b1,b2	 'convert No.1 sensor data to ascii
    
        tbyte = $C0                  'send cursor to start of bottom line
        GOSUB SendCmdtbyte
    
         FOR GET = 0 TO 1            'display counts on lcd
          lookup GET, (b1,b2), tbyte
          gosub SendDatatbyte
         next GET
      
      bintoascii MAP2,b0,b1,b2	 'convert No.2 sensor data to ascii
    
        tbyte = $C3                  'send cursor to third charactor position on bottom line
        GOSUB SendCmdtbyte
    
         FOR GET = 0 TO 1            'display counts on lcd
          lookup GET, (b1,b2), tbyte
          gosub SendDatatbyte
         next GET
         
      bintoascii MAP3,b0,b1,b2	 
    
        tbyte = $C6                  'send cursor to sixth charactor position on bottom line
        GOSUB SendCmdtbyte
    
         FOR GET = 0 TO 1
          lookup GET, (b1,b2), tbyte
          gosub SendDatatbyte
         next GET
         
      bintoascii MAP4,b0,b1,b2	 
    
        tbyte = $C9                   'send cursor to ninth charactor position on bottom line 
        GOSUB SendCmdtbyte
    
         FOR GET = 0 TO 1
          lookup GET, (b1,b2), tbyte
          gosub SendDatatbyte
         next GET
         
      bintoascii REVS,b0,b1,b2,b3,b6	 
    
        tbyte = $CC                   'send cursor to twelth charactor position on bottom line
        GOSUB SendCmdtbyte
    
         FOR GET = 0 TO 3
          lookup GET, (b1,b2,b3,b6), tbyte
          gosub SendDatatbyte
         next GET   
      	 
      goto main
       



    InitialiseLcd:

        FOR get = 0 TO 5
          READ get,tbyte
          GOSUB SendInitCmdtbyte
        NEXT

        ' 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

        ' tbyte 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

    SendInitCmdtbyte:

        PAUSE 15                        ; Delay 15mS

    SendCmdtbyte:

        rsbit = RSCMDmask               ; Send to Command register

    SendDatatbyte:

        pins = tbyte & %11110000 | rsbit ; Put MSB out first
        PULSOUT E,1                     ; Give a 10uS pulse on E
        pins = tbyte * %00010000 | rsbit ; Put LSB out second
        PULSOUT E,1                     ; Give a 10uS pulse on E

        rsbit = RSDATmask               ; Send to Data register next

        RETURN
 
Top