CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

4094 Shift Register 3 wire LCD - Driver By (Fattah-Tafreshi)

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
fattahtafreshi



Joined: 18 Apr 2011
Posts: 14

View user's profile Send private message Yahoo Messenger

4094 Shift Register 3 wire LCD - Driver By (Fattah-Tafreshi)
PostPosted: Mon Apr 18, 2011 8:34 am     Reply with quote

Code:

//main.c
//Fattah-Tafreshi
//fattah.roland@gmail.com
//2011
//4094 LCD Serial

#include "main.h"

//4094 PINs
#define data PIN_B0
#define clock PIN_B1
#define Strobe PIN_B2

#include "f_lcd.c"

void main()
{
int i;
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   lcd_init();
   
   for(i=0;i<=15;i++)
      {
         lcd_gotoxy(i,1);
         lcd_putc('-');
         lcd_gotoxy(16-i,2);
         lcd_putc('-');
         delay_ms(100);
      }
   
   
   printf(LCD_PUTC,"\fwww.ir-micro.com\n");
   printf(LCD_PUTC,"4094  Serial LCD");   
   delay_ms(2000);
   printf(LCD_PUTC,"\fFattah-Tafreshi\n");
   printf(LCD_PUTC,"VAF-O-T   2011");   

}



Code:

//main.h
#include <16F84A.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading

#use delay(clock=16000000)


Code:

//outshift.c
//Fattah-Tafreshi
//fattah.roland@gmail.com
//2011
//4094(Shift Register) 3wire Serial To Parallel

byte d0,d1,d2,d3,d4,d5,d6,d7;

#IFNDEF  data
#define data      PIN_A0
#define clock     PIN_A1
#define strobe    PIN_A2
#ENDIF

//4094   Shift Register
void set_shift(int8 value)
{
int8 location=0,n=0;
location=128;
for(n=1;n<=8;n++){
    if ((value & location)>0) output_bit(data,1); else output_bit(data, 0);
      output_bit(clock,1);
      location=location / 2;
      output_bit(clock,0);
}
 output_bit(strobe,1);
 output_bit(strobe,0);
}



void f_output(byte value)
{
   set_shift(value);
}

void fatport()
{
int value;
value=0;
if (d0==1) value=value+1;
if (d1==1) value=value+2;
if (d2==1) value=value+4;
if (d3==1) value=value+8;
if (d4==1) value=value+16;
if (d5==1) value=value+32;
if (d6==1) value=value+64;
if (d7==1) value=value+128;
f_output(value);
}


void dg0(int value)
{
d0=value;
fatport();
}

void dg1(int value)
{
d1=value;
fatport();
}

void dg2(int value)
{
d2=value;
fatport();
}

void dg3(int value)
{
d3=value;
fatport();
}

void dg4(int value)
{
d4=value;
fatport();
}

void dg5(int value)
{
d5=value;
fatport();
}

void dg6(int value)
{
d6=value;
fatport();
}

void dg7(int value)
{
d7=value;
fatport();
}

void f_output_bit(byte pin,value)
{
   switch(pin)
   {
      case 1:dg0(value);
            break;
      case 2:dg1(value);
            break;
      case 3:dg2(value);
            break;
      case 4:dg3(value);
            break;
      case 5:dg4(value);
            break;
      case 6:dg5(value);
            break;
      case 7:dg6(value);
            break;
      case 8:dg7(value);
            break;           
   }
}


void f_output_high(byte pin)
{
   switch(pin)
   {
      case 1:dg0(1);
            break;
      case 2:dg1(1);
            break;
      case 3:dg2(1);
            break;
      case 4:dg3(1);
            break;
      case 5:dg4(1);
            break;
      case 6:dg5(1);
            break;
      case 7:dg6(1);
            break;
      case 8:dg7(1);
            break;           
   }
}


void f_output_low(byte pin)
{
   switch(pin)
   {
      case 1:dg0(0);
            break;
      case 2:dg1(0);
            break;
      case 3:dg2(0);
            break;
      case 4:dg3(0);
            break;
      case 5:dg4(0);
            break;
      case 6:dg5(0);
            break;
      case 7:dg6(0);
            break;
      case 8:dg7(0);
            break;           
   }
}


Code:

//flcd.c
//Fattah-Tafreshi
//fattah.roland@gmail.com
//2011
//Edit flex_lcd For 4094(Shift Register) Serial LCD


#include "outshift.c"

// flex_lcd.c

// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver.  Change these
// pins to fit your own board.

#define LCD_DB4   5
#define LCD_DB5   6
#define LCD_DB6   7
#define LCD_DB7   8

#define LCD_E     4
#define LCD_RS    3
//#define LCD_RW    -->>   GND

 

//========================================

#define lcd_type 2        // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line

int8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
 0xc,                    // Display on
 1,                      // Clear display
 6                       // Increment cursor
 };
                             

//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note:  !! converts an integer expression
// to a boolean (1 or 0).

 f_output_bit(LCD_DB4, !!(nibble & 1));
 f_output_bit(LCD_DB5, !!(nibble & 2)); 
 f_output_bit(LCD_DB6, !!(nibble & 4));   
 f_output_bit(LCD_DB7, !!(nibble & 8));   

 delay_cycles(1);
 f_output_high(LCD_E);
 delay_us(2);
 f_output_low(LCD_E);
}


//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
f_output_low(LCD_RS);

delay_us(60); 


if(address)
   f_output_high(LCD_RS);
else
   f_output_low(LCD_RS);
     
 delay_cycles(1);

f_output_low(LCD_E);


lcd_send_nibble(n >> 4);

lcd_send_nibble(n & 0xf);
}

//----------------------------
void lcd_init(void)
{
int8 i;

f_output_low(LCD_RS);


f_output_low(LCD_E);

delay_ms(15);

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    delay_ms(5);
   }

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING[i]);
   }

}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;

if(y != 1)
   address = lcd_line_two;
else
   address=0;

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1,2);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}




Last edited by fattahtafreshi on Wed Apr 20, 2011 7:05 am; edited 2 times in total
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Apr 18, 2011 8:36 am     Reply with quote

So errrr, whats wrong with it ?
fattahtafreshi



Joined: 18 Apr 2011
Posts: 14

View user's profile Send private message Yahoo Messenger

4094 ShiftRegister 3 wire LCD Project Proteus
PostPosted: Mon Apr 18, 2011 8:41 am     Reply with quote

https://rapidshare.com/files/458006085/PIC-CCS-4094-Serial-LCD.zip
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Mon Apr 18, 2011 8:53 am     Reply with quote

You expect me to download that zip file? Why?
it would be nice if you actually asked a question and explained why you posted this.

If it is, as I expect a driver you have written which you wish to distribute then it should have been posted in the code section, not here.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 18, 2011 9:57 am     Reply with quote

What's 'wrong', is that I can buy a PIC cheaper than the 4094 !
Using the PIC, I can have a 'smart' LCD, offloading the main PIC all of the 'driver' functions.

Sign of the times.....
fattahtafreshi



Joined: 18 Apr 2011
Posts: 14

View user's profile Send private message Yahoo Messenger

New Version
PostPosted: Tue Aug 20, 2013 5:56 am     Reply with quote

Hi.
Please download new version.

http://fattahtafreshi.persiangig.com/other/PIC-CCS-4094-Serial-LCD.zip
fattahtafreshi



Joined: 18 Apr 2011
Posts: 14

View user's profile Send private message Yahoo Messenger

New Version
PostPosted: Tue Aug 20, 2013 6:02 am     Reply with quote

Code:

//main.c

//Fattah-Tafreshi
//fattah.roland@gmail.com
//2011-2013
//4094 LCD Serial

#include "main.h"

//4094 PINs
#define  SR4094_data    PIN_B0
#define  SR4094_clock   PIN_B1
#define  SR4094_Strobe  PIN_B2

#include "f_lcd.c"

void main()
{
int i;
int n=0;

   lcd_init();
   
   for(i=0;i<=15;i++)
      {
         lcd_gotoxy(i,1);
         lcd_putc('-');
         lcd_gotoxy(16-i,2);
         lcd_putc('-');
         delay_ms(100);
      }
   
   
   printf(lcd_putc,"\fwww.ccsinfo.com\n");
   printf(lcd_putc,"4094  Serial LCD");   
   delay_ms(2000);
   printf(lcd_putc,"\fFattah-Tafreshi\n");
   printf(lcd_putc,"VAF-O-T   2013");
   delay_ms(2000);
   
   while(true)
   {
      lcd_gotoxy(1,1);
      printf(lcd_putc,"\f%u",n);
      n++;
      delay_ms(100);
   }
   

}


Code:

//main.h

#include <16F84A.h>

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading

#use delay(clock=16000000)


Code:

//f_lcd.c

//Fattah-Tafreshi
//fattah.roland@gmail.com
//2011-2013
//Edit flex_lcd For 4094(Shift Register) Serial LCD


#include "outshift.c"

// flex_lcd.c

// These pins are for the Microchip PicDem2-Plus board,
// which is what I used to test the driver.  Change these
// pins to fit your own board.

#define LCD_DB4   4
#define LCD_DB5   5
#define LCD_DB6   6
#define LCD_DB7   7

#define LCD_E     3
#define LCD_RS    2
//#define LCD_RW    -->>   GND

 

//========================================

#define lcd_type 2        // 0=5x7, 1=5x10, 2=2 lines
#define lcd_line_two 0x40 // LCD RAM address for the 2nd line

int8 const LCD_INIT_STRING[4] =
{
 0x20 | (lcd_type << 2), // Func set: 4-bit, 2 lines, 5x8 dots
 0xc,                    // Display on
 1,                      // Clear display
 6                       // Increment cursor
 };
                             

//-------------------------------------
void lcd_send_nibble(int8 nibble)
{
// Note:  !! converts an integer expression
// to a boolean (1 or 0).

 f_output_bit(LCD_DB4, !!(nibble & 1));
 f_output_bit(LCD_DB5, !!(nibble & 2)); 
 f_output_bit(LCD_DB6, !!(nibble & 4));   
 f_output_bit(LCD_DB7, !!(nibble & 8));   

 delay_cycles(1);
 f_output_high(LCD_E);
 delay_us(2);
 f_output_low(LCD_E);
}


//----------------------------------------
// Send a byte to the LCD.
void lcd_send_byte(int8 address, int8 n)
{
f_output_low(LCD_RS);

delay_us(60); 


if(address)
   f_output_high(LCD_RS);
else
   f_output_low(LCD_RS);
     
 delay_cycles(1);

f_output_low(LCD_E);


lcd_send_nibble(n >> 4);

lcd_send_nibble(n & 0xf);
}

//----------------------------
void lcd_init(void)
{
int8 i;

f_output_low(LCD_RS);


f_output_low(LCD_E);

delay_ms(15);

for(i=0 ;i < 3; i++)
   {
    lcd_send_nibble(0x03);
    delay_ms(5);
   }

lcd_send_nibble(0x02);

for(i=0; i < sizeof(LCD_INIT_STRING); i++)
   {
    lcd_send_byte(0, LCD_INIT_STRING[i]);
   }

}

//----------------------------

void lcd_gotoxy(int8 x, int8 y)
{
int8 address;

if(y != 1)
   address = lcd_line_two;
else
   address=0;

address += x-1;
lcd_send_byte(0, 0x80 | address);
}

//-----------------------------
void lcd_putc(char c)
{
 switch(c)
   {
    case '\f':
      lcd_send_byte(0,1);
      delay_ms(2);
      break;
   
    case '\n':
       lcd_gotoxy(1,2);
       break;
   
    case '\b':
       lcd_send_byte(0,0x10);
       break;
   
    default:
       lcd_send_byte(1,c);
       break;
   }
}



Code:

//outshift.c

//Fattah-Tafreshi
//fattah.roland@gmail.com
//2011-2013
//4094(Shift Register) 3wire Serial To Parallel

#IFNDEF  SR4094_data
   #define  SR4094_data      PIN_A0
   #define  SR4094_clock     PIN_A1
   #define  SR4094_strobe    PIN_A2
#ENDIF

//4094   Shift Register

unsigned char tempdata=0;

void set_shift(unsigned char value)
{
   unsigned char mask=0x80;
   do{
      if(value & mask) output_bit(SR4094_data,1);else output_bit(SR4094_data,0);
      output_bit(SR4094_clock,1);
      output_bit(SR4094_clock,0);
      mask>>=1;
   }while(mask);
   
   output_bit(SR4094_strobe,1);
   output_bit(SR4094_strobe,0);
}


void f_output_bit(unsigned char pin,short value)
{
      if(value == 1)
         tempdata|=(1<<(pin % 8));
            else                         
         tempdata&=~(1<<(pin % 8));
     set_shift(tempdata);
}

void f_output_high(unsigned char pin)
{
   tempdata|=(1<<(pin % 8));
   set_shift(tempdata);
}

void f_output_low(unsigned char pin)
{
   tempdata&=~(1<<(pin % 8));
   set_shift(tempdata);
}
Code:
Nascimento



Joined: 30 Dec 2015
Posts: 3

View user's profile Send private message

PostPosted: Wed Dec 30, 2015 7:16 pm     Reply with quote

hi friend simulated in Proteus all right
more when I made the card did not work
Nascimento



Joined: 30 Dec 2015
Posts: 3

View user's profile Send private message

PostPosted: Wed Dec 30, 2015 7:17 pm     Reply with quote

you could send the layout of the 4094 card?
ps: google translator
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group