| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Donlaser 
 
 
 Joined: 17 Sep 2005
 Posts: 12
 Location: Trenque Lauquen, Argentina
 
 
			      
 
 | 
			
				| 2-wire LCD driver, no need for xtal osc |  
				|  Posted: Sat Sep 17, 2005 8:52 am |   |  
				| 
 |  
				| I adapt CCS driver for use the 2wire serial lcd interface. 
 I found this interface very useful for lcd when a 1 wire serial lcd is not practical due use of INTRC osc configuration. This interface has no timings problem when used with internal osc!.
 
 Just define in the main c module the 2 pins LCDCLK, LCDDAT..
 
 I test this code in 16f84, 16f877, 16f628 with rc / intrc at 4mhz.
 For 18fx52 20-40mhz operation, delays in lcd_es() is needed.
 
 Original idea from Myke Predko.
 For the schematics please see http://www.rentron.com/Myke1.htm .
 
 Hernan Guerrero
 Argentina
 
  	  | Code: |  	  | ////                             LCDHG.C
 ////                 Driver for common LCD modules
 ////
 ////  lcd_init()   Must be called before any other function.                                                                                           ////
 ////  lcd_putc(c)  Will display c on the next position of the LCD.
 ////                     The following have special meaning:
 ////                      \f  Clear display
 ////                      \n  Go to start of second line
 ////                      \b  Move back one position
 ////
 ////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)
 ////
 
 #ifndef LCDCLK
 #define  LCDCLK          PIN_A2
 #endif
 
 #ifndef LCDDAT
 #define  LCDDAT          PIN_A3
 #endif
 
 #define  DATA1           output_high(LCDDAT)
 #define  DATA0           output_low(LCDDAT)
 
 void lcd_Es()
 {
 output_high(LCDDAT);
 //delay_us(200);                     //only in high mhz
 output_low(LCDDAT);
 }
 
 void lcd_Clk()
 {
 output_high(LCDCLK);
 output_low(LCDCLK);
 
 }
 
 
 void lcd_Send_Nibble( char nibble, int1 rs)
 {
 int8 i;
 
 DATA0;                                    // clear output
 for (i=0; i<6; i++) lcd_Clk();
 
 DATA1;                          //  Output the "AND" Value
 lcd_Clk();
 
 IF (rs==1)    DATA1;            //  Output the RS Bit Value
 ELSE          DATA0;
 lcd_Clk();
 
 for (i = 0; i<4; i++)           // Output the Nybble
 {
 if (nibble & 0x08)  DATA1;   // Output the High Order Bit
 else                DATA0;
 lcd_Clk();                   //  Strobe the Clock
 nibble<<=1;                  // Shift up Nybble for Next Byte
 }
 lcd_Es();                       // Toggle the "E" Clock Bit
 }
 
 
 void lcd_send_byte( int n , int1 rs)
 {
 lcd_send_nibble(n >> 4 , rs);
 lcd_send_nibble(n & 0xf, rs);
 }
 
 
 void lcd_init( void)
 {
 lcd_send_nibble(0x03,0);
 delay_ms(5);
 lcd_es();
 delay_us(160);
 lcd_es();
 delay_us(160);
 lcd_send_nibble(0x02,0);
 delay_us(160);
 lcd_send_byte(0x28,0);
 lcd_send_byte(0x08,0);
 lcd_send_byte(0x01,0);
 delay_ms(5);
 lcd_send_byte(0x06,0);
 lcd_send_byte(0x0C,0);
 }
 
 
 void lcd_gotoxy( int x, int y)
 {
 BYTE address;
 if    (y!=1) address=0x40;
 else         address=0;
 address+=x-1;
 lcd_send_byte(0x80|address,0);
 }
 
 
 void lcd_putc( char c)
 {
 switch (c)
 {
 case '\f'   : lcd_send_byte(1,0); delay_ms(5);                                           break;
 case '\n'   : lcd_gotoxy(1,2);        break;
 case '\b'   : lcd_send_byte(0x10,0);  break;
 default     : lcd_send_byte(c,1);     break;
 }
 }
 | 
 
 Last edited by Donlaser on Fri Dec 16, 2005 6:03 am; edited 5 times in total
 |  |  
		|  |  
		| [mAnNaRo] 
 
 
 Joined: 02 Dec 2005
 Posts: 28
 Location: Italy, Milan
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Fri Dec 02, 2005 8:37 am |   |  
				| 
 |  
				| There is a strange error... strange because you say to have tested this code. In the function lcd_Send_Nibble you send only 3 bit of nibble and not 4.
 
 >for (i = 1; i<4; i++) // Output the Nybble
 >{
 >   ...
 >}
 cycles three times...
 
 instead of:
 for (i = 1; i<=4; i++) // Output the Nybble
 {
 ...
 }
 
 It's right the one which I am saying?
 
 Tnx
 Alex
 |  |  
		|  |  
		| [mAnNaRo] 
 
 
 Joined: 02 Dec 2005
 Posts: 28
 Location: Italy, Milan
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Fri Dec 02, 2005 4:11 pm |   |  
				| 
 |  
				| I've tried this code now with the modified 'for' and it work fine but another bug is present in the command char \f (Clear Display). The delay of 1ms isn't enough to complete clear sequence, 5ms is ok. 
 Bye
 Alex
 |  |  
		|  |  
		| Donlaser 
 
 
 Joined: 17 Sep 2005
 Posts: 12
 Location: Trenque Lauquen, Argentina
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Dec 03, 2005 7:05 am |   |  
				| 
 |  
				| Alex, 
 I feel it, it is truth, there is a typing error in the for loop, I already corrected it.
 
 The 1ms works ok in Powertip 1602 LCDs, and avoided the blinking that happens when was 5ms, this depend of LCD  that being this used, the correct thing would have to be 5ms, it would work in all the cases.
 
 
 
 Tnx, Greetings from Argentina
 Hernan Guerrero
 |  |  
		|  |  
		| [mAnNaRo] 
 
 
 Joined: 02 Dec 2005
 Posts: 28
 Location: Italy, Milan
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Sat Dec 03, 2005 1:53 pm |   |  
				| 
 |  
				| Hi Hernan, I'm using an Apex P162001 and a write after only 1ms take random char
 
  . Thanx for your code it will be very useful for my project 
   
 In my version (two small mod at your code) I have used an 8-bit shift register (74HC164) instead of d-latch (74HC174) this give me two more pin available for drive something.
 
 Tnx from Italy
 Alessandro Blason
 |  |  
		|  |  
		| jahan 
 
 
 Joined: 04 Apr 2005
 Posts: 63
 
 
 
			      
 
 | 
			
				| trouble |  
				|  Posted: Wed Jan 04, 2006 12:17 am |   |  
				| 
 |  
				| Is there any trick to this program? I cannot see anything on my LCD.  I've created the schematics from Myke's web page and using your code to make a simple "HELLO".
 The LCD is all black.
 I'm using 16F77, 4Mhz.
 would you please help?
 Thankx
 here is my main code:
 
  	  | Code: |  	  | #include <16F77.h>
 #device adc=8
 #fuses NOWDT,XT, NOPUT, NOPROTECT, NOBROWNOUT
 #use delay(clock=4000000)
 #include "LCD174Driver.c"
 void main() {
 port_b_pullups(TRUE);
 setup_adc_ports(NO_ANALOGS);
 setup_adc(ADC_OFF);
 setup_psp(PSP_DISABLED);
 setup_spi(FALSE);
 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
 setup_timer_1(T1_DISABLED);
 setup_timer_2(T2_DISABLED,0,1);
 lcd_init();
 delay_ms(1000);
 lcd_putc('\f');
 while(true) {
 lcd_putc('\f');
 delay_ms(10);
 lcd_putc('\n');
 delay_ms(10);
 lcd_putc('h');
 output_high(PIN_B0);
 delay_ms(1000);
 output_low(PIN_B0);
 }
 }
 
 | 
 and here is your driver code:
 
  	  | Code: |  	  | //// LCDHG.C
 //// Driver for common LCD modules
 ////
 //// lcd_init() Must be called before any other function. ////
 //// lcd_putc(c) Will display c on the next position of the LCD.
 //// The following have special meaning:
 //// \f Clear display
 //// \n Go to start of second line
 //// \b Move back one position
 ////
 //// lcd_gotoxy(x,y) Set write position on LCD (upper left is 1,1)
 ////
 
 #ifndef LCDCLK
 #define LCDCLK PIN_B2
 #endif
 
 #ifndef LCDDAT
 #define LCDDAT PIN_B1
 #endif
 
 #define DATA1 output_high(LCDDAT)
 #define DATA0 output_low(LCDDAT)
 
 void lcd_Es() {
 output_high(LCDDAT);
 //delay_us(200); //only in high mhz
 output_low(LCDDAT);
 }
 
 void lcd_Clk() {
 output_high(LCDCLK);
 output_low(LCDCLK);
 }
 
 
 void lcd_Send_Nibble( char nibble, int1 rs) {
 int8 i;
 
 DATA0; // clear output
 for (i=0; i<6; i++) lcd_Clk();
 
 DATA1; // Output the "AND" Value
 lcd_Clk();
 
 IF (rs==1) {
 DATA1; // Output the RS Bit Value
 } ELSE {
 DATA0;
 }
 lcd_Clk();
 for (i = 0; i<5; i++) { // Output the Nybble
 if (nibble & 0x08) {
 DATA1; // Output the High Order Bit
 }
 else {
 DATA0;
 }
 lcd_Clk(); // Strobe the Clock
 nibble<<=1; // Shift up Nybble for Next Byte
 }
 lcd_Es(); // Toggle the "E" Clock Bit
 }
 
 
 void lcd_send_byte( int n , int1 rs) {
 lcd_send_nibble(n >> 4 , rs);
 lcd_send_nibble(n & 0xf, rs);
 }
 
 
 void lcd_init( void) {
 lcd_send_nibble(0x03,0);
 delay_ms(5);
 lcd_es();
 delay_us(160);
 lcd_es();
 delay_us(160);
 lcd_send_nibble(0x02,0);
 delay_us(160);
 lcd_send_byte(0x28,0);
 lcd_send_byte(0x08,0);
 lcd_send_byte(0x01,0);
 delay_ms(5);
 lcd_send_byte(0x06,0);
 lcd_send_byte(0x0C,0);
 }
 
 
 void lcd_gotoxy( int x, int y) {
 BYTE address;
 if (y!=1) {
 address=0x40;
 } else {
 address=0;
 }
 address+=x-1;
 lcd_send_byte(0x80|address,0);
 }
 
 
 void lcd_putc( char c) {
 switch (c) {
 case '\f' : lcd_send_byte(1,0); delay_ms(5); break;
 case '\n' : lcd_gotoxy(1,2); break;
 case '\b' : lcd_send_byte(0x10,0); break;
 default : lcd_send_byte(c,1); break;
 }
 }
 
 | 
 the LED on B0 blinks OK, so I know the PIC part is working.
 Any help is greatly appriciated.
 Thankx
 |  |  
		|  |  
		| [mAnNaRo] 
 
 
 Joined: 02 Dec 2005
 Posts: 28
 Location: Italy, Milan
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Wed Jan 04, 2006 7:31 am |   |  
				| 
 |  
				| The nibble is four bit long, check your lcd_Send_Nibble function... 
 this statement is wrong because it cycles five times...
 
  	  | Code: |  	  | for (i = 0; i<5; i++) { // Output the Nybble
 
 | 
 correct version:
 
  	  | Code: |  	  | for (i = 0; i<4; i++) { // Output the Nybble
 
 | 
 
 Bye
 Alex
 |  |  
		|  |  
		| tvnorm 
 
 
 Joined: 29 Aug 2006
 Posts: 6
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Aug 29, 2006 8:17 pm |   |  
				| 
 |  
				| mAnNaRo, I have lots of 74595 chips, which are also 8 bit shift register. I was wondering what modifications you made to Donlasers code, and if you would be willing to share it, if it would work with 74595, and the connection details.
 Thanks,
 tvnorm
 |  |  
		|  |  
		| sidhuhere 
 
 
 Joined: 23 May 2010
 Posts: 2
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Mon May 24, 2010 6:00 am |   |  
				| 
 |  
				| Whether this needs a shift register for operation as mentioned in Mike website stated above?? |  |  
		|  |  
		| sidhuhere 
 
 
 Joined: 23 May 2010
 Posts: 2
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue May 25, 2010 12:19 am |   |  
				| 
 |  
				| Any1 online?? i have a doubt in connecting the LCD with the microcontroller. 
 What are the pins to be connected in the respective LCD pins..
 
 Pls reply.. Its urgent i need it for my final year project to be submitted in 15 days..
 |  |  
		|  |  
		| dantefo 
 
 
 Joined: 09 Jan 2011
 Posts: 1
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Sun Jan 09, 2011 2:46 pm |   |  
				| 
 |  
				|  	  | [mAnNaRo] wrote: |  	  | Hi Hernan, I'm using an Apex P162001 and a write after only 1ms take random char
 
  . Thanx for your code it will be very useful for my project 
   
 In my version (two small mod at your code) I have used an 8-bit shift register (74HC164) instead of d-latch (74HC174) this give me two more pin available for drive something.
 
 Tnx from Italy
 Alessandro Blason
 | 
 
 Hi, do you  have the code for using 2wire with the 74164 ? I'm having trouble to make it work. Thanks
 |  |  
		|  |  
		| subi 
 
 
 Joined: 29 Aug 2010
 Posts: 24
 
 
 
			    
 
 | 
			
				| dont't work |  
				|  Posted: Wed Jun 15, 2011 11:28 am |   |  
				| 
 |  
				| Hello Everybody, 
 I have built the circuit with 74LS174 and LCD.
 I would like to say that the code above for 2 wire lcd  does not work. I don't understand why.
 So I would like to ask who has a good code please send it me or load up.
 Thank you for your helping.
 Sorry for my English.
 Subi
 
  |  |  
		|  |  
		| mohamed2040 
 
 
 Joined: 30 Mar 2013
 Posts: 17
 
 
 
			      
 
 | 
			
				|  |  
				|  Posted: Thu May 30, 2013 1:19 pm |   |  
				| 
 |  
				| please !!!! can you help us to send us the correct driver ! !!!!
 urgent! tks
 |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |