Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * LCD interface example
- * Uses routines from delay.c
- * This code will interface to a standard LCD controller
- * like the Hitachi HD44780. It uses it in 4 bit mode, with
- * the hardware connected as follows (the standard 14 pin
- * LCD connector is used):
- *
- * PORT bits 0-3 are connected to the LCD data bits 4-7 (high nibble)
- * PORT bit 4 is connected to the LCD RS input (register select)
- * PORT bit 5 is connected to the LCD EN bit (enable)
- * To use these routines, set up the port I/O (TRISA, TRISB) then
- * call lcd_init(), then other routines as required.
- */
- #include <htc.h>
- #ifndef _XTAL_FREQ // 4Mhz
- #define _XTAL_FREQ 4000000
- #endif
- //#define LCD_RS RB4
- #define LCD_RS RA4
- //#define LCD_EN RB5
- #define LCD_EN RA7
- #define LCD_DATA PORTA //Define a porta de dados a ser usada, bits 0,1,2,3
- #define LCD_STROBE() ((LCD_EN = 1),(LCD_EN=0))
- /* write a byte to the LCD in 4 bit mode */
- void lcd_write(unsigned char c,unsigned char d) //alterei para + uma variavel no write
- {
- __delay_us(40);
- LCD_DATA = ( ( c >> 4 ) & 0x0F | d ); //Alterei incluindo o "or d" para ligar o bit RA6 RS
- LCD_STROBE();
- LCD_DATA = ( c & 0x0F | d ); //Alterei incluindo o "or d" para ligar o bit RA6 RS
- LCD_STROBE();
- }
- /* Clear and home the LCD */
- void lcd_clear(void)
- {
- LCD_RS = 0; //
- lcd_write(0x1,0x00); // Alterei para + uma variavel no write
- __delay_ms(2);
- }
- /* write a string of chars to the LCD */
- void lcd_puts(const char * s) // * é um sinalisador de pointer *s s pointer
- {
- LCD_RS = 1; // write characters
- while(*s)
- lcd_write(*s++,0x10); //alterei para + uma variavel no write/ bit RB6 nescesario para escrita
- }
- /* write one character to the LCD */
- void lcd_putch(char c)
- {
- LCD_RS = 1; // write characters
- lcd_write( c,0x10 ); //alterei para + uma variavel no write
- }
- /* Go to the specified position */
- void lcd_goto(unsigned char pos)
- {
- LCD_RS = 0;
- lcd_write(0x80+pos,0x00); //alterei para + uma variavel no write
- }
- /* initialise the LCD - put into 4 bit mode */
- void lcd_init()
- {
- char init_value;
- // CMCON = 0x07; // Disable analog pins on PORTA 16F628A
- // TRISB = 0b01000000;
- init_value = 0x3;
- LCD_RS = 0;
- LCD_EN = 0;
- __delay_ms(15); // wait 15mSec after power applied,
- LCD_DATA = init_value;
- LCD_STROBE();
- __delay_ms(5);
- LCD_STROBE();
- __delay_us(200);
- LCD_STROBE();
- __delay_us(200);
- LCD_DATA = 2; // Four bit mode
- LCD_STROBE();
- lcd_write(0x28,0x00); // Set interface length //alterei para + uma variavel no write
- lcd_write(0xC,0x00); // Display On, CURSOR OFF, Cursor Blink //alterei para + uma variavel no write
- lcd_clear(); // Clear screen
- lcd_write(0x6,0x00); // Set entry Mode //alterei para + uma variavel no write
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement