forked from telamon/utft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HW_AVR.h
196 lines (192 loc) · 3.44 KB
/
HW_AVR.h
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
// *** Hardwarespecific functions ***
void UTFT::LCD_Writ_Bus(char VH,char VL, byte mode)
{
switch (mode)
{
case 1:
if (display_serial_mode==SERIAL_4PIN)
{
if (VH==1)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
}
else
{
if (VH==1)
sbi(P_RS, B_RS);
else
cbi(P_RS, B_RS);
}
if (VL & 0x80)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x40)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x20)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x10)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x08)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x04)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x02)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
if (VL & 0x01)
sbi(P_SDA, B_SDA);
else
cbi(P_SDA, B_SDA);
pulse_low(P_SCL, B_SCL);
break;
case 8:
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
PORTA = VH;
pulse_low(P_WR, B_WR);
PORTA = VL;
pulse_low(P_WR, B_WR);
#elif defined(__AVR_ATmega32U4__)
/*
Pin TFT Leo Uno
-------------------
D0 DB8 PD2 PD0
D1 DB9 PD3 PD1
D2 DB10 PD1 PD2
D3 DB11 PD0 PD3
D4 DB12 PD4 PD4
D5 DB13 PC6 PD5
D6 DB14 PD7 PD6
D7 DB15 PE6 PD7
*/
if(VH & 0x01)
PORTD |= (1<<2);
else
PORTD &= ~(1<<2);
if(VH & 0x02)
PORTD |= (1<<3);
else
PORTD &= ~(1<<3);
if (VH & 0x04)
PORTD |= (1<<1);
else
PORTD &= ~(1<<1);
if (VH & 0x08)
PORTD |= (1<<0);
else
PORTD &= ~(1<<0);
if (VH & 0x10)
PORTD |= (1<<4);
else
PORTD &= ~(1<<4);
if (VH & 0x20)
PORTC |= (1<<6);
else
PORTC &= ~(1<<6);
if (VH & 0x40)
PORTD |= (1<<7);
else
PORTD &= ~(1<<7);
if (VH & 0x80)
PORTE |= (1<<6);
else
PORTE &= ~(1<<6);
pulse_low(P_WR, B_WR);
if(VL & 0x01)
PORTD |= (1<<2);
else
PORTD &= ~(1<<2);
if(VL & 0x02)
PORTD |= (1<<3);
else
PORTD &= ~(1<<3);
if (VL & 0x04)
PORTD |= (1<<1);
else
PORTD &= ~(1<<1);
if (VL & 0x08)
PORTD |= (1<<0);
else
PORTD &= ~(1<<0);
if (VL & 0x10)
PORTD |= (1<<4);
else
PORTD &= ~(1<<4);
if (VL & 0x20)
PORTC |= (1<<6);
else
PORTC &= ~(1<<6);
if (VL & 0x40)
PORTD |= (1<<7);
else
PORTD &= ~(1<<7);
if (VL & 0x80)
PORTE |= (1<<6);
else
PORTE &= ~(1<<6);
pulse_low(P_WR, B_WR);
#else
PORTD = VH;
pulse_low(P_WR, B_WR);
PORTD = VL;
pulse_low(P_WR, B_WR);
#endif
break;
case 16:
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
PORTA = VH;
PORTC = VL;
#else
PORTD = VH;
cport(PORTC, 0xFC);
sport(PORTC, (VL>>6) & 0x03);
PORTB = VL & 0x3F;
#endif
pulse_low(P_WR, B_WR);
break;
}
}
void UTFT::_set_direction_registers(byte mode)
{
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
DDRA = 0xFF;
if (mode==16)
DDRC = 0xFF;
#elif defined(__AVR_ATmega32U4__)
pinMode(0,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
#else
DDRD = 0xFF;
if (mode==16)
{
DDRB |= 0x3F;
DDRC |= 0x03;
}
#endif
}