1. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Hello and thanks always

    I apologize becuase this must be the stupidest question ever but I would appreciate if someone help me.
    Tired of 7segs I bought a LCD. This one over here
    [​IMG]
    now you see the connections to the right....? How do I connect this? Ultimately I want to connect this to a board but in the meantime I also want to connect it to a breadboard.
    Now I think the most elegant solution would be something like
    [​IMG]

    However I dont have that kind of connector :confused:
    Another option is the "Pin headers" but you see these 2 rows of pins? they are so close to each other it is not possible to connect it to a breadboard:arghh:

    Any suggestions...?

    P.S. Also do you know any tutorial or resource where I can learn about these basic things: ergo connectors and stuff
     
  2. nsaspook

    AAC Fanatic!

    Aug 27, 2009
    2,907
    2,163
  3. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    I think the TS's problem is that the row spacing on the display header is .100" and the breadboard spacing between rows is .300". If you buy them with long tails, you can put a Z bend in the long ends of the headers @nsaspook shows to make the spacing fit the breadboard. You also could use a piece of .100" perfboard to mount one row directly and the other spaced 2 rows over and add jumpers as required (some perfboards have several holes connected together, that would help).

    These and these headers have longer (.318") tails to give you something to work with.

    To init the LCD and actually display something, see this thread.
     
    nsaspook likes this.
  4. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Or you can do it like this:
    lcd1.JPG
    lcd2.JPG
    I've soldered a 10 pin header on a strip board, and used short wires from the board to the LCD.
    PIN OUT
    1 -> GND
    2 ->VDD
    3 -> POT
    4 -> RS
    5 -> RW
    6 -> E
    7 -> D4
    8 -> D5
    9 -> D6
    10 -> D7

    This fits perfectly on a bread board.
     
    KansaiRobot and JohnInTX like this.
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Given a solderless breadboard... one could always solder on insulated solid bus wires and dress each one into the correct breadboard row. Something to mechanically hold things in place would be a blessing.

    As far as the code to drive these, look over the multiple threads on this very forum for other people driving these. I've yet to see one of these that doesn't use the extremely common HD44780 chip (or clone) to drive them. Google "HD44780 code" or "LCD code" will bring up lots of hits.
     
  6. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,383
    495
    Me thinks you chose the wrong thing to buy.
     
  7. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Can you tell me why?

    Well, I did my first try and it didnt work :oops:. The LCD does not even turn on. I am using only 4 wires (so 4-bit nibble mode) so I am suspecting something in the very first initialization (when it is still 8-bit) is not correct. Guess it is time go go back and study...
     
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,341
    1,022
    The link in post 3 above has a schematic and working code for XC8. It inits the LCD and does some messages. If you read the thread, you'll get an idea of what we did to implement an lcd. Lots of other threads here as well.
     
    KansaiRobot likes this.
  9. Jswale

    Member

    Jun 30, 2015
    121
    6
    @KansaiRobot post your code if you want help with the initialisation.
     
  10. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5

    Thank you . I read the code and it is similar to what I did but I am sure I am making a mistake somewhere.
    The code is for P1459 right? I am implementing it on a PIC18F4553 so I will have to change some ports (from C to D), so I will edit the code try it and let you know...:)

    Also, I have to report that the LCD is working, it lights up and so far prints some strange lines in the incorrect position, so I guess that is just an improvement lol.
     
  11. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    I ve tried two codes
    one is
    Code (Text):
    1.  
    2. void lcd_ini ( void )
    3. {
    4. TRISB &= 0xE3;  //Initialize B2, B3 and B4 as output
    5. lcd_port_dir &= 0x0F; //Initialize D4,D5,D6 and D7 as output
    6. dis_cmd ( 0x02 ); //  Clears the display and initialize LCD in 4-bit mode.
    7. //dis_cmd(0x33);
    8. //dis_cmd(0x32);
    9.  
    10. dis_cmd ( 0x28 ); // 0010 1000 to initialize LCD in 2 lines, 5X7 dots and 4bit mode.  //FUNCTION SET DL= 4 bits 5x7 dots(only option for 2 lines)
    11. dis_cmd ( 0x0C );    //0000 1100    //Display ON/OFF cursor not displayed  not blinking
    12. dis_cmd ( 0x06 );    //0000 0110    //Entry Mode Set  increment Address counter no display shift
    13. dis_cmd ( 0x80 );    //1000 0000   //Set DDRAM Address
    14. dis_cmd ( 0x01 );    //0000 0001   // Clear Display
    15. delay_ms ( 500 );
    16. }
    17.  
    and the other one is one I found here in the forum (although I added the delay functions)

    Code (Text):
    1. /* initialise the LCD - put into 4 bit mode */
    2. void
    3. lcd_init()
    4. {
    5.     char init_value;
    6.  
    7.     ADCON1 = 0x06;  // Disable analog pins on PORTA
    8.  
    9.     init_value = 0x3;
    10.     TRISA=0;
    11.     TRISD=0;
    12.     LCD_RS = 0;
    13.     LCD_EN = 0;
    14.     LCD_RW = 0;
    15.  
    16. //    DelayMs(15);    // wait 15mSec after power applied,
    17.     Delay10TCYx(375);
    18.     LCD_DATA     = init_value;
    19.     LCD_STROBE();
    20. //    DelayMs(5);
    21.     Delay10TCYx(125);
    22.  
    23.     LCD_STROBE();
    24. //    DelayUs(200);
    25.     Delay10TCYx(5);
    26.     LCD_STROBE();
    27. //    DelayUs(200);
    28.     Delay10TCYx(5);
    29.     LCD_DATA = 2;   // Four bit mode
    30.     LCD_STROBE();
    31.  
    32.     lcd_write(0x28); // Set interface length
    33.     lcd_write(0xF); // Display On, Cursor On, Cursor Blink
    34.     lcd_clear();    // Clear screen
    35.     lcd_write(0x6); // Set entry Mode
    36. }
    37.  
     
  12. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Please post the complete code. It's hard to say what could be wrong with just fractions...:)
     
  13. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Oh sorry.

    First the first one

    Code (Text):
    1. /*
    2. * File:   main.c
    3. *  In this program  we are going to program
    4. * how to show messages on a LCD connected to the microprocessor 18F4553
    5. *
    6. * The Pins are going to be the following:
    7. *
    8. *   PIC 18F4553                       LCD
    9. *   RB2                               En
    10. *   RB3                               RW
    11. *   RB4                               RS
    12. *
    13. *   RD4                               D4
    14. *   RD5                               D5
    15. *   RD6                               D6
    16. *   RD7                               D7
    17. *
    18. *
    19. * Created on 2015/08/05, 11:05
    20. */
    21.  
    22. #include <stdio.h>
    23. #include <stdlib.h>
    24. #include <p18f4553.h>
    25.  
    26. //Configuration Bits
    27. #pragma config PLLDIV = 5  //(20MHz crystal div by 5 preescale
    28. #pragma config CPUDIV = OSC4_PLL6  //we get 16 MHz
    29. #pragma config FOSC = INTOSC_HS   //Internal oscillator, HS oscillator used by USB (INTHS)
    30. #pragma config USBDIV = 2  //Usb from PLL
    31. #pragma config FCMEN    = OFF   //fail safe clock disabled
    32. #pragma config IESO = OFF  //oscillator switch over mode disable
    33. #pragma config PWRT = OFF
    34. #pragma config BOR = ON  //
    35. #pragma config BORV=3 //
    36. #pragma config VREGEN = ON //
    37. #pragma config WDT = OFF
    38. #pragma config WDTPS = 32768
    39.  
    40.  
    41. #pragma config CCP2MX = ON
    42. #pragma config PBADEN = OFF
    43. #pragma config LPT1OSC = OFF
    44.  
    45. #pragma config MCLRE = ON
    46.  
    47. #pragma config STVREN = ON
    48. #pragma config LVP = OFF
    49. #pragma config ICPRT = OFF
    50. #pragma config XINST = OFF
    51. #pragma config DEBUG = OFF
    52. #pragma config WRTD = OFF
    53.  
    54. //LCD Control pins
    55. #define rs PORTBbits.RB4
    56. #define rw PORTBbits.RB3
    57. #define en PORTBbits.RB2
    58.  
    59. //LCD Data pins
    60. #define lcdport PORTD
    61. #define lcd_port_dir TRISD
    62.  
    63. #define LEDPin LATEbits.LATE2 //Define LEDPin as PORT E Pin 2
    64. #define LEDTris TRISEbits.TRISE2 //Define LEDTris as TRISE Pin 2
    65.  
    66.  
    67.  
    68. void lcd_clear ( void );
    69. void lcd_2nd_line ( void );
    70. void lcd_1st_line ( void );
    71. void lcd_ini ( void );
    72. void dis_cmd ( unsigned char cmd_value );
    73. void dis_data ( unsigned char data_value );
    74. void lcdcmd ( unsigned char cmdout );
    75. void lcddata ( unsigned char dataout );
    76. void delay_ms ( int delay );
    77.  
    78. int main(int argc, char** argv)
    79. {
    80.  
    81. unsigned int i = 0, a = 3, b = 3;
    82. unsigned char data1 [] = "Kansai Robot";
    83. unsigned char data2 [] = "    LCD demo   ";
    84.  
    85. OSCCON = 0x72; // 0111 0010 set CPU Frequency as 8 MHz
    86.  
    87. LEDTris = 0; // Set LED Pin data direction to OUTPUT
    88. LEDPin = 1; // Set LED Pin
    89.  
    90. lcd_ini (); // LCD initialization
    91.  
    92. //Start up display on LCD
    93.  
    94. // Display the first line in the display
    95. while ( data1 [i] != '\0' )
    96.    {
    97.     dis_data ( data1 [i] );
    98.     delay_ms ( 200 );
    99.     i++;
    100.     }
    101. i = 0;
    102.  
    103. //Change line
    104. lcd_2nd_line ();
    105.  
    106. //Display the second line in the display
    107. while ( data2 [i] != '\0' )
    108.    {
    109.     dis_data ( data2 [i] );
    110.     delay_ms ( 200 );
    111.     i++;
    112.    }
    113. i = 0;
    114.  
    115. delay_ms ( 3000 );
    116.  
    117.  
    118. //Some other operations
    119.  
    120.  
    121.  
    122.  
    123.  
    124.  
    125. while(1)
    126. {
    127.      LEDPin = ~LEDPin ;// Togle LED Pin
    128.      delay_ms(1000);
    129. // ;  //nothin
    130. }
    131.  
    132.     return (EXIT_SUCCESS);
    133. }// end of main
    134.  
    135.  
    136. //======================== LCD routines definitions ========================//
    137.  
    138. void delay_ms ( int delay )
    139. {int ms, i;
    140. for ( ms = 0; ms < delay; ms ++ )
    141.     for ( i = 0; i < 50; i ++ );
    142. }
    143.  
    144. void lcd_ini ( void )
    145. {
    146. TRISB &= 0xE3;  //Initialize B2, B3 and B4 as output
    147. lcd_port_dir &= 0x0F; //Initialize D4,D5,D6 and D7 as output
    148.  
    149.  
    150. /* dis_cmd ( 0x02 ); //  Clears the display and initialize LCD in 4-bit mode.
    151. //dis_cmd(0x33);
    152. //dis_cmd(0x32);
    153.  
    154.  
    155. */
    156.  
    157. lcdport &= 0x0F;
    158. lcdport |= 0x30;
    159. rs=0;
    160. rw=0;
    161. //Strobe
    162. en = 1;   //go!
    163. delay_ms ( 50 );
    164. en = 0;  //Ok it is enough
    165. delay_ms ( 50 );
    166.  
    167. //Strobe
    168. en = 1;   //go!
    169. delay_ms ( 50 );
    170. en = 0;  //Ok it is enough
    171. delay_ms ( 50 );
    172.  
    173. //Strobe
    174. en = 1;   //go!
    175. delay_ms ( 50 );
    176. en = 0;  //Ok it is enough
    177. delay_ms ( 50 );
    178.  
    179. lcdport &= 0x0F;
    180. lcdport |= 0x20;
    181.  
    182. //Strobe
    183. en = 1;   //go!
    184. delay_ms ( 50 );
    185. en = 0;  //Ok it is enough
    186. delay_ms ( 50 );
    187.  
    188.  
    189. dis_cmd ( 0x28 ); // 0010 1000 to initialize LCD in 2 lines, 5X7 dots and 4bit mode.  //FUNCTION SET DL= 4 bits 5x7 dots(only option for 2 lines)
    190. dis_cmd ( 0x0E );    //0000 1100    //Display ON/OFF cursor not displayed  not blinking
    191. dis_cmd ( 0x06 );    //0000 0110    //Entry Mode Set  increment Address counter no display shift
    192. dis_cmd ( 0x80 );    //1000 0000   //Set DDRAM Address
    193. dis_cmd ( 0x01 );    //0000 0001   // Clear Display
    194.  
    195.  
    196. /*
    197. dis_cmd ( 0x28 ); // 0010 1000 to initialize LCD in 2 lines, 5X7 dots and 4bit mode.  //FUNCTION SET DL= 4 bits 5x7 dots(only option for 2 lines)
    198. dis_cmd ( 0x0C );    //0000 1100    //Display ON/OFF cursor not displayed  not blinking
    199. dis_cmd ( 0x06 );    //0000 0110    //Entry Mode Set  increment Address counter no display shift
    200. dis_cmd ( 0x80 );    //1000 0000   //Set DDRAM Address
    201. dis_cmd ( 0x01 );    //0000 0001   // Clear Display
    202. */
    203. delay_ms( 500 );
    204. }
    205.  
    206. void dis_cmd ( unsigned char cmd_value )
    207. {  //We send a command in two nibbles
    208. unsigned char cmd_value1;
    209. cmd_value1 = cmd_value & 0xF0; //mask lower nibble because PD4-PD7 pins are used.
    210. lcdcmd ( cmd_value1 );         // send to LCD
    211. cmd_value1 = ( ( cmd_value << 4 ) & 0xF0 ); //shift 4-bit and mask
    212. lcdcmd ( cmd_value1 ); // send to LCD
    213. }
    214.  
    215. void dis_data ( unsigned char data_value )
    216. {
    217. unsigned char data_value1;
    218. data_value1 = data_value & 0xF0;
    219. lcddata ( data_value1 );
    220. data_value1 = ( ( data_value << 4 ) & 0xF0 );
    221. lcddata ( data_value1 );
    222. }
    223.  
    224. void lcdcmd ( unsigned char cmdout )
    225. {
    226. lcdport &= 0x0F;  //set the pins to 0
    227. lcdport |= cmdout; // then set those pins to the command
    228. rs = 0;   //Command
    229. rw = 0;   //write
    230. en = 1;   //go!
    231. delay_ms ( 50 );
    232. en = 0;  //Ok it is enough
    233. delay_ms ( 50 );
    234. }
    235.  
    236. void lcddata ( unsigned char dataout )
    237. {
    238. lcdport &= 0x0F;  // set the pins to 0
    239. lcdport |= dataout;  // then set those to the data
    240. rs = 1;  //Data
    241. rw = 0;  //Write
    242. en = 1;  //go!
    243. delay_ms ( 50 );
    244. en = 0;  //ok it is enough
    245. delay_ms ( 50 );
    246. }
    247.  
    248. void lcd_clear(void)
    249. {
    250. dis_cmd(0x01); //0000 0001  //Clear Display
    251. delay_ms(10);
    252. }
    253. void lcd_2nd_line(void)
    254. {
    255. dis_cmd(0xC0); //1100 0000  (DDRAM address 40)
    256. delay_ms(1);
    257. }
    258.  
    259. void lcd_1st_line(void)
    260. {
    261. dis_cmd(0x80); //1000 0000  (DDRAM address 00)
    262. delay_ms(1);
    263. }
    264.  
    I ve changed a little the initialization function according to this thread indications but still all I see is garbage
     
  14. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    RB2, RB3, RB4 are also analog inputs. Do you have to take that into consideration?

    Have you a schematic to show?
     
  15. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    I added
    Code (Text):
    1.  
    2. ADCON1=0x0F; // All Digital Inputs
    3.  
    but the result is still the same.


    I have the schematic in a format only readable to a program in the intranet here, and the network seems broken sorry. I ll post it when I can

    EDIT: Also I ve checked and the PBADEN configuration bit is off so they are digital inputs on reset
     
    Last edited: Aug 6, 2015
  16. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Should it be digital inputs? I was thinking more in the line of disabling them...

    You could perhaps take a screenshot?

    Network problems sucks!
     
  17. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Actually they are outputs since they control the RS,RW and EN of the LCD
    their TRIS are made 0

    the pic
    Cap1.jpg
    As you see , just garbage lines
     
  18. KansaiRobot

    Thread Starter Active Member

    Jan 15, 2010
    318
    5
    Trying to rewrite JohnInTX code for 18F4553 but compilation fails on the delay function
    it says
    Code (Text):
    1. main.c:176: error: (1355) in-line delay argument too large
    therefore since _delay_ms(300) is not possible I replaced it by three times __delay_ms(100)

    Anyway, results. It does not work :(
    Cap2.jpg

    I ll post the code next
     
    Last edited: Aug 6, 2015
  19. nerdegutta

    Moderator

    Dec 15, 2009
    2,515
    785
    Try to make a for-loop
    Code (C):
    1. for(i=0;i<10;i++){
    2. __delay_ms(30);
    3. }
    or something. It should do the same.
     
  20. Jswale

    Member

    Jun 30, 2015
    121
    6
    To make sure initialization is correct you need to eliminate all data write functions from your code and see if you are still getting those lines or if the LCD just gives blocks (hinting that it is ready for operation). If it still gives those lines then something is wrong.
     
Loading...