Advertisement
RuiViana

lcd_2015

Aug 4th, 2015
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.01 KB | None | 0 0
  1. // ------------------------------ Pinos interface LCD --------------
  2. #define LCD_RS RB4 // LCD_RS PINO4
  3. #define LCD_EN RB5 // LCD_EN PINO6
  4. #define LCD_DATA PORTB // Define a porta de dados a ser usada, bits 0,1,2,3
  5. #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
  6. // ------------------------------------------------------------------
  7. void lcd_write(char c, char d) // Escreve um byte no LCD em 4 bit bus mode
  8. { // d bit RS 0 = cmd 1 = dado
  9. __delay_us(40);
  10. LCD_DATA = ( ( c >> 4 ) & 0x0F | d ); // Envia MSb do byte
  11. LCD_STROBE();
  12. LCD_DATA = ( c & 0x0F | d ); // Envia LSb do byte
  13. LCD_STROBE();
  14. }
  15. // ------------------------------------------------------------------
  16. void lcd_clear(void) // Limpa LCD e vai para o home
  17. {
  18. lcd_write(0x1,0x00); // 0x01 = clear 0x00 = cmd
  19. __delay_ms(2); // Aguarde de 2 ms
  20. }
  21. // ------------------------------------------------------------------
  22. void lcd_puts(const char * s) // Escreve uma string de chars no LCD
  23. { // É um sinalisador de pointer *s s pointer
  24. while(*s) // Enqunato houver
  25. lcd_write(*s++,0x10); // 0x10 = dado
  26. }
  27. // ------------------------------------------------------------------
  28. void lcd_putch(char c) // Escreve um character no LCD
  29. {
  30. lcd_write( c,0x10 ); // 0x10 dado
  31. }
  32. // ----------------------
  33. void lcd_goto(char pos) // Vai para uma posição especifica
  34. {
  35. lcd_write(0x80+pos,0x00); // 0x80 = location pos = linha + posição na linha
  36. }
  37. // ----------------------
  38. void lcd_init() // Initialisa o LCD - define 4 bit bus mode
  39. {
  40. char init_value = 0x03; // Caracter especial de inicialização
  41. LCD_EN = 0;
  42. __delay_ms(15); // Aguarde 15mSec após power on
  43. LCD_DATA = init_value;
  44. LCD_STROBE();
  45. __delay_ms(5); // Aguarde 5 mSec
  46. LCD_STROBE();
  47. __delay_us(200); // Aguarde 5 uSec
  48. LCD_STROBE();
  49. __delay_us(200); // Aguarde 5 uSec
  50. lcd_write(0x28,0x00); // Bus 4 bit bus mode 2 linhas mode 0x00 = cmd
  51. // bit5 Function Set
  52.  
  53. // bit4 DL: Interface data length control bit
  54. // bit4 = “High”, it means 8-bit bus mode with MPU.
  55. // bit4 = “Low”, it means 4-bit bus mode with MPU.
  56. // When 4-bit bus mode, it needs to transfer 4-bit data twice.
  57.  
  58. // bit3 N: Display line number control bit
  59. // bit3 = “Low”, 1-line display mode is set.
  60. // bit3 = “High”, 2-line display mode is set.
  61.  
  62. // bit2 F: Display font type control bit
  63. // bit2 = “Low”, 5 ´8 dots format display mode is set.
  64. // bit2 = “High”, 5 ´11 dots format display mode.
  65.  
  66. lcd_write(0x0C,0x00); // Display On, CURSOR OFF, Cursor Blink // Alterei para + uma variavel no write
  67. // bit3 Display ON/OFF Control
  68.  
  69. // bit2 D: Display ON/OFF control bit
  70. // bit2 = “High”, entire display is turned on.
  71. // bit2 = “Low”, display is turned off, but display data remains in DDRAM.
  72.  
  73. // bit1 C: Cursor ON/OFF control bit
  74. // bit1 = “High”, cursor is turned on.
  75. // bit1 = “Low”, cursor is disappeared in current display, but I/D register preserves its data.
  76.  
  77. // bit0 B: Cursor Blink ON/OFF control bit
  78. // bit0 = “High”, cursor blink is on, which performs alternately between all the “High” data and
  79. // display characters at the cursor position.
  80. // bit0 = “Low”, blink is off.
  81.  
  82. lcd_clear(); // Clear screen
  83.  
  84. lcd_write(0x06,0x00); // Set entry Mode // Alterei para + uma variavel no write
  85. // bit1 = 2 Entry Mode Set
  86.  
  87. // bit1 I/D: Increment / decrement of DDRAM address (cursor or blink)
  88. // bit1 = “High” cursor/blink moves to right and DDRAM address is increased by 1.
  89. // bit1 = “Low” cursor/blink moves to left and DDRAM address is decreased by 1.
  90.  
  91. // bit0 SH: Shift of entire display
  92. // bit0 If = “High” and DDRAM write operation, shift of entire display is performed according to I/D value
  93. // (I/D = “High”: shift left, I/D = “Low”: shift right).
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement