Totally Lost

hippy

Ex-Staff (retired)
My interpretation of the C code below. You'll need to set the Symbols to the pins you are actually using and the C code seems to be initialising for 3V3 operation so you will have to alter the initialisation as well if using 5V.

Code:
Symbol LCD_CLK = 3
Symbol LCD_DO  = 2
Symbol LCD_RS  = 4
Symbol LCD_CS  = 1

High LCD_CS

b0 = $38 : Gosub outLCD
b0 = $39 : Gosub outLCD
b0 = $15 : Gosub outLCD
b0 = $55 : Gosub outLCD
b0 = $6E : Gosub outLCD
b0 = $72 : Gosub outLCD
b0 = $0F : Gosub outLCD
b0 = $01 : Gosub outLCD
b0 = $06 : Gosub outLCD

b0 = "H" : Gosub dataLCD
b0 = "e" : Gosub dataLCD
b0 = "l" : Gosub dataLCD
b0 = "l" : Gosub dataLCD
b0 = "o" : Gosub dataLCD

End

dataLCD:
  Low  LCD_CS
  High LCD_RS
  Goto xxxLCD

outLCD:
  Low LCD_CS
  Low LCD_RS

xxxLCD:
  For b1 = 0 To 7
    If bit7 = 0 Then
      Low LCD_D0
    Else
      High LCD_D0
    End If
    High LCD_CLK
    Low  LCD_CLK
    b0 = b0 * 2
  Next
  High LCD_RS
  High LCD_CS
  Return
 

marcos.placona

Senior Member
Hippy, thanks for the hands on, I'll sure try it out, and see if I get any luck.

In fact, I've just found something that's been tested with this kind of display.

It was posted on the pic forums, and uses basic.

I understood most of the code, but have no idea about how to replace the "fuses" and the lcdout. I believe I can use the same outlcd you used on your code example, but am not really sure how to pass the "lcdout $FE, $28" which seems to be necessary.

I'm gonna put the code here and see if anyone can help me. I'll definitely make this work today, or throw them away. I promise that.

Code:
'****************************************************************
'*  Name    : LCD-EA_DOG-M_2x16_4bits_16F690.BAS                *
'*  Author  : FLOTUL                                            *
'*  Notice  : Copyright (c) 2006 Flotulopex & Co.               *
'*          : All Rights Reserved                               *
'*  Date    : 22.09.2007                                        *
'*  Version : 1.0                                               *
'*  Notes   : ELECTRONIC ASSEMBLY DOG-M162L-A LCD display       *
'*  Tested  : yes                                                *
'*  Finished: no                                                *
'****************************************************************

' LCD circuitery
'23,24,25,26,32,33,34,35,40 - Vdd (+5V)
'27,37,38 - Vss (GND)
'35 DB0   - PORTC.0 - set to 1 (+5V) in 4 bits mode
'34 DB1   - PORTC.1 - set to 1 (+5V) in 4 bits mode
'33 DB3   - PORTC.2 - set to 1 (+5V) in 4 bits mode
'32 DB4   - PORTC.3 - set to 1 (+5V) in 4 bits mode
'31 DB4   - PORTC.4
'30 DB5   - PORTC.5
'29 DB6   - PORTC.6
'28 DB7   - PORTC.7
'39 RS    - PORTB.5
'36 E     - PORTB.4
'37 R/W   - 'Vss (GND)

'-------------------------------------------------------------------------------
' Fuses
@ DEVICE PIC16F690,FCMEN_OFF
@ DEVICE PIC16F690,IESO_OFF
@ DEVICE PIC16F690,BOD_OFF
@ DEVICE PIC16F690,CPD_OFF
@ DEVICE PIC16F690,PROTECT_OFF
@ DEVICE PIC16F690,MCLR_OFF
@ DEVICE PIC16F690,PWRT_OFF
@ DEVICE PIC16F690,WDT_OFF
@ DEVICE PIC16F690,INTRC_OSC_NOCLKOUT

'-------------------------------------------------------------------------------
' Registers   76543210
OPTION_REG = %10000000 'PORT A&B Pull-Ups disabled (look WPUA & WPUB)
'OSCCON     = %01100000 'Internal RC set to 4Mhz - not to be used with XTal
ANSEL      = %00000000 'Disable analog inputs Channels 0 to 7
ANSELH     = %00000000 'Disable analog inputs Channels 8 to 11
ADCON0     = %00000000 'A/D Module is OFF
CM1CON0    = %00000000 'Comparator1 Module is OFF
CM2CON0    = %00000000 'Comparator2 Module is OFF
INTCON     = %00000000 'INTerrupts CONtrol
TRISA      = %00000000 'Set Input/Output (0 to 5)
PORTA      = %00000000 'Ports High/Low (0 to 5)
TRISB      = %00000000 'Set Input/Output (4 to 7)
PORTB      = %00000000 'Ports High/Low (4 to 7)
TRISC      = %00000000 'Set Input/Output (0 to 7)
PORTC      = %00001111 'Ports High/Low (0 to 7)

'-------------------------------------------------------------------------------
' Defines
DEFINE LCD_DREG PORTC   'LCD data port 
DEFINE LCD_DBIT 4       'LCD data starting bit 0 or 4 on µC 
DEFINE LCD_RSREG PORTB  'LCD register select port 
DEFINE LCD_RSBIT 5      'LCD register select bit
DEFINE LCD_EREG PORTB   'LCD enable port
DEFINE LCD_EBIT 4       'LCD enable bit 
DEFINE LCD_BITS 4       'LCD bus size 4 or 8 
DEFINE LCD_LINES 2      'Number lines on LCD 

'-------------------------------------------------------------------------------
' Variables

'-------------------------------------------------------------------------------
' Init display

' COG Mandatory settings
pause 200       'Time to settle Vdd (IMPORTANT!!!)
lcdout $FE, $28 'Function Set: 4 bit bus mode
lcdout $FE, $1C
lcdout $FE, $52
lcdout $FE, $69

'COG Optional settings
'Lcdout $FE, $74 'Contrast
'lcdout $FE, $38
'lcdout $FE, $0F
'Lcdout $FE, $01
'Lcdout $FE, $06

'-------------------------------------------------------------------------------
' Program
lcdout $FE,2    'Return cursor Home first or you start at position 2!
DISPLAY:
    LCDOUT $FE,1,"2 Lines Display",$FE,$C0,"4 bit bus mode"
    pause 1500
    LCDOUT $FE,1,"LCD-Module",$FE,$C0,"EA DOGM162"
    pause 1500
    goto display
end
 

Dippy

Moderator
'Fuses' and config are general settings mostly to set up the PIC when doing programming via a harware programmer. They have no relevance with PICAXE programming.

Most of the other things are not rel to PICAXE either. They are register/port settings which you don't have to worry about with PICAXE.

That drop of code won't help you much as it uses a built-in LCDOUT command which does all the things your are trying to do.
I don't know what compiler that's from, I'm not going to guess.

Bottom line, apart from a few 'constant' setting/setup values it won't help you at all.
 

marcos.placona

Senior Member
'Fuses' and config are general settings mostly to set up the PIC when doing programming via a harware programmer. They have no relevance with PICAXE programming.

Most of the other things are not rel to PICAXE either. They are register/port settings which you don't have to worry about with PICAXE.

That drop of code won't help you much as it uses a built-in LCDOUT command which does all the things your are trying to do.
I don't know what compiler that's from, I'm not going to guess.

Bottom line, apart from a few 'constant' setting/setup values it won't help you at all.
But wouldn't there be a way for me to send "$FE, $28" from the picaxe to the LCD?

Cheers
 

Dippy

Moderator
Yes, those are things that hippy has shown you in all his writing to LCD code.
That snippet you showed assigns a port to 4 bit parallel where it would send 2 x 4bits parallel. The mystery compiler's LCDOUT command is doing all the Register select (RS) and Enable (E) high/lows i.e. unless you could see the assm you can't see what it is doing.
 

hippy

Ex-Staff (retired)
But wouldn't there be a way for me to send "$FE, $28" from the picaxe to the LCD?
I'd guess $FE is simply an indicator to the LCDOUT command that the next byte should be sent to the Control Register of the LCD rather than the Data Register. Apart from passing things through the LCDOUT command that Basic Code looks to be very much like the standard ( my own and Rev-Ed's ) code used to handle any Parallel LCD.

Apart from the values used for initialisation we're not really learning much new. One would have to look at what the initialisation values mean according to the datasheet to understand what each are doing, then it should be a case of putting those into existing parallel LCD driver code and adding the necessary delays.

If it works, "Tada!", if not, it's back to head scratching. If confident that the software is working and initialisation is correct, that points to incorrect wiring or a faulty display.

This is the nature of getting something unknown working; very frustrating and time consuming. It should simply 'just work', when it doesn't it's hard to solve without hands-on access and all the necessary tools, scopes, logic analysers. At the back of my mind I cannot help but worry you could have already damaged the displays from mis-wiring earlier on and are simply beating a dead horse.
 

