Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC 16f628A -LCD Control

Status
Not open for further replies.

SwingeyP

Member
Hello. Can anyone tell me whats wrong with this code / circuit.

The idea will be to have a menu here and the 3 buttons select an option. (im not that clever though yet)

At present I am just trying to write to the LCD ignoring the busy lines and using a delay. I think you'll see what im doing. However nothing is happening. I have tried the pic on my test board and i would have at least thought i'd see a few led's light up on port B.

Any ideas?

Many thanks Paul
 

Attachments

  • lcd_Driver_Schematic.jpg
    lcd_Driver_Schematic.jpg
    122.2 KB · Views: 877
  • LCD_Paul.asm
    2.5 KB · Views: 368
Hello. Can anyone tell me whats wrong with this code / circuit.
The idea will be to have a menu here and the 3 buttons select an option. (im not that clever though yet)
At present I am just trying to write to the LCD ignoring the busy lines and using a delay. I think you'll see what im doing. However nothing is happening. I have tried the pic on my test board and i would have at least thought i'd see a few led's light up on port B.
Any ideas?
Many thanks Paul
the program might not work
but perhaps you may have to write AGAIN, see list below only how to start with, the best are Nigel's tutorials at
Code:
    list            p=16f628a
    #include     <P16F628A.inc>                ;Tell the assembler to generate code for this device
     errorlevel    -302
    __config     03F41H    ;_XT_OSC & _PWRTE_ON & _WDT_OFF & _CP_OFF & _BODEN_ON & _LVP_OFF    & _MCLR_OFF

counter_reg    equ    0x20
short_delay    equ    0x21
long_delay    equ    0x22
             
            movlw    0x07    
            movwf    CMCON                ;make all pins i/0
            
            goto start

 
start            clrf        counter_reg    ;Clear register   (Counter Register)
                clrf        short_delay    ;Clear register   (Short Delay Register)
                clrf        long_delay    ;Clear register   (Long Delay Register)
                clrf        PORTA        ;PORT A (Register 05) Set all outputs to logic 0
                clrf        PORTB        ;PORT B (Register 06) Set all outputs to logic 0
setports        movlw        0xF8        ;PORT A bits 0,1,2 as outputs (E,RS,RW)
                MOVWF        TRISA        ;05            
                movlw        00            ;Port B all bits as outputs (DO - D7)
                MOVWF        TRISB        ;06
longdelay        call        shortdelay    ;Delay while LCD initialises
                decfsz        long_delay,f
                goto         longdelay    
functionset        bcf        PORTA,02        ;RS line to 0 (Port A, bit2)
                bcf        PORTA,01        ;R/W line to 0 (Port A, bit 1)
                movlw        38            ;Function set command (00111000 - 8 bit transfer, 2 line mode, 5x10 dot format)
                movwf        06            ;Put this code on the data lines Port B
                call        pulse_E    ;Call the routine to pulse the E line (Port A bit 0)
                call        shortdelay    ;Give it time to get it
displayon        bcf        05,02        ;RS line to 0 (Port A, bit2)
                bcf        05,01        ;R/W line to 0 (Port A, bit 1)
                movlw        0F            ;Display on/off & curosr (00001111 - Display on, Cursor Underline, Cursor Blink)
                movwf        06            ;Put this code on the data lines Port B
                call        pulse_E        ;Call the routine to pulse the E line (Port A bit 0)
                call        shortdelay    ;Give it time to get it
                clrf        counter_reg    ;Set counter register to zero
getchar            movf        counter_reg,w        ;Put the counter value in the W register (now we can use it)
                call        text        ;Get a character from te text table below
                bsf        05,02        ;RS line to 1 (Port A, bit2)
                bcf        05,01        ;R/W line to 0 (Port A, bit 1)
                movwf        06            ;Put the character fetched from the table on Port B
                call         pulse_E        ;Call the routine to pulse the E line (Port A bit 0)
                call        shortdelay    ;Give it time to get it
                incf        counter_reg,w        ;Try incrementing the counter register
                xorlw        05            ;Is the counter register at 5?
                btfsc        03,02        ;Set the zero flag in the status register
                goto        stop        ;Stop if all characters displayed
                incf        counter_reg,f        ;Increment the counter register
                goto        getchar        ;Go back and get the next character
stop            goto        stop        ;Stop the program

;Here are the subroutines

shortdelay        decfsz        short_delay,f        ;Delay while the LCD is busy
                goto        shortdelay
                retlw        0
pulse_E        bsf            05,00        ;Set the E line High
                nop                        ;wait for a clock cycle
                bcf            05,00        ;Set the E line low again
                retlw        0
text            addwf        02,f
                retlw        'H'
                retlw        'E'
                retlw        'L'
                retlw        'L'
                retlw        'O'
    end
 
Last edited:
Thanks. I have seen that tutorial before and its very useful. However I need to know what's wrong with the above. Is it code or electronics? - Nothing will be learnt from just copying the code in the above tutorials.
 
Last edited:
after i read your code I thing you should use (ORG or CODE) directors to identify the beaning
of the program, which will be written in the program memory like this:

start CODE 0x000
goto start
Interrupt CODE 0x004
goto int
main CODE 0x005
goto main

I hope that I helped you
 
Thanks. I have seen that tutorial before and its very useful. However I need to know what's wrong with the above. Is it code or electronics? - Nothing will be learnt from just copying the code in the above tutorials.
i fear your delay loops were not in order

now i tried to change them, ( me too a learner),see the code below now works
Code:
      list            p=16f628a
    #include     <P16F628A.inc>                ;Tell the assembler to generate code for this device
     errorlevel    -302
    __config      _XT_OSC & _PWRTE_ON & _WDT_OFF & _CP_OFF & _BODEN_ON & _LVP_OFF    & _MCLRE_OFF

counter_reg    equ    0x20
short_delay    equ    0x21
long_delay    equ    0x22
 
            movlw    0x07    
            movwf    CMCON                ;make all pins i/0
            goto     start
 
start            clrf        counter_reg    ;Clear register   (Counter Register)
                clrf        short_delay    ;Clear register   (Short Delay Register)
                clrf        long_delay    ;Clear register   (Long Delay Register)
                clrf        PORTA        ;PORT A (Register 05) Set all outputs to logic 0
                clrf        PORTB        ;PORT B (Register 06) Set all outputs to logic 0
setports        BSF            STATUS,RP0
                movlw        0xF8        ;PORT A bits 0,1,2 as outputs (E,RS,RW)
                MOVWF        TRISA             
                movlw        0X00        ;Port B all bits as outputs (DO - D7)
                MOVWF        TRISB        ;06
                BCF            STATUS,RP0
longdelay          
                clrf    long_delay
                
ldelay            call    SDELAY    ;Delay while LCD initialises
                decfsz        long_delay,f
                goto         ldelay    
functionset        bcf            PORTA,2            ;RS line to 0 (Port A, bit2)
                bcf            PORTA,1            ;R/W line to 0 (Port A, bit 1)
                movlw        38            ;Function set command (00111000 - 8 bit transfer, 2 line mode, 5x10 dot format)
                movwf        PORTB        ;Put this code on the data lines Port B
                call        pulse_E        ;Call the routine to pulse the E line (Port A bit 0)
                call        SDELAY    ;Give it time to get it
displayon        bcf            PORTA,2        ;RS line to 0 (Port A, bit2)
                bcf            PORTA,1        ;R/W line to 0 (Port A, bit 1)
                movlw        0F            ;Display on/off & curosr (00001111 - Display on, Cursor Underline, Cursor Blink)
                movwf        PORTB        ;Put this code on the data lines Port B
                call        pulse_E        ;Call the routine to pulse the E line (Port A bit 0)
                call        SDELAY    ;Give it time to get it
                clrf        counter_reg    ;Set counter register to zero
getchar            movf        counter_reg,w    ;Put the counter value in the W register (now we can use it)
                call        text        ;Get a character from te text table below
                bsf            PORTA,2        ;RS line to 1 (Port A, bit2)
                bcf            PORTA,1        ;R/W line to 0 (Port A, bit 1)
                movwf        PORTB        ;Put the character fetched from the table on Port B
                call         pulse_E        ;Call the routine to pulse the E line (Port A bit 0)
                call        SDELAY    ;Give it time to get it
                incf        counter_reg,w        ;Try incrementing the counter register
                xorlw        05            ;Is the counter register at 5?
                btfsc        STATUS,2        ;Set the zero flag in the status register
                goto        stop        ;Stop if all characters displayed
                incf        counter_reg,f        ;Increment the counter register
                goto        getchar        ;Go back and get the next character
stop            goto        stop        ;Stop the program

;Here are the subroutines


pulse_E            bsf        PORTA,0    ;Set the E line High
                nop                        ;wait for a clock cycle
                bcf        PORTA,0        ;Set the E line low again
                retlw        0

SDELAY             
                clrf    short_delay
shortdelay        decfsz        short_delay,f        ;Delay while the LCD is busy
                goto        shortdelay
                 retlw        0
text            addwf        02,f
                retlw        'H'
                retlw        'E'
                retlw        'L'
                retlw        'L'
                retlw        'O'
    end
perhaps it can be simplified further
 
Last edited:
This is a common problem for most of microcontroller fans when try to use LCD, do not worry, you will solve it after you appreciate it.

Is it code or electronics? .

try to adjust the contrast of the LCD ( for hardware ) and the initialization of the LCD ( for program )


- Nothing will be learnt from just copying the code in the above tutorials.

At the beginning try to get it work even by copying the code, then take your time to study it with peaceful mind.
 
Many thanks for amending the delay loops. Yes things appear to be working now on my velleman board (for what I can see) but still nothing on the LCD. First off I had all the outputs mixed up RA0,RA1,RA2. They didn't match the schematic / PCB. I have corrected that and stepped through the code using 'stops'. You can see the stops I put in the code commented out. I see everything I expect to see with a logic probe at all the stops on the velleman board but when transfered to my PCB I have The following :
Pin1 - Nothing detected
Pin2 - Low
Pin3 - Low
Pin4 - Nothing detected
Pin5 - Low
Pin6 - High
Pin7 - High
Pin8 - High
Pin9 - High
Pin10 - High
Pin11 - High
Pin12 - High
Pin13 - High
Pin14 - High
Pin15 - Low
Pin16 - Low
Pin17 - High
Pin18 - High

Looks like there is something wrong with the PCB Ihave made. Can any of you gurus tell me what is wrong please? - Pull up resisitors?

Regards - Paul
 

Attachments

  • LCD_PaulV2.asm
    4.4 KB · Views: 222
ooops sorry that code doesn't have the stops commented. Its my final test for V2. I'm sure you get the idea though. I just put a stop after the delay after each pulse to the E-Line. The final stop in that code I would expect to see a letter H on the data lines. (01001000). The velleman displays only 6 bits but I see 001000 which im sure is right. My electronics must be wrong.
 
Hi. Can anyone please help me with this? - Im pretty sure its the circuit / PCB. Without the LCD connected to the PCB im seeing nothing on any of the pins (except the obvious power lines) with a logic probe. Its a really basic circuit so I don't understan why its not working. As I have said before all seems ok on my Velleman programmer/test board. Agggghhhhhhh...! - PLEASE HELP
 
hi Paul,
Are you saying that you have never seen the LCD working with this final program.???
 
Hello ericgibbs. Yes thats right nothing on the LCD. I can control contrast etc from the PCB I made but nothing else. Infact when I connect the LCD the pins go as above. With the LCD disconnected I get :

Pin1 - Nothing detected
Pin2 - Low
Pin3 - Low
Pin4 - Low
Pin5 - Low
Pin6 - Nothing Detected
Pin7 - Nothing Detected
Pin8 - Nothing Detected
Pin9 - Nothing Detected
Pin10 - Nothing Detected
Pin11 - Nothing Detected
Pin12 - Nothing Detected
Pin13 - Nothing Detected
Pin14 - High
Pin15 - Low
Pin16 - Low
Pin17 - Nothing Detected
Pin18 - Nothing Detected

Some clearly wrong. I can control the LCD from a veroboard tester I made up from an article in EPE Feb 1997. That works with simple switching and I see characters. As I have mentioned before the code seems right. When I step through I see the outputs i'd expect on my Velleman programmer/tester.

Is this something to do with pull up/down resistors? Can the MCRL line be used as an input and do I need to configure anything other than cmcon and mcrle?

Im sure this is an electronics problem though.
 
hi,
Your program will not run in my Oshonsoft simulator , the LCD set up delays are too short , so the LCD is not being initialised correctly.
 
Hi again. Its been quite a nice day here in Brum. I live north of the city near Sutton Coldfield. Thanks for your help with this. I now have code version 3. This one calls a 20ms delay after each pulse of the E-Line. What do you think? - Although there may be a few errors in timing of the code im still not convinced this is the only thing. Does the circuit look right?

Regards - Paul
 

Attachments

  • LCD_PaulV3.asm
    4.3 KB · Views: 209
hi Paul,
Downloaded your program, will try it later today.
 
Hello again Eric. I have just tried the simulator package you mentioned. BRILLIANT! - I have run the program through it and it worked. Takes a while to get through those 20ms delays even at extremely fast.

I burned the chip (with the stop in the right place) transferred it to my PCB but no luck so it has to be something to do with that. I have no idea why though. It's a very simple circuit. I think im going to try removing the 3 switches and just going with the basic data and control pins to the lcd.

Thanks again for your help so far.

Regards - Paul
 
Hello again Eric. I have just tried the simulator package you mentioned. BRILLIANT! - I have run the program through it and it worked. Takes a while to get through those 20ms delays even at extremely fast.

I burned the chip (with the stop in the right place) transferred it to my PCB but no luck so it has to be something to do with that. I have no idea why though. It's a very simple circuit. I think im going to try removing the 3 switches and just going with the basic data and control pins to the lcd.

Thanks again for your help so far.

Regards - Paul

hi Paul,
Look at this link, you may find some one these Oshonsoft external modules useful.
With regard to those long simulation delays, its possible to use conditional statements in your program, so that the delays are shortened in simulation.
 
As long as the switches are not in the program, it should not bother you, I feel. anyway simulator showing is different.
I was sure when I posted the V2 of asm, as I tested it on mplab simulator and I saw the ascii code for the HELLO" on the PORTB..

but timings I was not certain, especially a single clock cycle for E line enable /disable
 
Hi Sarma. I changed the code again in V3 to have a 20ms delay on all actions. It's maybe too long for many of the actions but it will do for now. The specification sheet says that timings can be a lot less. I have this running now in simulation but not on the PCB I made. Is there something wrong with the configuarion word? Do I need to switch pullups on / off. This is very frustrating. All the circuits i have seen are very similar to mine.
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top