Advertisement
RuiViana

lcd.h

Jul 29th, 2015
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. /*
  2. * LCD interface example
  3. * Uses routines from delay.c
  4. * This code will interface to a standard LCD controller
  5. * like the Hitachi HD44780. It uses it in 4 bit mode, with
  6. * the hardware connected as follows (the standard 14 pin
  7. * LCD connector is used):
  8. *
  9. * PORT bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
  10. * PORT bit 4 is connected to the LCD RS input (register select)
  11. * PORT bit 5 is connected to the LCD EN bit (enable)
  12.  
  13. * To use these routines, set up the port I/O (TRISA, TRISB) then
  14. * call lcd_init(), then other routines as required.
  15. */
  16.  
  17. #include <htc.h>
  18. #ifndef _XTAL_FREQ // 4Mhz
  19. #define _XTAL_FREQ 4000000
  20. #endif
  21.  
  22. //#define LCD_RS RB4
  23. #define LCD_RS RA4
  24.  
  25. //#define LCD_EN RB5
  26. #define LCD_EN RA7
  27.  
  28. #define LCD_DATA PORTA //Define a porta de dados a ser usada, bits 0,1,2,3
  29.  
  30. #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
  31.  
  32. /* write a byte to the LCD in 4 bit mode */
  33. void lcd_write(unsigned char c,unsigned char d) //alterei para + uma variavel no write
  34. {
  35. __delay_us(40);
  36. LCD_DATA = ( ( c >> 4 ) & 0x0F | d ); //Alterei incluindo o "or d" para ligar o bit RA6 RS
  37. LCD_STROBE();
  38. LCD_DATA = ( c & 0x0F | d ); //Alterei incluindo o "or d" para ligar o bit RA6 RS
  39. LCD_STROBE();
  40. }
  41.  
  42. /* Clear and home the LCD */
  43. void lcd_clear(void)
  44. {
  45. LCD_RS = 0; //
  46. lcd_write(0x1,0x00); // Alterei para + uma variavel no write
  47. __delay_ms(2);
  48. }
  49.  
  50. /* write a string of chars to the LCD */
  51. void lcd_puts(const char * s) // * é um sinalisador de pointer *s s pointer
  52. {
  53. LCD_RS = 1; // write characters
  54. while(*s)
  55. lcd_write(*s++,0x10); //alterei para + uma variavel no write/ bit RB6 nescesario para escrita
  56. }
  57.  
  58. /* write one character to the LCD */
  59. void lcd_putch(char c)
  60. {
  61. LCD_RS = 1; // write characters
  62. lcd_write( c,0x10 ); //alterei para + uma variavel no write
  63. }
  64.  
  65. /* Go to the specified position */
  66. void lcd_goto(unsigned char pos)
  67. {
  68. LCD_RS = 0;
  69. lcd_write(0x80+pos,0x00); //alterei para + uma variavel no write
  70. }
  71.  
  72. /* initialise the LCD - put into 4 bit mode */
  73. void lcd_init()
  74. {
  75. char init_value;
  76. // CMCON = 0x07; // Disable analog pins on PORTA 16F628A
  77. // TRISB = 0b01000000;
  78.  
  79. init_value = 0x3;
  80. LCD_RS = 0;
  81. LCD_EN = 0;
  82.  
  83. __delay_ms(15); // wait 15mSec after power applied,
  84. LCD_DATA = init_value;
  85. LCD_STROBE();
  86. __delay_ms(5);
  87. LCD_STROBE();
  88. __delay_us(200);
  89. LCD_STROBE();
  90. __delay_us(200);
  91. LCD_DATA = 2; // Four bit mode
  92. LCD_STROBE();
  93.  
  94. lcd_write(0x28,0x00); // Set interface length //alterei para + uma variavel no write
  95. lcd_write(0xC,0x00); // Display On, CURSOR OFF, Cursor Blink //alterei para + uma variavel no write
  96. lcd_clear(); // Clear screen
  97. lcd_write(0x6,0x00); // Set entry Mode //alterei para + uma variavel no write
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement