Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- */
- #include <avr/io.h>
- #include <util/delay.h>
- #define F_CPU 16000000
- /*
- * Este codigo eh para ser usado com display LCD 16x2
- * no modo 8-bit
- *
- */
- //**************Definicoes para pinos de Controle***********
- #define RS (1 << PB0)
- #define E (1 << PB1)
- //********************Definicoes do Display*****************
- #define Linha 2
- #define Coluna 16
- int main(void)
- {
- DDRD = 0xFF;
- DDRB |= RS | E;
- iniciaDisplay();
- while(1){
- }
- return 0;
- }
- /*
- * Esta inicializacao e recomEdada pelo datasheet do display
- * para casos onde a fonte de Eergia nao e satisfatoria
- */
- void iniciaDisplay(void){
- PORTB &= ~RS; // Desabilitar o sinal de Register Select
- PORTB &= ~E; // Desabilitar o sinal de Enable
- _delay_ms(20);
- PORTD |= 0x30;
- _delay_ms(5);
- PORTD |= 0x30;
- _delay_ms(1);
- PORTD |= 0x30;
- _delay_ms(10);
- functionSet();
- clearDisplay();
- entryMode();
- displayOn();
- }
- //Function Set para 8-Bits, duas linhas e 5x10 dots
- void functionSet(void){
- /*
- * RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
- * 0 0 0 0 1 1 1 1 * *
- */
- PORTB &= ~RS; // Desabilitar o sinal de Register Select
- PORTD |= 0x38;
- PORTB |= E; // Desabilitar o sinal de Enable
- _delay_ms(1);
- PORTB &= ~E;
- _delay_ms(1);
- }
- // Limpa o Display
- void clearDisplay(void){
- /*
- * RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
- * 0 0 0 0 0 0 0 0 0 1
- */
- PORTB &= ~RS; // Desabilitar o sinal de Register Select
- PORTD |= 0x01;
- PORTB |= E;
- _delay_ms(1);
- PORTB &= ~E;
- _delay_ms(1);
- }
- // Voltar o cursor a posicao 0 (Edereco 0)
- void cursorAtHome(void){
- /*
- * RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
- * 0 0 0 0 0 0 0 0 1 *
- * Testar DB0 com 0 ou 1
- */
- PORTB &= ~RS; // Desabilitar o sinal de Register Select
- PORTD |= 0x02;
- PORTB |= E;
- _delay_ms(1);
- PORTB &= ~E;
- _delay_ms(1);
- }
- void displayOn(void){
- /*
- * RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
- * 0 0 0 0 0 0 1 1 1 1
- * Display On com cursor piscando
- */
- PORTB &= ~RS; // Desabilitar o sinal de Register Select
- PORTD |= 0x0F;
- PORTB |= E;
- _delay_ms(1);
- PORTB &= ~E;
- _delay_ms(1);
- }
- void displayOff(void){
- /*
- * RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
- * 0 0 0 0 0 0 1 0 0 0
- * Display On com cursor piscando
- */
- PORTB &= ~RS; // Desabilitar o sinal de Register Select
- PORTD |= 0x08;
- PORTB |= E;
- _delay_ms(1);
- PORTB &= ~E;
- _delay_ms(1);
- }
- void entryMode(void){
- /*
- * RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
- * 0 0 0 0 0 0 0 1 1 0
- * Display On com cursor piscando
- */
- PORTB &= ~RS; // Desabilitar o sinal de Register Select
- PORTD |= 0x06;
- PORTB |= E;
- _delay_ms(1);
- PORTB &= ~E;
- _delay_ms(1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement