Skip to content

Instantly share code, notes, and snippets.

@antonyalkmim
Last active June 16, 2016 23:21
Show Gist options
  • Save antonyalkmim/a4e932ac8d01243ef652a9013bc3b651 to your computer and use it in GitHub Desktop.
Save antonyalkmim/a4e932ac8d01243ef652a9013bc3b651 to your computer and use it in GitHub Desktop.
Arduino - Display LCD
/*
* Enviar caracteres e comandos ao LCD com via de dados de 8 bits.
* c é o dado e cd indica se é instrução ou caractere (0 ou 1).
**/
void cmd_LCD(unsigned char c, char cd);
/* Inicialização do LCD com via de dados de 8 bits */
void inic_LCD_8bits();
/* Escrita no LCD – dados armazenados na RAM */
void escreve_LCD(char *c);
/* Escrita no LCD – dados armazenados na FLASH */
void escreve_LCD_Flash(const char *c);
void inic_LCD_8bits(){
PORTB = 2;
_delay_us(40);
PORTD = (7 << 3); //function set
_delay_us(39);
PORTD = (7 << 3); //function set
_delay_us(37);
PORTD = (7 << 1); //display control
_delay_us(37);
PORTD = 1; //display clear
_delay_ms(1.53);
PORTD = (2 << 1); //mode set
}
void cmd_LCD(unsigned char c, char cd){
//instrucao
if(cd == '0'){
PORTB &= ~(1 << 1); //modo de instrucao
}
//caractere
if(cd == '1'){
PORTB |= (1 << 1); //modo de dados
}
PORTD = c;
//gerar pulso de habilitacao
_delay_us(1);
PORTB |= 1;
_delay_us(1);
PORTB &= 0b11111110;
_delay_us(45);
}
void escreve_LCD(char *c){
int ch = 0;
while (c[ch] != 0) {
cmd_LCD(c[ch], '1');
++ch;
}
}
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "display.hpp"
char op;
int temp;
void setup(void){
DDRB = 0xFF;
DDRD = 0x00;
//Tensão de referência
// select_reference(INTERNAL_1_1);
// //Entrada analógica ADC0;
// set_analog_channel(0);
// //Divisão do clock da CPU 128
// set_prescaler();
// // Habilita a interrupção do ADC
// enable_interrupt_adc();
// //Habilita o ADC
// enable(true);
//Control and Status Register
// ADCSRB = 0x00;
//
// //Configura a forma que o resultado da conversão do ADC
// set_result_adjust(RIGHT_ADJUST);
// //Habilita individualmente cada entrada do ADC
// enable_input(0);
//
// //Modo de auto disparo ativo
// start();
inic_LCD_8bits();
}
void loop(void){
escreve_LCD("TESTE");
}
int main(){
setup();
while(true){
loop();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment