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 support@ccsinfo.com

Flexible LCD driver for 20x4 LCDs, 3 pin mode

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



Joined: 18 Jul 2010
Posts: 14
Location: Puebla, Mexico

View user's profile Send private message Visit poster's website

Flexible LCD driver for 20x4 LCDs, 3 pin mode
PostPosted: Sat Dec 29, 2012 12:06 pm     Reply with quote

Este driver es para usar con LCDs de 20x4, con sólo 3 pines.

esta librería la modifique a partir del "Flex_LCD420.c" mostrado aquí:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268

y de la libreria "flex_lcd_3pins.c" mostrada aquí:
http://www.todopic.com.ar/foros/index.php?topic=27011.0

para usar esta librería se usa un registro de corrimiento "74VHC164"
descargar ejemplo y simulación.

"Que la disfruten"
----------------------------------------------------------------------------------
This driver is for use with 20x4 LCDs, 3 pin mode.

I modify this library from "Flex_LCD420.c" shown here:
http://www.ccsinfo.com/forum/viewtopic.php?t=28268

and the library "flex_lcd_3pins.c" shown here:
http://www.todopic.com.ar/foros/index.php?topic=27011.0

to use this library using a shift register "74VHC164"
download example and simulation.

"Enjoy it"

example
Code:
/*  http://www.todopic.com.ar/foros/   */

//ejemplo modificado bye PicTrance (I.S.R.)
#include <16F88.h>

#FUSES INTRC_IO,NOWDT,PUT,MCLR,NOBROWNOUT,NOLVP,NOPROTECT,NODEBUG,CCPB0,NOFCMEN,NOIESO
#use delay(Internal=8M)
//#use rs232(baud=9600, xmit=PIN_b6, rcv=PIN_b7)

//------------ Pines del LCD ---------------------//
#define LCD_E     PIN_A0
#define LCD_CK    PIN_A1   
#define LCD_DAT   PIN_A2
//--------------------------------------------------//

#include "flex_lcd4x20_3pines.c"            // Cargamos libreria del lcd

void main(){
   delay_ms(100);
   
   output_a(0);
   output_b(0);
   lcd_init();              // inicializamos el LCD
   lcd_setcursor_vb(1,1);  //cursor visible,papadeo
   while(1){
      printf(lcd_putc,"\f-LCD 3 pin Mode-\n* !.|.|..|.|.! *");
      printf(lcd_putc,"\n* PicTrance  *\n *  I.S.R.  *");
      delay_ms(1000);
      printf(lcd_putc,"\f* PicTrance  *\n *  I.S.R.  *");
      printf(lcd_putc,"\n-LCD 3 pin Mode-\n* !.|.|..|.|.! *");
      delay_ms(1000);
   }//end while           
}//end main


flex_lcd4x20_3pines.c
Code:
////////////////////////////////////////////////////////////////////////////////
///                        Flex_LCD4x20_3pines.c                             ///
///            Driver for temperature and humidity sensor                    ///
///            Realizado por PicTrance  (I.S.R.)                             ///
///            junio del 2011, Puebla - México                               ///
///            Compiler: CCS                                                 ///
///                                                                          ///
///            Modificacion del del felx_lcd_3pins.c  y del Flex_LCD420.c    ///
///                                                                          ///
/// lcd_init()  - Iicializa el sensor sht21 -                                ///
///                                                                          ///
/// lcd_putc(c) - para mandar a escribir en el LCD                           ///
///                                                                          ///
/// lcd_gotoxy(x,y) - para mandar el cursor auna posicion especifia en el lcd///
///                                                                          ///
/// lcd_setcursor_vb(visible,blink) - para hacer el cursor visible           ///
///                          u ocultaro y también poder hacer que parpadee   ///
///                                                                          ///
/// Modificación del Modificacion del felx_lcd_3pins.c y del Flex_LCD420.c   ///
/// por PicTrance (I.S.R.)                                                   ///
/// Trabaja con 3 pines y 74VHC164                                           ///
/// 8-Bit Serial-In, Parallel-Out Shift Register                             ///
/// La LCD se usa en modo 4bits, Revisar diagrama de conexion Adjunto        ///
/// No esta habilitada la lectura del LCD                                    ///
/// RW debe ir a gnd                                                         ///
///                                                                          ///
/// Definir pines antes de llamar libreria                                   ///
/// #define LCD_E     PIN_A0                                                 ///
/// #define LCD_CK    PIN_A1                                                 ///
/// #define LCD_DAT   PIN_A2                                                 ///
////////////////////////////////////////////////////////////////////////////////

//Definir pines antes de llamar libreria//
//#define LCD_E     PIN_A0
//#define LCD_CK    PIN_A1   
//#define LCD_DAT   PIN_A2

// These are the line addresses for most 4x20 LCDs.
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x40
#define LCD_LINE_3_ADDRESS 0x14
#define LCD_LINE_4_ADDRESS 0x54

// These are the line addresses for LCD's which use
// the Hitachi HD66712U controller chip.
/*
#define LCD_LINE_1_ADDRESS 0x00
#define LCD_LINE_2_ADDRESS 0x20
#define LCD_LINE_3_ADDRESS 0x40
#define LCD_LINE_4_ADDRESS 0x60
*/

//========================================
int RS_bit;
int8 lcd_line; // para ir de linea en linea de las 4 del lcd
#define lcd_type 2   // 0=5x7, 1=5x10, 2=2 lines(or more)
 

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

//-----------------------------------------------
void lcd_send_nibble(int8 nibble, int rs_bit){
   int x;
   if(RS_bit==1)
      nibble=nibble|0x10;

   for(x=0;x<5;x++){
      output_bit(LCD_DAT,shift_right(&nibble,1,0));
      delay_cycles(1);
      output_low(LCD_CK);
      delay_us(1);
      output_high(LCD_CK);}

   output_high(LCD_E);
   delay_us(2);
   output_low(LCD_E);
}

//----------------------------------------
// Send a byte to the LCD.

void lcd_send_byte(int8 address, int8 n){
//output_low(LCD_RS);
   RS_bit=0;
   delay_us(100);


   if(address)
      //output_high(LCD_RS);
      RS_bit=1;
   else
      //output_low(LCD_RS);
      RS_bit=0;

   delay_cycles(1);


   output_low(LCD_E);

   lcd_send_nibble(n >> 4,RS_bit);
   lcd_send_nibble(n & 0xf,RS_bit);
}

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

   //output_low(LCD_RS);
   RS_bit=0;

   output_low(LCD_E);

   delay_ms(20);

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

   lcd_send_nibble(0x02,RS_bit);

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

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

   switch(y){
      case 1:
         address = LCD_LINE_1_ADDRESS;
         break;
      case 2:
         address = LCD_LINE_2_ADDRESS;
         break;
      case 3:
         address = LCD_LINE_3_ADDRESS;
         break;
      case 4:
         address = LCD_LINE_4_ADDRESS;
         break;
      default:
         address = LCD_LINE_1_ADDRESS;
         break;
      }

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

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

//------------------------------
void lcd_setcursor_vb(short visible, short blink){
   lcd_send_byte(0, 0xC|(visible<<1)|blink);
}


Link de descarga, con la simulación en proteus y el código de ejemplo
http://www.mediafire.com/download.php?heac5cvq4jb04e6

Saludos!!!!

Mi blog http://pictrance.blogspot.mx/
_________________
Si el proyecto tiene mal olor es de Química, Si echa humo negro es de Mecánica, Si es verde o se retuerce es de Bioingenieria Y si no funciona es de Electrónica.. :p ... no es mia la frase, pero me gusto.
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