LockedPic 16F84 + 4x20 line LCD

Author
Guest
Super Member
  • Total Posts : 80499
  • Reward points : 0
  • Joined: 2003/01/01 00:00:00
  • Location: 0
  • Status: online
2005/03/20 09:58:35 (permalink)
0

Pic 16F84 + 4x20 line LCD

Hello i am new here and from germany.
I am trying to interface with a pic 16f84A an 44780 based lcd display in c.
But my init routine does not work corectly.
Here some code !!!!!


//
//
// Ansteuerung der LCD-Anzeige 4 x 20 Zeilen
// im 4 Bit Mode
//
// Compiler CC5x

//////////////// Config´s ///////////////////////////////////////
#include"inline.h"

#pragma chip PIC16f84A
#pragma config WDTE=off,FOSC=XT,PWRTE=off
#define _4_MHz /* 4 MHz system clock */

/////////////// Variablen /////////////////////////////////////

//#define Ini_con = 0b.00000000; // TMR0 -> Intetupt disable
//#define Ini_opt = 0b.00000010; // pull-up


/////////////// Port Pins In und Out ///////////////////////////
bit InPortB0 @ PORTB.0;
bit InPortB1 @ PORTB.1;
bit InPortB2 @ PORTB.2;

bit InPortB3 @ PORTB.3;
bit InPortB4 @ PORTB.4;
bit InPortB5 @ PORTB.5;
bit InPortB6 @ PORTB.6;
bit InPortB7 @ PORTB.7;

bit OutPortB0 @ PORTB.0; //Die Enable Leitung schaltet das Interface ein (E=1). Nur wenn Enable auf High-Pegel liegt, läßt sich das Display ansprechen.
bit OutPortB1 @ PORTB.1;
bit OutPortB2 @ PORTB.2; //Die RS (Register-Select)-Leitung bestimmt,ob die übertragenen Daten als Zeichen in den Textpuffer (RS=1),
//oder als Befehl in ein Steuerregister (RS=0) geschrieben werden
bit OutPortB3 @ PORTB.3; //R/W Leitung
bit OutPortB4 @ PORTB.4;
bit OutPortB5 @ PORTB.5;
bit OutPortB6 @ PORTB.6;
bit OutPortB7 @ PORTB.7;

bit InPortA0 @ PORTA.0;
bit InPortA1 @ PORTA.1;
bit InPortA2 @ PORTA.2;
bit InPortA3 @ PORTA.3;
bit InPortA4 @ PORTA.4;

/////////////// Prototypen /////////////////////////////////////

extern void LCDInit();
extern void LCDCls();
extern void LCDPos(unsigned char zeile,unsigned char position);
extern void LCDString(const char *__putstr);

/**************************************************************
* delay verzögerung in ms *
**************************************************************/
void pause(uns16 ms) // Unterprogramm zum Abwarten einer
{ // angegebenen Anzahl von Millisekunden
while(ms) // Schleife verlassen, wenn ms=0 ist
{
OPTION = 2; // Vorteiler auf 8 einstellen

TMR0 = 131; // 125 * 8 = 1000 (= 1 ms)
INTCON &= ~0x04; // T0IF loeschen

while (! (INTCON & 0x04)); // Abwarten einer Millisekunde
ms--; // "ms" mit jeder Millisekunde erniedrigen
}
}

/**************************************************************
* main *
**************************************************************/
void main( void)
{
TRISB = 0b.0000.0000; // PortB als Ausgang definieren 0 = Out / 1 = In
TRISA = 0b.0000.0001; // PortA als Eingang definieren
PORTB = 0; // Alle Ausgänge PORTB löschen
LCDInit();
do{

} while (1);
}

//*********************************************
//Stellt die Funktionsweise der LCD Anzeige ein
//*********************************************


void LCDInit(void)
{
pause(255);
OutPortB2=0; //set RS = low for instruction
OutPortB3=0; //set RW = low to send data to display
OutPortB0=1; //write instruction to LCD
NOP;
OutPortB0=0;

PORTB= 0b00110000; //1 8 Bit
OutPortB0=1; //write instruction to LCD
NOP;
OutPortB0=0;
pause(50);

PORTB= 0b00110000; //2 8 Bit
OutPortB0=1; //write instruction to LCD
NOP;
OutPortB0=0;
pause(46);

PORTB= 0b00110000; //3 8 Bit
OutPortB0=1; //write instruction to LCD
NOP;
OutPortB0=0;
pause(46);

PORTB= 0b00100000; //4 4 Bit Mode SET
OutPortB0=1; //write instruction to LCD
NOP;
OutPortB0=0;
pause(46);

// 8 Bit Mode
/* PORTB = 0b00101000; //5 2-lines, 5x8-dot-Matrix
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);
*/

// 4 Bit Mode High and Low nible transfer
PORTB = 0b00100000; //5 2-lines, 5x8-dot-Matrix High Nible
OutPortB0=1;
NOP;
OutPortB0=0;
PORTB = 0b10000000; //5 2-lines, 5x8-dot-Matrix Low Nible
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);

// 8 Bit Mode
/* PORTB = 0b00001000; //6 Display Off
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);
*/
// 4 Bit Mode High and Low nible transfer
PORTB = 0b00000000; //6 Display Off High Nible
OutPortB0=1;
NOP;
OutPortB0=0;
PORTB = 0b10000000; //6 Display Off Low Nible
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);
// 8 Bit Mode
/* PORTB = 0b00000001; //7 Display Clear
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);
*/
// 4 Bit Mode High and Low nible transfer
PORTB = 0b00000000; //7 Display Clear High Nible
OutPortB0=1;
NOP;
OutPortB0=0;
PORTB = 0b00010000; //7 Display Clear Low Nible
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);
// 8 Bit Mode
/* PORTB = 0b00000010; //8 Cursor nach rechts wandernd, no Display shift
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);
*/
// 4 Bit Mode High and Low nible transfer
PORTB = 0b00000000; //8 Cursor nach rechts wandernd, no Display shift
OutPortB0=1;
NOP;
OutPortB0=0;
PORTB = 0b00100000; //8 Cursor nach rechts wandernd, no Display shift
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);

// 8 Bit Mode
/* PORTB = 0b00001100; //9 Display On
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);
*/
// 4 Bit Mode High and Low nible transfer
PORTB = 0b00000000; //9 Display On
OutPortB0=1;
NOP;
OutPortB0=0;
PORTB = 0b11000000; //9 Display On
OutPortB0=1;
NOP;
OutPortB0=0;
pause(46);

} //end LCDInit



#1

13 Replies Related Threads

    rkarnik
    Super Member
    • Total Posts : 1355
    • Reward points : 0
    • Joined: 2005/01/02 11:06:42
    • Location: Newark, Delaware, USA
    • Status: offline
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 10:35:56 (permalink)
    0
    Before reading deeper, how do you know that your init routine doesn't work?
    You don't seem to be writing anything to the LCD after trying to initialise.
    So what are your symptoms?

    Rahul

    Recursion
    See Recursion
    #2
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 10:53:36 (permalink)
    0
    the symptoms are the Cousor is off an ist not blinking!!!!
    And at last if i turn on the cusor in step 9 it must blink.
    If i use my Assembler routine all is working fine but i want to start coding the pic´s in C.

    Great´s
    #3
    Aiden.Morrison
    Super Member
    • Total Posts : 721
    • Reward points : 0
    • Joined: 2005/02/25 11:18:31
    • Location: Canada
    • Status: offline
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 11:09:26 (permalink)
    0
    pause(255);
    OutPortB2=0; //set RS = low for instruction
    OutPortB3=0; //set RW = low to send data to display
    OutPortB0=1; //write instruction to LCD
    NOP;
    OutPortB0=0;

    PORTB= 0b00110000; //1 8 Bit
    OutPortB0=1; //write instruction to LCD
    NOP;
    OutPortB0=0;
    pause(50);


    When i'm initializing my 44780 based display I set E (OutPortB0) then put the data on the lines, then delay several nops (effectively reduce chip speed to 2mhz) then clear E (OutPortB0).

    It looks to me like you're doing it data->Eup->Edown which doesn't work for me.

    Also in your first step you're sending a clock pulse with no data, i do not see the purpose.


    try changing the code to

    pause(255);
    OutPortB2=0; //set RS = low for instruction
    OutPortB3=0; //set RW = low to send data to display
    OutPortB0=1; //write instruction to LCD
    PORTB= 0b00110000; //1 8 Bit
    NOP;
    NOP;
    NOP;
    NOP;
    NOP; //ensures code works up to mcu @ 48mhz assuming LCD @5v
    NOP; //this is in case the code needs to be used on an 18f4550 or other 48mhz pic.
    NOP; //48mhz/4=12mhz 12mhz/6nops=2mhz(max bus speed of 44780).
    OutPortB0=0;
    pause(50);
    < Message edited by Aiden.Morrison -- Mar. 20, 2005 1:17:18 PM >
    #4
    rkarnik
    Super Member
    • Total Posts : 1355
    • Reward points : 0
    • Joined: 2005/01/02 11:06:42
    • Location: Newark, Delaware, USA
    • Status: offline
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 11:19:48 (permalink)
    0
    If i use my Assembler routine all is working fine but i want to start coding the pic´s in C.


    Great! This means your hardware is ok. Have you tried sending any characters? Clear command first, etc.?

    Also you can take a look at how it is done hier.
    There are two separate examples with your PIC used so you might be able to compare and figure out what's going wrong for you.
    < Message edited by rkarnik -- Mar. 20, 2005 1:19:38 PM >

    Rahul

    Recursion
    See Recursion
    #5
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 11:43:14 (permalink)
    0
    Hello,

    is this right how i put the Data on the 4 Bit Mode BUS.


    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00100000; //5 2-lines, 5x8-dot-Matrix High Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b10000000; //5 2-lines, 5x8-dot-Matrix Low Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(46);


    I have changed it to following code but it doesnt work.


    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00100000; //5 2-lines, 5x8-dot-Matrix High Nible
    OutPortB0=1;
    NOP;
    NOP;
    NOP;
    NOP;
    NOP;
    NOP;
    NOP;
    OutPortB0=0;
    PORTB = 0b10000000; //5 2-lines, 5x8-dot-Matrix Low Nible
    OutPortB0=1;
    NOP;
    NOP;
    NOP;
    NOP;
    NOP; //ensures code works up to mcu @ 48mhz assuming
    NOP; //this is in case the code needs to be used on an
    NOP;
    OutPortB0=0;
    pause(50);


    The problem is if I use only my Assembler Init Routine all is working fine the Cursor is blinking.
    If i use the C init Routine the cursor is off.
    In both Routine i don´t put any charater on display.

    Great´s
    #6
    Aiden.Morrison
    Super Member
    • Total Posts : 721
    • Reward points : 0
    • Joined: 2005/02/25 11:18:31
    • Location: Canada
    • Status: offline
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 11:50:50 (permalink)
    0
    It is strange that your code works in assembly but not in C... have you tried simulating it in mplab to make sure it is behaving properly?


    Also be sure of the sequencing of the clock pulse... for my lcd i have to do
    clock high
    put data to lcd
    delay 500uSec
    pull clock low

    delay 1msec

    repeat
    < Message edited by Aiden.Morrison -- Mar. 20, 2005 1:52:22 PM >
    #7
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 11:57:16 (permalink)
    0
    very strange!!!!!
    this is my Assemby Code.




    list p=16f84
    ;**************************************************************
    ;* Pinbelegung
    ;* ----------------------------------
    ;* PORTA: 0 -
    ;* 1 -
    ;* 2 -
    ;* 3 -
    ;* 4 -
    ;* PORTB: 0 LCD Display E
    ;* 1
    ;* 2 LCD Display RS
    ;* 3 LCD Display R/W
    ;* 4-7 LCD Display D4 .. D7
    ;*
    ;**************************************************************
    ;
    ;sprut (zero) Bredendiek 05/2000 (mod. 15.01.2002)
    ;
    ; LCD-Display mit Matrixtastatur
    ;
    ; Taktquelle: 4 MHz
    ;
    ;**************************************************************
    ; Includedatei für den 16F84 einbinden

    #include <P16f84.INC>

    ; Configuration festlegen
    ; bis 4 MHz: Power on Timer, kein Watchdog, XT-Oscillator

    __CONFIG _PWRTE_ON & _WDT_OFF & _XT_OSC

    ;**************************************************************
    ; Variablen festlegen

    w_copy Equ 0x20
    s_copy Equ 0x21
    LcdDaten Equ 0x22
    LcdStatus Equ 0x23
    loops EQU 0x24
    loops2 EQU 0x25

    ; Constanten festlegen

    PORTC equ PORTB ; LCD-Control-Port
    PORTD equ PORTB ; LCD-Daten-Port
    LcdE equ 0 ; enable Lcd
    LcdRw equ 3 ; read Lcd
    LcdRs equ 2 ; Daten Lcd (nicht control)
    Ini_con Equ B'00000000' ; TMR0 -> Intetupt disable
    Ini_opt Equ B'00000010' ; pull-up

    ;********************************************************
    ; Das Programm beginnt mit der Initialisierung

    Init bsf STATUS, RP0 ; Bank 1
    movlw Ini_opt ; pull-up on
    movwf OPTION_REG
    movlw B'11111000' ; RA0 .. RA2 outputs, RA3, RA4 input
    movwf TRISA ;
    movlw B'00000000' ; PortB alle outputs
    movwf TRISB
    bcf STATUS, RP0 ; Bank 0
    clrf PORTA
    clrf PORTB

    movlw Ini_con ; Interupt disable
    movwf INTCON

    call InitLCD ; Display initialisieren

    ; am LCD "Hallo" ausgeben

    movlw 'H'
    movwf LcdDaten
    call OutLcdDaten
    movlw 'a'
    movwf LcdDaten
    call OutLcdDaten
    movlw 'l'
    movwf LcdDaten
    call OutLcdDaten
    movlw 'l'
    movwf LcdDaten
    call OutLcdDaten
    movlw 'o'
    movwf LcdDaten
    call OutLcdDaten

    sleep
    Main
    goto Main

    ;*****************************************************************
    ;Zeitverzögerung um loops * 1 ms
    ; 4MHz externer Takt bedeutet 1MHz interner Takt
    ; also dauert 1 ms genau 1000 Befehle
    ; 110 Schleifen a 9 Befehle sind 990 Befehle = 0.99 ms
    ; die restlichen 10 Befehle für Einsprung und Rücksprung

    WAIT
    top movlw .110 ; timing adjustment variable (1ms)
    movwf loops2
    top2 nop ; sit and wait
    nop
    nop
    nop
    nop
    nop
    decfsz loops2, F ; inner loops complete?
    goto top2 ; no, go again
    ;
    decfsz loops, F ; outer loops complete?
    goto top ; no, go again
    retlw 0 ; yes, return from subWAIT

    ;**********************************************************
    ; Initialisierung des LCD-Displays

    InitLCD
    movlw D'255' ; 250 ms Pause nach dem Einschalten
    movwf loops
    call WAIT

    movlw B'00110000' ; 1
    movwf PORTB
    bsf PORTB, LcdE
    nop
    bcf PORTB, LcdE

    movlw D'50' ; 50 ms Pause
    movwf loops
    call WAIT

    movlw B'00110000' ; 2
    call Control8Bit
    movlw B'00110000' ; 3
    call Control8Bit
    movlw B'00100000' ; 4
    call Control8Bit

    movlw B'00000001' ; löschen und cusor home
    call OutLcdControl
    movlw B'00101000' ; 5 function set, 4-bit 2-zeilig, 5x7
    call OutLcdControl
    movlw B'00001000' ; 6 display off
    call OutLcdControl
    movlw B'00000110' ; 7 entry mode, increment, disable display-shift
    call OutLcdControl
    movlw B'00000011' ; 8 cursor home, cursor home
    call OutLcdControl
    movlw B'00001111' ; 9 display on
    call OutLcdControl
    return

    ; ein Steuerbyte 8-bittig übertragen
    Control8Bit
    movwf PORTB
    bsf PORTB, LcdE
    nop
    bcf PORTB, LcdE
    movlw D'10'
    movwf loops
    call WAIT
    return

    ; darauf warten, daß das Display bereit zur Datenannahme ist
    LcdBusy
    bsf PORTA, 1 ; Test LED 1 on
    bsf STATUS, RP0 ; make Port B4..7 input
    movlw B'11110000'
    iorwf TRISB, f
    bcf STATUS, RP0
    BusyLoop
    bcf PORTC, LcdRs
    bsf PORTC, LcdRw ; Lesen
    bsf PORTC, LcdE
    nop
    movf PORTD, w
    movwf LcdStatus
    bcf PORTC, LcdE
    nop
    bsf PORTC, LcdE ; Enable
    nop
    bcf PORTC, LcdE
    btfsc LcdStatus, 7 ; teste bit 7
    goto BusyLoop
    bcf PORTC, LcdRw
    bsf STATUS, RP0 ; make Port B4..7 output
    movlw B'00001111'
    andwf TRISB, f
    bcf STATUS, RP0
    bcf PORTA, 1 ; Test LED 1 off
    return

    ; ein Byte mit Steuerdaten von LcdDaten zum Display übertragen
    OutLcdControl
    movwf LcdDaten
    call LcdBusy
    movf LcdDaten, w
    andlw H'F0'
    movwf PORTD ; Hi-teil Daten schreiben
    bsf PORTC, LcdE
    nop
    bcf PORTC, LcdE ; Disable LcdBus
    swapf LcdDaten, w
    andlw H'F0'
    movwf PORTD ; Lo-teil Daten schreiben
    bsf PORTC, LcdE
    nop
    bcf PORTC, LcdE ; Disable LcdBus
    return

    ; ein Datenbyte von LCDDaten zum Display übertragen
    OutLcdDaten
    bsf PORTA, 2 ; Test LED 2 on
    movwf LcdDaten
    call LcdBusy
    movf LcdDaten, w
    andlw H'F0'
    movwf PORTD ; Hi-teil Daten schreiben
    bsf PORTC, LcdRs ; Daten
    bsf PORTC, LcdE ; Enable LcdBus
    nop
    bcf PORTC, LcdE ; Disable LcdBus
    swapf LcdDaten, w
    andlw H'F0'
    movwf PORTD ; Lo-teil Daten schreiben
    bsf PORTC, LcdRs ; Daten
    bsf PORTC, LcdE
    nop
    bcf PORTC, LcdE ; Disable LcdBus
    bcf PORTC, LcdRs ;
    bcf PORTA, 2 ; Test LED 2 on
    return

    end

    #8
    Aiden.Morrison
    Super Member
    • Total Posts : 721
    • Reward points : 0
    • Joined: 2005/02/25 11:18:31
    • Location: Canada
    • Status: offline
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 12:12:13 (permalink)
    0
    movlw	B'00110000'	; 1
    movwf PORTB
    bsf PORTB, LcdE
    nop
    bcf PORTB, LcdE


    I will try my lcd again with this sequence, maybe i had another problem and blamed it on this at the time.

    EDIT: I tried it again with your sequence and it works. I am sorry for the previous comments to the contrary[:o]
    BUT, thank you for pointing it out to me... it made my code more efficient wink

    Does your C code proplerly write to the outputs during simulation?
    < Message edited by Aiden.Morrison -- Mar. 20, 2005 2:21:54 PM >
    #9
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 15:26:58 (permalink)
    0
    Hello,

    " Does your C code proplerly write to the outputs during simulation?"

    What do you mean exactly with your question ?
    #10
    Aiden.Morrison
    Super Member
    • Total Posts : 721
    • Reward points : 0
    • Joined: 2005/02/25 11:18:31
    • Location: Canada
    • Status: offline
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 19:44:25 (permalink)
    0
    I mean if you go to view --> special function registers

    while simulating your code step by step, can you see it writing the correct information to the ports?
    #11
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 21:38:36 (permalink)
    0
    Yes , i think so.

    if this is the rigth way to put the high an low nible to the portb 4-7.
    for examble to switch 2 lines an 5x8 dot matrix mode???

    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00100000; //5 2-lines, 5x8-dot-Matrix High Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b10000000; //5 2-lines, 5x8-dot-Matrix Low Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(46);
    #12
    Aiden.Morrison
    Super Member
    • Total Posts : 721
    • Reward points : 0
    • Joined: 2005/02/25 11:18:31
    • Location: Canada
    • Status: offline
    RE: Pic 16F84 + 4x20 line LCD 2005/03/20 22:42:42 (permalink)
    0
    Yes i believe that does set it to be 5x8 font, it's the same code i use for mine

    call	    LongInitDelay
    movlw B'00110011' ; nibble interface
    call INIT_WR_INS
    movlw B'00110010' ; 2 line display
    call INIT_WR_INS
    movlw B'00101000' ; 5X7 dot <---[b]i probably meant 5x8[/b]
    call INIT_WR_INS
    movlw B'00001100' ; display on/off
    call INIT_WR_INS
    movlw B'00000110' ; Entry mode
    call INIT_WR_INS
    movlw B'00000001' ; Clear ram
    call INIT_WR_INS
    movlw B'00000000' ; point to address 00H in LCD
    call INIT_WR_INS


    And just in case you're curious what write init ins is
    ;****************************************
    ; Write command to LCD during [b]initialization[/b]
    ; Input : W
    ; output : -
    ;****************************************
    INIT_WR_INS
    bcf RS ;clear RS
    bsf E ;pull enable high
    movwf LCDbuf ;set appropriate bits
    btfsc LCDbuf,7
    bsf LCDPORT,7
    btfss LCDbuf,7
    bcf LCDPORT,7
    btfsc LCDbuf,6
    bsf LCDPORT,6
    btfss LCDbuf,6
    bcf LCDPORT,6

    btfsc LCDbuf,5
    bsf LCDPORT,5
    btfss LCDbuf,5
    bcf LCDPORT,5
    btfsc LCDbuf,4
    bsf LCDPORT,4
    btfss LCDbuf,4
    bcf LCDPORT,4
    bcf E ;send first nibble
    call lcdwait ;delay
    swapf LCDbuf,1 ;invert the data byte to send low nibble
    bsf E ;pull enable high
    btfsc LCDbuf,7
    bsf LCDPORT,7
    btfss LCDbuf,7
    bcf LCDPORT,7
    btfsc LCDbuf,6
    bsf LCDPORT,6
    btfss LCDbuf,6
    bcf LCDPORT,6
    btfsc LCDbuf,5
    bsf LCDPORT,5
    btfss LCDbuf,5
    bcf LCDPORT,5
    btfsc LCDbuf,4
    bsf LCDPORT,4
    btfss LCDbuf,4
    bcf LCDPORT,4
    bcf E ;send second nibble
    call lcdwait ;delay
    bsf E

    return


    the reason i use so many btfsc and btfss is so i only change the state of pins that are used for the lcd, so i can have other devices coexist on the 4 unused pins of the port.
    #13
    Guest
    Super Member
    • Total Posts : 80499
    • Reward points : 0
    • Joined: 2003/01/01 00:00:00
    • Location: 0
    • Status: online
    RE: Pic 16F84 + 4x20 line LCD 2005/03/21 12:21:58 (permalink)
    0
    Hello thanks to all my INIT Routine in C works it was a Bug in the Bit value
    here the right code.

    GREAT DEBUGGER :-)



    void LCDInit(void)
    {
    pause(255);
    OutPortB2=0; //set RS = low for instruction
    OutPortB3=0; //set RW = low to send data to display
    PORTB= 0b00110000; //1 8 Bit
    OutPortB0=1; //write instruction to LCD
    NOP;
    OutPortB0=0;
    pause(50);

    PORTB= 0b00110000; //2 8 Bit
    OutPortB0=1; //write instruction to LCD
    NOP;
    OutPortB0=0;
    pause(50);

    PORTB= 0b00110000; //3 8 Bit
    OutPortB0=1; //write instruction to LCD
    NOP;
    OutPortB0=0;
    pause(50);

    PORTB= 0b00100000; //4 4 Bit Mode SET
    OutPortB0=1; //write instruction to LCD
    NOP;
    OutPortB0=0;
    pause(50);

    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00000000; //clear
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b00010000; //clear
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(50);

    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00100000; //5 2-lines, 5x8-dot-Matrix High Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b10000000; //5 2-lines, 5x8-dot-Matrix Low Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(50);


    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00000000; //6 Display Off High Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b10000000; //6 Display Off Low Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(50);

    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00000000; //7 Entry mode High Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b01100000; //7 Entry mode Low Nible
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(50);

    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00000000; //8 Cursor home
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b00110000; //8 Cursor home
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(50);


    // 4 Bit Mode High and Low nible transfer
    PORTB = 0b00000000; //9 Display On
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    PORTB = 0b11110000; //9 Display On
    OutPortB0=1;
    NOP;
    OutPortB0=0;
    pause(50);

    } //end LCDInit

    #14
    Jump to:
    © 2017 APG vNext Commercial Version 4.5