1. 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.
    Dismiss Notice

Library 3-wire serial lcd using 74hc595 for CodevisionAVR

Discussion in 'AVR' started by Azadfalah, Feb 12, 2017.

  1. Azadfalah

    Azadfalah New Member

    Joined:
    Feb 12, 2017
    Messages:
    2
    Likes:
    0
    Hi everybody,

    I need Library 3-wire serial lcd using 74hc595 for CodevisionAvr

    [​IMG]

    Please guide me
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK
    • Like Like x 1
  3. wkrug

    wkrug Active Member

    Joined:
    May 30, 2010
    Messages:
    280
    Likes:
    29
    Location:
    Germany
    You can copy the lcd.h and the lcd.c library into Your project folder.
    Change the include in Your main routine.
    Then You should change the parallel output routine into a serial Output for the 74HC595 in the copied files.

    So You can use this library for the serial LCD.
     
    • Like Like x 1
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,245
    Likes:
    911
    Location:
    Rochdale UK

    I just wrote one for the pic12f675... Took about 10 mins...
    Code (c):

    #include<xc.h>

    #define _XTAL_FREQ 4000000
    #define SDATA GPIO2
    #define SCLK GPIO1
    #define SCS GPIO0

    #pragma config FOSC = INTRCIO
    #pragma config MCLRE = OFF
    #pragma config WDTE = OFF

    unsigned char dataout;

    void shiftout(unsigned char ch)
       {
       char x;
       unsigned char dummy = ch;
       for(x=0;x<8;x++)
           {
           SDATA = 0;
           if(dummy & 0x80) SDATA = 1;
           SCLK = 1;
           NOP();
           SCLK = 0;
           dummy<<=1;    
           }
       SCS = 1;
       NOP();
       SCS = 0;
       }

    void LCDtoggle(void)
       {
       dataout ^= 0x10;
       shiftout(dataout);
       dataout ^= 0x10;
       shiftout(dataout);
       }
     
    void LCDnibbles(unsigned char ch)
       {
       dataout &= 0xF0;
       dataout += (ch>>4) & 0xF;
       shiftout(dataout);
       LCDtoggle();
       dataout &= 0xF0;
       dataout += ch & 0xF;
       shiftout(dataout);
       LCDtoggle();
       }

    void LCDcmd(unsigned char cmd)
       {
       dataout = 0;
       LCDnibbles(cmd);
       __delay_us(100);
       }
     
    void LCDdata(unsigned char data)
       {
       dataout = 0x20;
       LCDnibbles(data);
       __delay_us(100);
       }
     
    void LCDinit(void)
       {
       TRISIO = 0;
       __delay_ms(15);
       dataout = 2;
       LCDtoggle();
       __delay_ms(5);
       LCDtoggle();
       __delay_ms(5);
       LCDtoggle();
       __delay_ms(5);
       LCDcmd(0x28);
       __delay_ms(5);
       LCDcmd(0x28);
       LCDcmd(0xC);
       LCDcmd(0x6);
       LCDcmd(0x1);
       }
     
    void LCDprint(const char* str)
       {
       while(*str != 0)
           LCDdata(*str++);
       }

    void LCDgoto(char x, char y)
       {
       char addr = 0x80;
       if(y==2) addr = 0xC0;
       if(y==3) addr = 0x94;
       if(y==4) addr = 0xD4;
       addr+=x;
       LCDcmd(addr);
       }
     
    void main(void)
       {
       ANSEL = 0;
       LCDinit();
       __delay_ms(10);
       LCDprint("Hello World");
       LCDgoto(0,2);
       LCDprint("Serial LCD driver");
       LCDgoto(4,3);
       LCDprint("For minimum");
       LCDgoto(6,4);
       LCDprint("pin counts");
       while(1);
       }
     
    upload_2017-2-15_21-48-36.png
     
    Last edited: Feb 15, 2017
    • Like Like x 2

Share This Page