| 
	
	|  |  |  
	
		| View previous topic :: View next topic |  
		| Author | Message |  
		| Hendrik 
 
 
 Joined: 19 Apr 2012
 Posts: 5
 
 
 
			    
 
 | 
			
				| Need help to change the code use for LCD into Oled |  
				|  Posted: Thu Apr 19, 2012 11:05 am |   |  
				| 
 |  
				| I have the sources to use LCD display now I use the Winstar WH1602 L1 lcd display and want to change this into the WEH001602B
 both are HD44780 compatible.
 
 Does anyone can help me out changing the source that will work on the Oled of Winstar?
 
 I use the PIC16F877A.
 
 Hereby the code
 
 
  	  | Code: |  	  | ////////////////////////////////////////////////////////////////////////////
 ////                             LCDD.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)     ////
 ////                                                                    ////
 ////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////
 ////                                                                    ////
 ////////////////////////////////////////////////////////////////////////////
 
 #define lcd_type 2           // 0=5x7, 1=5x10, 2=2 lines
 
 #ifdef  LCD_16x4_lines
 #define lcd_line_1 0x00    // LCD RAM address for the first line  (16x4)
 #define lcd_line_2 0x40    // LCD RAM address for the second line (16x4)
 #define lcd_line_3 0x10    // LCD RAM address for the third line  (16x4)
 #define lcd_line_4 0x50    // LCD RAM address for the fourth line (16x4)
 #else //LCD_20x4_lines
 #define lcd_line_1 0x00    // LCD RAM address for the first line  (20x4)
 #define lcd_line_2 0x40    // LCD RAM address for the second line (20x4)
 #define lcd_line_3 0x14    // LCD RAM address for the third line  (20x4)
 #define lcd_line_4 0x54    // LCD RAM address for the fourth line (20x4)
 #endif
 // Comptible with 16,20,40x2 (default) but not for 40x4
 // *x1 or 8x2 LCD data types are NOT recommanded.
 
 
 byte CONST LCD_INIT_STRING[4] = {0x20 | (lcd_type << 2), 0xc, 1, 6};
 // These bytes need to be sent to the LCD
 // to start it up.
 #list
 byte lcd_read_byte() {
 byte low,high;
 
 #ifdef LCD_HIGH
 tris_lcd_port |= 0xf0;                 // Input High Pins
 #else
 tris_lcd_port |= 0X0f;                 // Input Low Pins
 #endif
 lcd_rw = 1;
 delay_cycles(1);
 lcd_enable = 1;
 delay_us(1);
 high = lcd_port;
 lcd_enable = 0;
 delay_cycles(2);
 lcd_enable = 1;
 delay_us(1);
 low = lcd_port;
 lcd_enable = 0;
 
 #ifdef LCD_HIGH
 tris_lcd_port &= 0x0f;                 // Output High Pins
 #ASM  MOVLW 0xF0
 ANDWF HIGH,F
 SWAPF LOW,W
 ANDLW 0x0F
 IORWF HIGH,F
 #ENDASM
 return(high);
 #else
 tris_lcd_port &= 0Xf0;                 // Output Low Pins
 #ASM
 MOVLW 0x0F
 ANDWF LOW,F
 SWAPF HIGH,W
 ANDLW 0xF0
 IORWF LOW,F
 #ENDASM
 return(low);
 #endif
 }
 
 
 void lcd_send_nibble( byte n ) {
 
 #ifdef LCD_HIGH
 tris_lcd_port &= 0x0f;                 // lcd_port direction = Output
 lcd_port &= 0b00001111;
 #else
 tris_lcd_port &= 0Xf0;                 // lcd_port direction = Output
 lcd_port &= 0b11110000;
 #endif
 lcd_port |= n;
 delay_cycles(1);
 lcd_enable = 1;
 delay_us(2);
 lcd_enable = 0;
 }
 
 
 void lcd_send_byte( byte address, byte n ) {
 byte i=0;                                   // Init 500ms. Counter for LCD Time_Out (NOT Implemented here).
 
 trisb &= 0b11100111;                        // RW and RS pins are Outputs.
 lcd_rs = 0;
 while(bit_test(lcd_read_byte(),7));
 lcd_rs = address;
 delay_cycles(1);
 lcd_rw = 0;
 delay_cycles(1);
 lcd_enable = 0;
 #ifdef LCD_HIGH
 lcd_send_nibble(n & 0xf0);                // Send High nibble...
 lcd_send_nibble(n << 4);
 #else
 lcd_send_nibble(n >> 4);                  // Send High nibble...
 lcd_send_nibble(n & 0x0f);
 #endif
 }
 
 
 void lcd_init() {
 byte i;
 
 #ifdef LCD_HIGH
 tris_lcd_port &= 0x0f;                      // Output High Pins
 #else
 tris_lcd_port &= 0Xf0;                      // Output Low Pins
 #endif
 
 trisb &= 0b11100111;                        // RW and RS pins are Outputs.
 delay_ms(15);
 for(i=1;i<=3;++i) {
 lcd_send_nibble(3);
 delay_ms(5);
 }
 lcd_send_nibble(2);
 for(i=0;i<=3;++i)
 lcd_send_byte(0,LCD_INIT_STRING[i]);
 }
 
 
 void lcd_gotoxy( byte x, byte y) {
 byte address;
 
 if (y == 1 || !y)                            // If y=0 or 1 chooses the first line.
 address=lcd_line_1;
 
 if (y == 2)
 address=lcd_line_2;
 
 if (y == 3)
 address=lcd_line_3;
 
 if (y == 4)
 address=lcd_line_4;
 
 address+=x-1;
 lcd_send_byte(0,0x80|address);
 }
 
 #separate
 void lcd_putc( char c) {
 
 switch (c) {
 case '\f'   : lcd_send_byte(0,1);
 delay_ms(2);
 break;
 case '\n'   :
 case '\2'   : lcd_gotoxy(1,2);        break;
 case '\3'   : lcd_gotoxy(1,3);        break;
 case '\4'   : lcd_gotoxy(1,4);        break;
 
 case '\b'   : lcd_send_byte(0,0x10);  break;
 default     : lcd_send_byte(1,c);     break;
 }
 }
 
 char lcd_getc( byte x, byte y) {
 char value;
 
 lcd_gotoxy(x,y);
 lcd_rs=1;
 value = lcd_read_byte();
 lcd_rs=0;
 return(value);
 }
 #nolist
 
 
 | 
 |  |  
		|  |  
		| Gabriel 
 
 
 Joined: 03 Aug 2009
 Posts: 1074
 Location: Panama
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 19, 2012 2:25 pm |   |  
				| 
 |  
				|  	  | Quote: |  	  | both are HD44780 compatible | 
 
 Does that not imply they use the same driver?
 
 ... i might be wrong.
 
 G.
 _________________
 CCS PCM 5.078 & CCS PCH 5.093
 |  |  
		|  |  
		| Hendrik 
 
 
 Joined: 19 Apr 2012
 Posts: 5
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 19, 2012 2:33 pm |   |  
				| 
 |  
				| Yes, but when i connect the Oled display nothing happen. |  |  
		|  |  
		| ezflyr 
 
 
 Joined: 25 Oct 2010
 Posts: 1019
 Location: Tewksbury, MA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 19, 2012 2:48 pm |   |  
				| 
 |  
				| Hi, 
 Well, does your circuit and code work with a "normal" LCD display? Lots of people here have trouble with getting a normal LCD display working, so I'd try that first before attempting to use the OLED display.
 
 A couple of suggestions:
 
 1. Scrap the driver you are using, and switch to the Flex_LCD driver. This driver has very good support on the forum.
 2. Make sure that you disconnect pin #3 on the OLED when you substitute it for the "normal" LCD. It may not matter, but the datasheet for the OLED display says this pin is a 'NC' (no connect), but it's the Vee (contrast voltage) pin on the normal LCD.
 
 John
 |  |  
		|  |  
		| Hendrik 
 
 
 Joined: 19 Apr 2012
 Posts: 5
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 19, 2012 3:07 pm |   |  
				| 
 |  
				| Hi, 
 Yes everything work with the lcd display of winstar
 For several yards how.
 
 Because winstar has an Oled display i want to use this
 That's the reason why I want to change it
 |  |  
		|  |  
		| ezflyr 
 
 
 Joined: 25 Oct 2010
 Posts: 1019
 Location: Tewksbury, MA
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 19, 2012 3:11 pm |   |  
				| 
 |  
				| Hi, 
 OK, if the exact circuit, and the exact firmware work with a "normal" display then you should ask Winstar if the OLED is a direct swap for the normal LCD.
 
 What about the pin #3 issue I mentioned?? Did you disconnect it when you connect the OLED display?
 
 Thanks,
 
 John
 |  |  
		|  |  
		| Hendrik 
 
 
 Joined: 19 Apr 2012
 Posts: 5
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 19, 2012 3:13 pm |   |  
				| 
 |  
				| I have change the code see this link http://www.picaxe.com/docs/oled.pdf
 
 strange:
 
 only the upperline in the display works the lowerline
 stay black. everything on the upperline works ok
 
 see code
 
 
  	  | Code: |  	  | ////////////////////////////////////////////////////////////////////////////
 ////                             LCDD.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)     ////
 ////                                                                    ////
 ////  lcd_getc(x,y)   Returns character at position x,y on LCD          ////
 ////                                                                    ////
 ////////////////////////////////////////////////////////////////////////////
 
 #ifdef  LCD_16x4_lines
 #define lcd_line_1 0x00    // LCD RAM address for the first line  (16x4)
 #define lcd_line_2 0x40    // LCD RAM address for the second line (16x4)
 #define lcd_line_3 0x10    // LCD RAM address for the third line  (16x4)
 #define lcd_line_4 0x50    // LCD RAM address for the fourth line (16x4)
 #else //LCD_20x4_lines
 #define lcd_line_1 0x00    // LCD RAM address for the first line  (20x4)
 #define lcd_line_2 0x40    // LCD RAM address for the second line (20x4)
 #define lcd_line_3 0x14    // LCD RAM address for the third line  (20x4)
 #define lcd_line_4 0x54    // LCD RAM address for the fourth line (20x4)
 #endif
 // Comptible with 16,20,40x2 (default) but not for 40x4
 // *x1 or 8x2 LCD data types are NOT recommanded.
 
 
 byte CONST LCD_INIT_STRING[6] = {
 0x08, //display off
 0x06, //entry mode set//need to configure this cmd or char will move left not move right
 0x17, //Character mode and internel power on (have to turn on internel power to get the best brightness)
 0x01, //clear display
 0x02, //return home
 0x0c  //display on
 };
 // These bytes need to be sent to the LCD
 // to start it up.
 #list
 byte lcd_read_byte() {
 byte low,high;
 
 #ifdef LCD_HIGH
 tris_lcd_port |= 0xf0;                 // Input High Pins
 #else
 tris_lcd_port |= 0X0f;                 // Input Low Pins
 #endif
 lcd_rw = 1;
 delay_cycles(1);
 lcd_enable = 1;
 delay_us(1);
 high = lcd_port;
 lcd_enable = 0;
 delay_cycles(2);
 lcd_enable = 1;
 delay_us(1);
 low = lcd_port;
 lcd_enable = 0;
 
 #ifdef LCD_HIGH
 tris_lcd_port &= 0x0f;                 // Output High Pins
 #ASM  MOVLW 0xF0
 ANDWF HIGH,F
 SWAPF LOW,W
 ANDLW 0x0F
 IORWF HIGH,F
 #ENDASM
 return(high);
 #else
 tris_lcd_port &= 0Xf0;                 // Output Low Pins
 #ASM
 MOVLW 0x0F
 ANDWF LOW,F
 SWAPF HIGH,W
 ANDLW 0xF0
 IORWF LOW,F
 #ENDASM
 return(low);
 #endif
 }
 
 
 void lcd_send_nibble( byte n ) {
 
 #ifdef LCD_HIGH
 tris_lcd_port &= 0x0f;                 // lcd_port direction = Output
 lcd_port &= 0b00001111;
 #else
 tris_lcd_port &= 0Xf0;                 // lcd_port direction = Output
 lcd_port &= 0b11110000;
 #endif
 lcd_port |= n;
 delay_cycles(1);
 lcd_enable = 1;
 delay_us(2);
 lcd_enable = 0;
 }
 
 
 void lcd_send_byte( byte address, byte n ) {
 byte i=0;                                   // Init 500ms. Counter for LCD Time_Out (NOT Implemented here).
 
 trisb &= 0b11100111;                        // RW and RS pins are Outputs.
 lcd_rs = 0;
 while(bit_test(lcd_read_byte(),7));
 lcd_rs = address;
 delay_cycles(1);
 lcd_rw = 0;
 delay_cycles(1);
 lcd_enable = 0;
 #ifdef LCD_HIGH
 lcd_send_nibble(n & 0xf0);                // Send High nibble...
 lcd_send_nibble(n << 4);
 #else
 lcd_send_nibble(n >> 4);                  // Send High nibble...
 lcd_send_nibble(n & 0x0f);
 #endif
 }
 
 
 void lcd_init() {
 byte i;
 
 #ifdef LCD_HIGH
 tris_lcd_port &= 0x0f;                      // Output High Pins
 #else
 tris_lcd_port &= 0Xf0;                      // Output Low Pins
 #endif
 
 trisb &= 0b11100111;                        // RW and RS pins are Outputs.
 delay_ms(15);
 for(i=1;i<=3;++i) {
 lcd_send_nibble(3);
 delay_ms(5);
 }
 lcd_send_nibble(2);
 for(i=0;i<6;++i)
 lcd_send_byte(0,LCD_INIT_STRING[i]);
 }
 
 
 void lcd_gotoxy( byte x, byte y) {
 byte address;
 
 if (y == 1 || !y)                            // If y=0 or 1 chooses the first line.
 address=lcd_line_1;
 
 if (y == 2)
 address=lcd_line_2;
 
 if (y == 3)
 address=lcd_line_3;
 
 if (y == 4)
 address=lcd_line_4;
 
 address+=x-1;
 lcd_send_byte(0,0x80|address);
 }
 
 #separate
 void lcd_putc( char c) {
 
 switch (c) {
 case '\f'   : lcd_send_byte(0,1);
 delay_ms(2);
 break;
 case '\n'   :
 case '\2'   : lcd_gotoxy(1,2);        break;
 case '\3'   : lcd_gotoxy(1,3);        break;
 case '\4'   : lcd_gotoxy(1,4);        break;
 
 case '\b'   : lcd_send_byte(0,0x10);  break;
 default     : lcd_send_byte(1,c);     break;
 }
 }
 
 char lcd_getc( byte x, byte y) {
 char value;
 
 lcd_gotoxy(x,y);
 lcd_rs=1;
 value = lcd_read_byte();
 lcd_rs=0;
 return(value);
 }
 #nolist
 
 | 
 |  |  
		|  |  
		| Hendrik 
 
 
 Joined: 19 Apr 2012
 Posts: 5
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Thu Apr 19, 2012 3:27 pm |   |  
				| 
 |  
				| I have disconnect pin 3 and it is NC |  |  
		|  |  
		|  |  
  
	| 
 
 | 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
 
 |