Autor Tema: escribir en LCD de 16x4  (Leído 8115 veces)

0 Usuarios y 1 Visitante están viendo este tema.

Desconectado japifer_22

  • PIC18
  • ****
  • Mensajes: 405
escribir en LCD de 16x4
« en: 31 de Enero de 2009, 15:22:35 »
hola de nuevo esta ves los molesto por lo siguiente. estoy contolando una pantalla LCD de 16x4 pero el drama que tengo es que solo pudo controlar las dos primeras filas de ella, y e tratado con el gotoxy intentar de posisionarla en la 3º o 4ta fila una letra cualquiera pero no puedo. mi pregunta es como lo puedo hacer, me faltara alguna libreria? especial o alguna intruccion.
bueno espero que me puedan ayudar saludos. 

Desconectado gera

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2188
Re: escribir en LCD de 16x4
« Respuesta #1 en: 31 de Enero de 2009, 15:34:28 »
Buenas! Podrias especificar q compilador estas usando y q librerias? Y si es posible, el modelo de tu lcd tambien.
saludos!

"conozco dos cosas infinitas: el universo y la estupidez humana. Y no estoy muy seguro del primero." A.Einstein

Desconectado japifer_22

  • PIC18
  • ****
  • Mensajes: 405
Re: escribir en LCD de 16x4
« Respuesta #2 en: 31 de Enero de 2009, 15:46:19 »
hola tienes rason perdon ^^ bueno estoy utilisando el compilador ccs y las librerias son     #define use_portb_lcd TRUE    y     
#include<lcd.c>    y perdon la LCD es de 16x20 y el modelo es VT204D-RN-GBS. bueno espero que me puedan ayudar ^^           

Desconectado MiCrOtRoNiC

  • PIC18
  • ****
  • Mensajes: 271
Re: escribir en LCD de 16x4
« Respuesta #3 en: 31 de Enero de 2009, 16:26:26 »
esa es un lcd de 20x4 no de 16x20 aunque creo que quisiste decir 16x2...amigo en el foro de www.ccsinfo.com hay una libreria para controlar 20x4 y 40x4

Desconectado japifer_22

  • PIC18
  • ****
  • Mensajes: 405
Re: escribir en LCD de 16x4
« Respuesta #4 en: 31 de Enero de 2009, 16:42:14 »
uff no se que me pasa XD sip tienes rason es de 20x4 perdon

Desconectado MiCrOtRoNiC

  • PIC18
  • ****
  • Mensajes: 271
Re: escribir en LCD de 16x4
« Respuesta #5 en: 31 de Enero de 2009, 16:56:55 »
Flexible LCD driver for 20x4 LCDs

Código: C
  1. // Flex_LCD420.c
  2.  
  3. // These pins are for my Microchip PicDem2-Plus board,
  4. // which I used to test this driver.
  5. // An external 20x4 LCD is connected to these pins.
  6. // Change these pins to match your own board's connections.
  7.  
  8. #define LCD_DB4   PIN_D4
  9. #define LCD_DB5   PIN_D5
  10. #define LCD_DB6   PIN_D6
  11. #define LCD_DB7   PIN_D7
  12.  
  13. #define LCD_RS    PIN_E0
  14. #define LCD_RW    PIN_E1
  15. #define LCD_E     PIN_E2
  16.  
  17. /*
  18. // To prove that the driver can be used with random
  19. // pins, I also tested it with these pins:
  20. #define LCD_DB4   PIN_D4
  21. #define LCD_DB5   PIN_B1
  22. #define LCD_DB6   PIN_C5
  23. #define LCD_DB7   PIN_B5
  24.  
  25. #define LCD_RS    PIN_E2
  26. #define LCD_RW    PIN_B2
  27. #define LCD_E     PIN_D6
  28. */
  29.  
  30. // If you want only a 6-pin interface to your LCD, then
  31. // connect the R/W pin on the LCD to ground, and comment
  32. // out the following line.  Doing so will save one PIC
  33. // pin, but at the cost of losing the ability to read from
  34. // the LCD.  It also makes the write time a little longer
  35. // because a static delay must be used, instead of polling
  36. // the LCD's busy bit.  Normally a 6-pin interface is only
  37. // used if you are running out of PIC pins, and you need
  38. // to use as few as possible for the LCD.
  39. #define USE_RW_PIN   1    
  40.  
  41.  
  42. // These are the line addresses for most 4x20 LCDs.
  43. #define LCD_LINE_1_ADDRESS 0x00
  44. #define LCD_LINE_2_ADDRESS 0x40
  45. #define LCD_LINE_3_ADDRESS 0x14
  46. #define LCD_LINE_4_ADDRESS 0x54
  47.  
  48. // These are the line addresses for LCD's which use
  49. // the Hitachi HD66712U controller chip.
  50. /*
  51. #define LCD_LINE_1_ADDRESS 0x00
  52. #define LCD_LINE_2_ADDRESS 0x20
  53. #define LCD_LINE_3_ADDRESS 0x40
  54. #define LCD_LINE_4_ADDRESS 0x60
  55. */
  56.  
  57.  
  58. //========================================
  59.  
  60. #define lcd_type 2   // 0=5x7, 1=5x10, 2=2 lines(or more)
  61.  
  62. int8 lcd_line;
  63.  
  64. int8 const LCD_INIT_STRING[4] =
  65. {
  66.  0x20 | (lcd_type << 2),  // Set mode: 4-bit, 2+ lines, 5x8 dots
  67.  0xc,                     // Display on
  68.  1,                       // Clear display
  69.  6                        // Increment cursor
  70.  };
  71.                              
  72.  
  73. //-------------------------------------
  74. void lcd_send_nibble(int8 nibble)
  75. {
  76. // Note:  !! converts an integer expression
  77. // to a boolean (1 or 0).
  78.  output_bit(LCD_DB4, !!(nibble & 1));
  79.  output_bit(LCD_DB5, !!(nibble & 2));
  80.  output_bit(LCD_DB6, !!(nibble & 4));  
  81.  output_bit(LCD_DB7, !!(nibble & 8));  
  82.  
  83.  delay_cycles(1);
  84.  output_high(LCD_E);
  85.  delay_us(2);
  86.  output_low(LCD_E);
  87. }
  88.  
  89. //-----------------------------------
  90. // This sub-routine is only called by lcd_read_byte().
  91. // It's not a stand-alone routine.  For example, the
  92. // R/W signal is set high by lcd_read_byte() before
  93. // this routine is called.    
  94.  
  95. #ifdef USE_RW_PIN
  96. int8 lcd_read_nibble(void)
  97. {
  98. int8 retval;
  99. // Create bit variables so that we can easily set
  100. // individual bits in the retval variable.
  101. #bit retval_0 = retval.0
  102. #bit retval_1 = retval.1
  103. #bit retval_2 = retval.2
  104. #bit retval_3 = retval.3
  105.  
  106. retval = 0;
  107.    
  108. output_high(LCD_E);
  109. delay_us(1);
  110.  
  111. retval_0 = input(LCD_DB4);
  112. retval_1 = input(LCD_DB5);
  113. retval_2 = input(LCD_DB6);
  114. retval_3 = input(LCD_DB7);
  115.  
  116. output_low(LCD_E);
  117. delay_us(1);
  118.    
  119. return(retval);  
  120. }  
  121. #endif
  122.  
  123. //---------------------------------------
  124. // Read a byte from the LCD and return it.
  125.  
  126. #ifdef USE_RW_PIN
  127. int8 lcd_read_byte(void)
  128. {
  129. int8 low;
  130. int8 high;
  131.  
  132. output_high(LCD_RW);
  133. delay_cycles(1);
  134.  
  135. high = lcd_read_nibble();
  136.  
  137. low = lcd_read_nibble();
  138.  
  139. return( (high<<4) | low);
  140. }
  141. #endif
  142.  
  143. //----------------------------------------
  144. // Send a byte to the LCD.
  145. void lcd_send_byte(int8 address, int8 n)
  146. {
  147. output_low(LCD_RS);
  148.  
  149. #ifdef USE_RW_PIN
  150. while(bit_test(lcd_read_byte(),7)) ;
  151. #else
  152. delay_us(60);
  153. #endif
  154.  
  155. if(address)
  156.    output_high(LCD_RS);
  157. else
  158.    output_low(LCD_RS);
  159.      
  160.  delay_cycles(1);
  161.  
  162. #ifdef USE_RW_PIN
  163. output_low(LCD_RW);
  164. delay_cycles(1);
  165. #endif
  166.  
  167. output_low(LCD_E);
  168.  
  169. lcd_send_nibble(n >> 4);
  170. lcd_send_nibble(n & 0xf);
  171. }
  172. //----------------------------
  173.  
  174. void lcd_init(void)
  175. {
  176. int8 i;
  177.  
  178. lcd_line = 1;
  179.  
  180. output_low(LCD_RS);
  181.  
  182. #ifdef USE_RW_PIN
  183. output_low(LCD_RW);
  184. #endif
  185.  
  186. output_low(LCD_E);
  187.  
  188. // Some LCDs require 15 ms minimum delay after
  189. // power-up.  Others require 30 ms.  I'm going
  190. // to set it to 35 ms, so it should work with
  191. // all of them.
  192. delay_ms(35);        
  193.  
  194. for(i=0 ;i < 3; i++)
  195.    {
  196.     lcd_send_nibble(0x03);
  197.     delay_ms(5);
  198.    }
  199.  
  200. lcd_send_nibble(0x02);
  201.  
  202. for(i=0; i < sizeof(LCD_INIT_STRING); i++)
  203.    {
  204.     lcd_send_byte(0, LCD_INIT_STRING[i]);
  205.    
  206.     // If the R/W signal is not used, then
  207.     // the busy bit can't be polled.  One of
  208.     // the init commands takes longer than
  209.     // the hard-coded delay of 50 us, so in
  210.     // that case, lets just do a 5 ms delay
  211.     // after all four of them.
  212.     #ifndef USE_RW_PIN
  213.     delay_ms(5);
  214.     #endif
  215.    }
  216.  
  217. }
  218.  
  219. //----------------------------
  220.  
  221. void lcd_gotoxy(int8 x, int8 y)
  222. {
  223. int8 address;
  224.  
  225.  
  226. switch(y)
  227.   {
  228.    case 1:
  229.      address = LCD_LINE_1_ADDRESS;
  230.      break;
  231.  
  232.    case 2:
  233.      address = LCD_LINE_2_ADDRESS;
  234.      break;
  235.  
  236.    case 3:
  237.      address = LCD_LINE_3_ADDRESS;
  238.      break;
  239.  
  240.    case 4:
  241.      address = LCD_LINE_4_ADDRESS;
  242.      break;
  243.  
  244.    default:
  245.      address = LCD_LINE_1_ADDRESS;
  246.      break;
  247.      
  248.   }
  249.  
  250. address += x-1;
  251. lcd_send_byte(0, 0x80 | address);
  252. }
  253.  
  254. //-----------------------------
  255. void lcd_putc(char c)
  256. {
  257.  switch(c)
  258.    {
  259.     case '\f':
  260.       lcd_send_byte(0,1);
  261.       lcd_line = 1;
  262.       delay_ms(2);
  263.       break;
  264.    
  265.     case '\n':
  266.        lcd_gotoxy(1, ++lcd_line);
  267.        break;
  268.    
  269.     case '\b':
  270.        lcd_send_byte(0,0x10);
  271.        break;
  272.    
  273.     default:
  274.        lcd_send_byte(1,c);
  275.        break;
  276.    }
  277. }
  278.  
  279. //------------------------------
  280. #ifdef USE_RW_PIN
  281. char lcd_getc(int8 x, int8 y)
  282. {
  283. char value;
  284.  
  285. lcd_gotoxy(x,y);
  286.  
  287. // Wait until busy flag is low.
  288. while(bit_test(lcd_read_byte(),7));
  289.  
  290. output_high(LCD_RS);
  291. value = lcd_read_byte();
  292. output_low(LCD_RS);
  293.  
  294. return(value);
  295. }
  296. #endif

test...
Código: C
  1. #include <16F877.H>
  2. #fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
  3. #use delay(clock = 4000000)
  4.  
  5. #include <Flex_LCD420.c>  
  6.  
  7. //===================================
  8. void main()
  9. {
  10. int8 i;
  11. int8 b1, b2, b3, b4;
  12.  
  13. // The lcd_init() function should always be called once,
  14. // near the start of your program.
  15. lcd_init();
  16.  
  17. // Clear the LCD.
  18. printf(lcd_putc, "\f");
  19. delay_ms(500);
  20.  
  21.  
  22. while(1)
  23.   {
  24.    // Test the clear screen and newline commands.
  25.    // Also test that we can write to all 4 lines.
  26.    printf(lcd_putc, "\fThis is the 1st line");
  27.    printf(lcd_putc, "\nNext is the 2nd line");
  28.    printf(lcd_putc, "\nThis is the 3rd line");
  29.    printf(lcd_putc, "\nFinally the 4th line");
  30.    delay_ms(3000);
  31.  
  32.    // Test some additional characters.
  33.    printf(lcd_putc, "\fABCDEFGHIJKLMNOPQRST");
  34.    printf(lcd_putc, "\nabcdefghijklmnopqrst");
  35.    printf(lcd_putc, "\n12345678901234567890");
  36.    printf(lcd_putc, "\n!@#$^&*(){}[]:;<>?/=");
  37.    delay_ms(3000);
  38.  
  39.    // Clear the LCD.
  40.    printf(lcd_putc, "\f");
  41.    delay_ms(500);
  42.  
  43.    // Test that lcd_gotoxy() works.  Go to each of
  44.    // the four corners and put a number in each one,
  45.    // in a clockwise direction, starting with the upper
  46.    // left corner.
  47.    lcd_gotoxy(4, 2);      
  48.    printf(lcd_putc, "Put a number in");  
  49.    lcd_gotoxy(4, 3);      
  50.    printf(lcd_putc, "each corner.");  
  51.    lcd_gotoxy(1, 1);      
  52.    printf(lcd_putc, "1");  
  53.    lcd_gotoxy(20, 1);      
  54.    printf(lcd_putc, "2");  
  55.    lcd_gotoxy(20, 4);      
  56.    printf(lcd_putc, "3");  
  57.    lcd_gotoxy(1, 4);      
  58.    printf(lcd_putc, "4");  
  59.    delay_ms(3000);
  60.  
  61. // Read the character that was written in each corner
  62. // of the LCD and display it.   This tests the lcd_getc()
  63. // function.  
  64. // The following test can only be done if we can read
  65. // from the LCD.  If the RW pin is not used, then the
  66. // LCD is in write-only mode, and we can't do this test.
  67. // The #ifdef statement will prevent the code from
  68. // being compiled, in that case.
  69.  
  70. #ifdef USE_RW_PIN  
  71.    // Test if lcd_getc() can read
  72.    // a byte from each corner.
  73.    b1 = lcd_getc(1,1);  
  74.    b2 = lcd_getc(20,1);  
  75.    b3 = lcd_getc(20,4);  
  76.    b4 = lcd_getc(1,4);  
  77.    lcd_gotoxy(1, 1);      
  78.    printf(lcd_putc, "\fRead these bytes\n");
  79.    printf(lcd_putc, "from the 4 corners:\n\n");
  80.    printf(lcd_putc, "     %c %c %c %c", b1, b2, b3, b4);      
  81.    delay_ms(3000);
  82. #endif
  83.  
  84.    // Type some characters and backspace over them.
  85.    printf(lcd_putc, "\fType characters and\n");
  86.    printf(lcd_putc,   "backspace over them.");
  87.    delay_ms(2000);
  88.  
  89.    // Go to end of 2nd line.
  90.    lcd_gotoxy(20, 2);      
  91.  
  92.    // Backspace over 2nd line.
  93.    for(i = 0; i < 20; i++)
  94.       {
  95.        printf(lcd_putc," \b\b");
  96.        delay_ms(150);
  97.       }
  98.  
  99.    // Go to end of first line.              
  100.    lcd_gotoxy(20, 1);      
  101.  
  102.    // Backspace over first line.
  103.    for(i = 0; i < 20; i++)
  104.       {
  105.        printf(lcd_putc," \b\b");
  106.        delay_ms(150);
  107.       }        
  108.  
  109.   }  
  110.  
  111. }

Desconectado japifer_22

  • PIC18
  • ****
  • Mensajes: 405
Re: escribir en LCD de 16x4
« Respuesta #6 en: 01 de Febrero de 2009, 16:47:57 »
hola grax por la ayuda bueno era mas fasil de lo que pense solo tenemos que agregar la libreria de el y mas ensima ya biene definida es la #include<lcd420.c>  al poner esto ta listo para manejar el LCD de 20X4.
bueno saludo y grax = por la ayuda