Skip to content

Instantly share code, notes, and snippets.

@pferreir
Created May 31, 2014 23:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pferreir/dcb134eeaee309c281de to your computer and use it in GitHub Desktop.
Save pferreir/dcb134eeaee309c281de to your computer and use it in GitHub Desktop.
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"
void _set_pin(uint8_t port, uint8_t val) {
if (val) {
PORTA |= _BV(port);
} else {
PORTA &= ~_BV(port);
}
}
void set_rs(int v) {
_set_pin(PA4, v);
}
void set_rw(int v) {
_set_pin(PA5, v);
}
void set_e(int v) {
_set_pin(PA6, v);
}
void e_cycle() {
set_e(0);
set_e(1);
_delay_us(1);
set_e(0);
}
void set_data(uint8_t data) {
PORTC = data;
e_cycle();
}
void wait_busy() {
// PORTC |= _BV(PC7);
// set_e(1);
// set_rs(0);
// set_rw(1);
// DDRC &= ~_BV(PC7);
// while(PORTC & 0x80) {
// set_e(0);
// _delay_us(0.230);
// set_e(1);
// }
// DDRC |= _BV(PC7);
_delay_us(400);
}
void send_command(uint8_t cmd) {
set_rs(0);
set_rw(0);
set_data(cmd);
wait_busy();
}
void send_data(uint8_t data) {
set_rs(1);
set_rw(0);
set_data(data);
wait_busy();
}
void display_start() {
set_rs(0);
set_rw(0);
set_e(0);
_delay_ms(40);
send_command(0x30);
_delay_ms(10);
send_command(0x30);
_delay_ms(1);
send_command(0x30);
_delay_ms(1);
send_command(0x38); // function set
send_command(0x08); // display control
send_command(0x01); // clear
send_command(0x06); // entry mode
}
int main(void) {
DDRA = 0xFF;
DDRC = 0xFF;
PORTC = 0;
PORTA = 0;
PORTA = 1;
_delay_ms(2000);
PORTA = 0;
display_start();
// lcd_init(LCD_DISP_ON_CURSOR_BLINK);
// lcd_clrscr();
while (1) {
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment