• 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.

Library 3-wire serial lcd using 74hc595 for CodevisionAVR

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#2

wkrug

Active Member
#3
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.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#4
I just wrote one for the pic12f675... Took about 10 mins...
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:

Latest threads

EE World Online Articles

Loading

 
Top