marcos.placona

Senior Member
@hippy I don't think this is the case, as as was doing most of my tests with just one of them, as as soon as I was sure the wiring was ok, I tried the other one. It doesn't seem to be easy to make those suckers work, as stated on other threads I found on pic's forum, but eventually one makes it work.

It's ok, I'm doing it as a hobby, so I've got plenty of time to make it work, and would like to thank you all guys again for all the support.

I'm coming down to London on the next Friday 23/05, so if anybody fancy a beer after work, just drop me a line. :D
 

marcos.placona

Senior Member
UPDATE

After many different tries tries and no results at all, I'm sending the displays back to the manufacturer and see what they have to say.

Let's see if I come up with good news.

Cheers
 

Dippy

Moderator
Are you going to order some 'normal' ones so you can get some code working?

I guess sending them back is a positive move, but it's difficult to predict a response.
If you've soldered them then , assuming they are duff, then they may question your soldering. In my view a fair enough question.
Did you confess you'd wired one up wrong?
Or, of course, the supplier makes them work and may charge a handling fee to return them to you. I didn't check the T&C.

In any event, good luck and I hope you get it all working at some stage.
 

marcos.placona

Senior Member
Hi guys, I guess I should post an update on this one. I got the LCD's back, and it turns out there was nothing wrong with them.

Strangely, I've just tried the same circuit, and now they work :D

Well, in parts. It displays the cursor, but doesn't display any text on screen.

I used part of hippy's code, and made some changes to same variables the LCD needs. It starts fine now, but still doesn't display text.

I've made a video to show you how it stands up to now....

http://www.youtube.com/watch?v=ScAiFPifGVQ

As per my code, it looks like this now:

Code:
;               __
;    Input 2 -o|  |o- Input 1
; Serial Out -o|  |o- Input 0
;  Serial In -o|  |o- Input 7
;      Reset -o|  |o- Input 6
;         0V -o|  |o- +V
;   Output 0 -o|  |o- Output 7
;   Output 1 -o|  |o- Output 6
;   Output 2 -o|  |o- Output 5
;   Output 3 -o|  |o- Output 4
;               --
        SYMBOL  RS        = 0         ; 0 = Command   1 = Data
        SYMBOL  E         = 2         ; 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  byteo     = b12
        SYMBOL  rsbit     = b13
        
        
        ' Nibble commands - To initialise 4-bit mode

        EEPROM 0,( $33 )    ; set interface
        EEPROM 1,( $32 )    ; set interface

        ' Byte commands - To configure the LCD
        EEPROM 2,( $29 )    ; set lines
        EEPROM 3,( $14 )    ; set bias OSC
        EEPROM 4,( $78 )    ; set contrast
        EEPROM 5,( $00 )    ; set power, icon, contrat
        EEPROM 6,( $6D )    ; set follower
        EEPROM 7,( $0F )    ; set fidplay on/off
        EEPROM 8,( $01 )    ; Clear Screen
        EEPROM 9,( $06 )     ; entry mode set
              
        'Text to display
        EEPROM 10,("Hello")

     'Must pause in order to initialize
     pause 40

    PowerOnReset:
    {
        GOSUB InitialiseLcd

     }
     
    display:
     {
        FOR get = 10 TO 14
          READ 10,byteo
          GOSUB SendDataByte
        NEXT
           
    }
          
     
    InitialiseLcd:
     {
            'Function set
         READ 0,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         'Function set
         READ 1,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         
         'set line
         READ 2,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         'Internal OSC Frequency
         READ 3,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         'Contrast Set
         READ 4,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         
         'Power / contrast control
         READ 5,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         'Follower Control
         READ 6,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         'Display on / off
         READ 7,byteo
         GOSUB SendInitCmdByte
         pause 30
         
         'Clear Display
         READ 8,byteo
         GOSUB SendInitCmdByte
         pause 200
         
         'Function set
         READ 9,byteo
         GOSUB SendInitCmdByte
         pause 30
        
        RETURN
     }        


    SendInitCmdByte:
    {

        PAUSE 50                        ; Delay 50mS
    }

    SendCmdByte:
    {

        rsbit = RSCMDmask               ; Send to Command register
    }

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

        rsbit = RSDATmask               ; Send to Data register next

        RETURN
     }
Any help would be appreciated.

At least no I know it's something on my code :p

UPD: I tried to also put an END after the inside the display function, but this just makes the cursor fade away
 
Last edited:
Top