Created
February 27, 2014 10:19
-
-
Save naquad/9247611 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <avr/interrupt.h> | |
#include <util/delay.h> | |
#include <util/delay_basic.h> | |
#include "macroes.h" | |
// LCD is wired to PORTB | |
// higher bits are data bits, | |
// lower are flags | |
#define LCD_PORT PORTB | |
#define LCDRS PB0 | |
#define LCDRW PB1 | |
#define LCDE PB2 | |
#define LCD4 PB3 | |
#define LCD5 PB4 | |
#define LCD6 PB5 | |
#define LCD7 PB6 | |
void _lcd_cmd(uint8_t delay, uint8_t cmd){ | |
LCD_PORT = cmd; | |
_delay_loop_1(delay); | |
LCD_PORT = 0; | |
} | |
#define lcd_cmd(delay, ...) _lcd_cmd(delay, bits(LCDE, ## __VA_ARGS__)) | |
void lcd_init(void){ | |
_delay_ms(1000); // it should be >15ms, but just in case | |
/// page 34, 4-bit interface initialization | |
lcd_cmd(5, LCD5, LCD4); | |
lcd_cmd(1, LCD5, LCD4); | |
lcd_cmd(1, LCD5, LCD4); | |
lcd_cmd(1, LCD5); | |
lcd_cmd(1, LCD5); | |
lcd_cmd(1, LCD7); | |
lcd_cmd(1); | |
lcd_cmd(1, LCD7); | |
lcd_cmd(1); | |
lcd_cmd(1, LCD4); | |
lcd_cmd(1); | |
lcd_cmd(1, LCD5, LCD4); | |
} | |
void lcd_write(unsigned char c){ | |
// LCDRS to write to data | |
_lcd_cmd(1, _BV(LCDRS) | ((c >> 4) << 4)); // higher | |
_lcd_cmd(1, _BV(LCDRS) | ((c & 0x0F) << 4)); // lower | |
} | |
/* | |
** Main Function | |
*/ | |
int main(void) | |
{ | |
DDRB = 0xFF; | |
lcd_init(); | |
while(1){ | |
lcd_write('a'); | |
} | |
// Finally, return 0 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment