Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------------------------ Pinos interface LCD --------------
- #define LCD_RS RB4 // LCD_RS PINO4
- #define LCD_EN RB5 // LCD_EN PINO6
- #define LCD_DATA PORTB // Define a porta de dados a ser usada, bits 0,1,2,3
- #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
- // ------------------------------------------------------------------
- void lcd_write(char c, char d) // Escreve um byte no LCD em 4 bit bus mode
- { // d bit RS 0 = cmd 1 = dado
- __delay_us(40);
- LCD_DATA = ( ( c >> 4 ) & 0x0F | d ); // Envia MSb do byte
- LCD_STROBE();
- LCD_DATA = ( c & 0x0F | d ); // Envia LSb do byte
- LCD_STROBE();
- }
- // ------------------------------------------------------------------
- void lcd_clear(void) // Limpa LCD e vai para o home
- {
- lcd_write(0x1,0x00); // 0x01 = clear 0x00 = cmd
- __delay_ms(2); // Aguarde de 2 ms
- }
- // ------------------------------------------------------------------
- void lcd_puts(const char * s) // Escreve uma string de chars no LCD
- { // É um sinalisador de pointer *s s pointer
- while(*s) // Enqunato houver
- lcd_write(*s++,0x10); // 0x10 = dado
- }
- // ------------------------------------------------------------------
- void lcd_putch(char c) // Escreve um character no LCD
- {
- lcd_write( c,0x10 ); // 0x10 dado
- }
- // ----------------------
- void lcd_goto(char pos) // Vai para uma posição especifica
- {
- lcd_write(0x80+pos,0x00); // 0x80 = location pos = linha + posição na linha
- }
- // ----------------------
- void lcd_init() // Initialisa o LCD - define 4 bit bus mode
- {
- char init_value = 0x03; // Caracter especial de inicialização
- LCD_EN = 0;
- __delay_ms(15); // Aguarde 15mSec após power on
- LCD_DATA = init_value;
- LCD_STROBE();
- __delay_ms(5); // Aguarde 5 mSec
- LCD_STROBE();
- __delay_us(200); // Aguarde 5 uSec
- LCD_STROBE();
- __delay_us(200); // Aguarde 5 uSec
- lcd_write(0x28,0x00); // Bus 4 bit bus mode 2 linhas mode 0x00 = cmd
- // bit5 Function Set
- // bit4 DL: Interface data length control bit
- // bit4 = “High”, it means 8-bit bus mode with MPU.
- // bit4 = “Low”, it means 4-bit bus mode with MPU.
- // When 4-bit bus mode, it needs to transfer 4-bit data twice.
- // bit3 N: Display line number control bit
- // bit3 = “Low”, 1-line display mode is set.
- // bit3 = “High”, 2-line display mode is set.
- // bit2 F: Display font type control bit
- // bit2 = “Low”, 5 ´8 dots format display mode is set.
- // bit2 = “High”, 5 ´11 dots format display mode.
- lcd_write(0x0C,0x00); // Display On, CURSOR OFF, Cursor Blink // Alterei para + uma variavel no write
- // bit3 Display ON/OFF Control
- // bit2 D: Display ON/OFF control bit
- // bit2 = “High”, entire display is turned on.
- // bit2 = “Low”, display is turned off, but display data remains in DDRAM.
- // bit1 C: Cursor ON/OFF control bit
- // bit1 = “High”, cursor is turned on.
- // bit1 = “Low”, cursor is disappeared in current display, but I/D register preserves its data.
- // bit0 B: Cursor Blink ON/OFF control bit
- // bit0 = “High”, cursor blink is on, which performs alternately between all the “High” data and
- // display characters at the cursor position.
- // bit0 = “Low”, blink is off.
- lcd_clear(); // Clear screen
- lcd_write(0x06,0x00); // Set entry Mode // Alterei para + uma variavel no write
- // bit1 = 2 Entry Mode Set
- // bit1 I/D: Increment / decrement of DDRAM address (cursor or blink)
- // bit1 = “High” cursor/blink moves to right and DDRAM address is increased by 1.
- // bit1 = “Low” cursor/blink moves to left and DDRAM address is decreased by 1.
- // bit0 SH: Shift of entire display
- // bit0 If = “High” and DDRAM write operation, shift of entire display is performed according to I/D value
- // (I/D = “High”: shift left, I/D = “Low”: shift right).
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement