-
Notifications
You must be signed in to change notification settings - Fork 1
/
lcd.c
56 lines (42 loc) · 974 Bytes
/
lcd.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"
#define SEND(byte) PORTB = byte
#define CLR_RW() PORTC &= ~(1 << PINC1)
#define CLR_RS() PORTC &= ~(1 << PINC2)
#define SET_RS() PORTC |= (1 << PINC2)
#define SET_E() PORTC |= (1 << PINC0)
#define CLR_E() PORTC &= ~(1 << PINC0)
#define CLOCK() SET_E(); SET_E(); CLR_E(); CLR_E(); _delay_ms(10);
void mylcd_init() {
DDRB = 0xFF;
DDRC = (1 << PINC0) | (1 << PINC1) | (1 << PINC2);
_delay_ms(50);
// function set
mylcd_sendcmd(0x38);
// function set again
mylcd_sendcmd(0x38);
// display on/off, cursor
mylcd_sendcmd(0x0C);
// display clear
mylcd_sendcmd(0x01);
// entry mode set
mylcd_sendcmd(0x06);
// cursor home!
mylcd_sendcmd(0x01);
// write D!
//mylcd_senddata('D');
mylcd_senddata('A');
}
void mylcd_sendcmd(uint8_t cmd) {
CLR_RS();
CLR_RW();
SEND(cmd);
CLOCK();
}
void mylcd_senddata(uint8_t data) {
SET_RS();
CLR_RW();
SEND(data);
CLOCK();
}