-
Notifications
You must be signed in to change notification settings - Fork 0
/
lcd.c
84 lines (66 loc) · 1.88 KB
/
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//lcd
void lcd_init()
{
delaylcd();
send_command(0x38); //function set, 8 bit, 2 line
send_command(0x0C); //turn display on, cursor off
send_command(0x06); //entry mode, cursor increment and no display shift
send_command(0x01); //clear display
}
void send_command(char command)
{
char value;
DC = 0; //D/C set to command
RW = 1; //R/W starts high
delaylcd();
RW = 0; //set R/W for write
delaylcd();
EN = 1; //enable the chip select
delaylcd();
value = reverse_bits(command); //reverse the bits before sending to port
PORTA = value;
delaylcd();
EN = 0; //enable the chip select
delaylcd();
RW = 1; //R/W starts high
delaylcd();
}
void send_data(char data)
{
char value;
DC = 1; //D/C set to data
RW = 1; //R/W starts high
delaylcd();
RW = 0; //set R/W for write
delaylcd();
EN = 1; //enable the chip select
delaylcd();
value = reverse_bits(data); //reverse the bits before sending to port
PORTA = value;
delaylcd();
EN = 0; //enable the chip select
delaylcd();
RW = 1; //R/W starts high
delaylcd();
}
void send_string(char string[],int length)
{
int i;
for (i = 0; i < length; i++)
{
send_data(string[i]);
}
}
//I designed my board wrong and reversed the data pins, all I'm doing here is reversing the bits before sending it out to the port
char reverse_bits(char value)
{
char reversed = 0;
int i;
for(i=0; i<=7; i++)
{
reversed<<=1;
reversed|=(value&1);
value>>=1;
}
return reversed;
}