![]() | ![]() | ![]() |
| |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
![]() |
| | Tools |
| | #1 |
|
I'm trying to do an example set in a book to learn how to use an LCD in a project, however i've copied the code out and it doesn't work, in previous examples of code there have been errors in the book and i've managed to find them and get the code to work. I can't figure this one out!! When connected I get a line of solid characters across the 1st line of the LCD and that's it, which is the same as I get if the chip is not connected and the LCD is just powered up. I am supposed to just be using 4 data lines. R/W tied to ground RS - A1 E - A2 Using a 16F84A as this was the one in the book, not the controller of my choice but I want to get the thing working on this before moving on!! Can anybody advise on any code issues? Code: ;ANHEAD84.ASM Alphanumeric display header using 6 I/O lines. ;On the display RS pin 4 connects to A1. ;R/W pin 5 connects to 0v. ;E pin 6 connects to A2 ;D4-D7 pins 11-14 connect to B0-B7. TMR0 EQU 1 ;TMR0 is FILE 1. PORTA EQU 5 ;PORTA is FILE 5. PORTB EQU 6 ;PORTB is FILE 6. STATUS EQU 3 ;STATUS is FILE3. ZEROBIT EQU 2 ;ZEROBIT is Bit 2. ;********************************************************* LIST P=16F84 ;We are using the 16F84. ORG 0 ;0 is the start address. GOTO START ;goto start! ;********************************************************* ; SUBROUTINE SECTION. ;3 SECOND DELAY DELAY3 CLRF TMR0 ;START TMR0 LOOPA MOVF TMR0,W ;READ TMR0 IN W SUBLW .96 ;TIME - W BTFSS STATUS,ZEROBIT ;CHECK TIME-W=0 GOTO LOOPA RETLW 0 ;return after TMR0 = 96 ;P1 SECOND DELAY DELAYP1 CLRF TMR0 ;START TMR0 LOOPC MOVF TMR0,W ;READ TMR0 IN W SUBLW .3 ;TIME - W BTFSS STATUS,ZEROBIT ;CHECK TIME-W=0 GOTO LOOPC RETLW 0 ;return after tmr0 = 3 CLOCK BSF PORTA,2 NOP BCF PORTA,2 NOP RETLW 0 ;********************************************************* A MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 1H ;41 is code for A MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 BB MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 2H ;42 is code for B MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 C MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 3H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 D MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 4H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 E MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 5H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 F MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 6H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 G MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 7H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 H MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 8H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 I MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 9H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 J MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 0AH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 K MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 0BH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 L MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 0CH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 M MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 0DH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 N MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK ;clock character onto display. MOVLW 0EH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 O MOVLW 2 ;enables the display MOVWF PORTA MOVLW 4H MOVWF PORTB CALL CLOCK MOVLW 0FH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 P MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 0H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 Q MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 1H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 R MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 2H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 S MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 3H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 T MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 4H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 U MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 5H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 V MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 6H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 WW MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 7H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 X MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 8H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 Y MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 9H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 Z MOVLW 2 MOVWF PORTA MOVLW 5H MOVWF PORTB CALL CLOCK MOVLW 0AH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM0 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 0H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM1 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 1H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM2 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 2H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM3 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 3H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM4 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 4H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM5 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 5H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM6 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 6H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM7 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 7H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM8 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 8H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 NUM9 MOVLW 2 ;enables the display MOVWF PORTA MOVLW 3H MOVWF PORTB CALL CLOCK MOVLW 9H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 GAP MOVLW 2 MOVWF PORTA MOVLW 2H MOVWF PORTB CALL CLOCK MOVLW 0H MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 DOT MOVLW 2 MOVWF PORTA MOVLW 2H MOVWF PORTB CALL CLOCK MOVLW 0EH MOVWF PORTB CALL CLOCK ;clock character onto display. RETLW 0 CLRDISP CLRF PORTA MOVLW 0H MOVWF PORTB CALL CLOCK ;clock command onto display. MOVLW 1 MOVWF PORTB CALL CLOCK CALL DELAYP1 RETLW 0 ;********************************************************* ; CONFIGURATION SECTION. START BSF STATUS,5 ;Turn to BANK1 MOVLW B'00000000' ;5 bits of PORTA are O/Ps. TRIS PORTA MOVLW B'00000000' TRIS PORTB ;PORTB IS OUTPUT MOVLW B'00000111' OPTION ;PRESCALER is /256 BCF STATUS,5 ;Return to BANK0 CLRF PORTA ;Clears PORTA CLRF PORTB ;Clears PORTB ;Display Configuration MOVLW 03H ;FUNCTION SET MOVWF PORTB ;8bit data (default) CALL CLOCK CALL DELAYP1 ;wait for display MOVLW 02H ;FUNCTION SET MOVWF PORTB ;change to 4bit CALL CLOCK ;clock in data CALL DELAYP1 ;wait for display MOVLW 02H ;FUNCTION SET MOVWF PORTB ;must repeat command CALL CLOCK ;clock in data CALL DELAYP1 ;wait for display MOVLW 08H ;4 bit micro MOVWF PORTB ;using 2 line display. CALL CLOCK ;clock in data CALL DELAYP1 MOVLW 0H ;Display on, cursor off MOVWF PORTB ;0CH CALL CLOCK MOVLW 0CH MOVWF PORTB CALL CLOCK CALL DELAYP1 MOVLW 0H ;Increment cursor, 06H MOVWF PORTB CALL CLOCK MOVLW 6H MOVWF PORTB CALL CLOCK ;******************************************************** ;Program starts now. BEGIN CALL CLRDISP MOVLW 8H ;Cursor at top left, 80H MOVWF PORTB CALL CLOCK MOVLW 0H MOVWF PORTB CALL CLOCK CALL M ;display M CALL DELAYP1 ;wait 0.1 seconds CALL I ;display I CALL DELAYP1 ;wait 0.1 seconds CALL C ;Etc. CALL DELAYP1 CALL R CALL DELAYP1 CALL O CALL DELAYP1 CALL C CALL DELAYP1 CALL O CALL DELAYP1 CALL N CALL DELAYP1 CALL T CALL DELAYP1 CALL R CALL DELAYP1 CALL O CALL DELAYP1 CALL L CALL DELAYP1 CALL L CALL DELAYP1 CALL E CALL DELAYP1 CALL R CALL DELAYP1 CALL S CALL DELAYP1 CLRF PORTA MOVLW 0CH ;Cursor on second line, C3 MOVWF PORTB CALL CLOCK MOVLW 3H MOVWF PORTB CALL CLOCK CALL A CALL DELAYP1 CALL T CALL DELAYP1 CALL GAP CALL T CALL DELAYP1 CALL H CALL DELAYP1 CALL E CALL DELAYP1 CALL GAP CALL M CALL DELAYP1 CALL M CALL DELAYP1 CALL U CALL DELAYP1 CALL DELAY3 ;wait 3 seconds CALL CLRDISP MOVLW 8H ;Cursor at top left, 80H MOVWF PORTB CALL CLOCK MOVLW 0H MOVWF PORTB CALL CLOCK CALL C CALL DELAYP1 CALL O CALL DELAYP1 CALL N CALL DELAYP1 CALL T CALL DELAYP1 CALL A CALL DELAYP1 CALL C CALL DELAYP1 CALL T CALL DELAYP1 CLRF PORTA MOVLW 0CH ;Cursor on 2nd line MOVWF PORTB CALL CLOCK MOVLW 3H MOVWF PORTB CALL CLOCK CALL D CALL DELAYP1 CALL A CALL DELAYP1 CALL V CALL DELAYP1 CALL E CALL DELAYP1 CALL GAP CALL DELAYP1 CALL S CALL DELAYP1 CALL M CALL DELAYP1 CALL I CALL DELAYP1 CALL T CALL DELAYP1 CALL H CALL DELAY3 ;wait 3 seconds GOTO BEGIN END | |
| |
| | #2 |
|
wow...that looks a little simplified and over fussy for controlling an lcd module... I'm sure there is far better code than that available to you... try using Nigel's code, or go to the piclist and snag some from there or something... | |
| |
| | #3 |
|
Any idea what's wrong with this code though? I would like to use another code but I am very new to this and would prefer to find help with this code first before moving on. I can't figure out where there's a problem.
| |
| |
| | #4 |
|
DER!!! I missed out a line!! __CONFIG H'3FF0' | |
| |
| | #5 |
|
Please check Delaying. Each LCD command need to delay for a while to operate.
__________________ Microcontroller Programming Forums: http://forum.mcuprogramming.com Answer to your questions! --- Microcontroller Programming Blog: http://mcu-programming.blogspot.com uC - News, Resources and Tutorials | |
| |
| | #6 |
| | |
| |
| | #7 |
|
Hi, if you have problem with lcd, please try this: Set LCD Data port DEFINE LCD_DREG PORTB ' Set starting Data bit (0 or 4) if 4-bit bus DEFINE LCD_DBIT 4 ' Set LCD Register Select port DEFINE LCD_RSREG PORTB ' Set LCD Register Select bit DEFINE LCD_RSBIT 1 ' Set LCD Enable port DEFINE LCD_EREG PORTB ' Set LCD Enable bit DEFINE LCD_EBIT 0 ' Set LCD bus size (4 or 8 bits) DEFINE LCD_BITS 4 ' Set number of lines on LCD DEFINE LCD_LINES 2 pause 100 lcdout $fe,1,"Hello" end LCD Connection Pin1=Vss: connect to ground Pin2=Vdd: connect to Vcc=5V Pin3=Vo: connect to middle pin of the POT(20K) to control brightness Pin4=RS(register select): connect to micro pins that specify in the software(RB1) Pin5=RW(Read/Write): connect to ground because we want to only write Pin6=E(Enable): connect to micro pin that specify in the software(RB0) Pin7 to 10: No connection Pin 11 to 14: connect to RB4 to RB7 Pin15: connect to Vcc with a resistor(100 or 200 ohm resistor is good) Pin16: connect to ground. pin 16 and pin 16 are for backligh this a very simple code for lcd.if you don't have problem with this program so you have problem in another part. | |
| |
| | #8 | |
| Quote:
| ||
| |
| | #9 |
|
Hi, you are right. he writes his program in assembelly. | |
| |
| | #11 |
|
Thanks for all the replies, I am just learning from the very beginning about programming PIC, I use assembly language as I feel I can relate to it better than other languages, I have no previous programing experience and understood nothing about registers etc. Thanks to this site and others including Nigels very excellent tutorials I am having more eureka moments!! I am now making an electrical flush system with LCD display for a toilet, i've adapted and written new code for this and it works fine on the breadboard. Next is photo etch the board and install it!! Thanks | |
| |
| | #12 | |
| Quote:
![]() I am dying to know what messages you are going to put on your LCD!
__________________ Regards MATT! | ||
| |
| | #13 |
|
LOL, no daft messages on the finished project!! Although I have had a few choice phrases while testing. I have been working with the ISD2532 playback/record chip on another project and had thoughts of adding sound effects to it.........but i'm not going to!! It isn't for my home so it has to be sensible!! I could add a small fanfare for 1 million flushes!!
| |
| |
| | #14 |
|
maybe ya need a strain gauge Last edited by tunedwolf; 9th November 2006 at 02:30 PM. | |
| |
| | #15 |
|
help Program 18F4520 with LCD
| |
| |
|
| Tags |
| code, lcd, problem |
| Thread Tools | |
| Display Modes | |
| |
Similar | ||||
| Title | Starter | Forum | Replies | Latest |
| problem with timer code | nicoli | Micro Controllers | 5 | 9th November 2005 01:27 AM |
| Problem with Code: Help | Electrix | Micro Controllers | 7 | 29th September 2005 08:42 PM |
| Tough assembly program for the PIC16F84 | asmpic | Micro Controllers | 34 | 3rd December 2004 07:50 PM |
| weird pic code problem | Fletcher | Micro Controllers | 9 | 13th October 2004 03:39 PM |
| An error in pic16f84a, why? | Zener_Diode | Micro Controllers | 6 | 11th April 2004 03:55 AM |