forked from lgeek/Arduino-Color-LCD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLowLevel.cpp
More file actions
85 lines (68 loc) · 2.02 KB
/
LowLevel.cpp
File metadata and controls
85 lines (68 loc) · 2.02 KB
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
/*
This file is part of Arduino-Color-LCD, an Arduino library for driving
Nokia 132x132 color displays, including the "Knock-Off color LCD"
from SparkFun.
Version 0.1.1. Created by Cosmin Gorgovan <cosmin AT linux-geek.org>,
December 28, 2009
Home page: http://www2.cs.man.ac.uk/~gorgovc9/arduino.html
Arduino-Color-LCD is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Arduino-Color-LCD is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Arduino-Color-LCD. If not, see <http://www.gnu.org/licenses/>.
*/
#include "WProgram.h"
#include "ColorLCD.h"
// Outputs a bit with the logical value of (byte & mask)
#define bitout(byte, mask) \
cbi(PORT, CLK); \
if (mask & b)\
sbi(PORT, SDA);\
else\
cbi(PORT, SDA);\
sbi(PORT, CLK);\
// Software serial output (MSB first)
void ColorLCD::softwareSerialByteOut(byte b)
{
// All this could be done in a for loop
// But this way, it is about 40 % faster
bitout(b, 128);
bitout(b, 64);
bitout(b, 32);
bitout(b, 16);
bitout(b, 8);
bitout(b, 4);
bitout(b, 2);
bitout(b, 1);
}
// Select the LCD (CS line low)
void ColorLCD::select()
{
cbi(PORT, CS);
}
// Unselect the LCD (CS line high)
void ColorLCD::unselect()
{
sbi(PORT, CS);
}
// Sends a 1 bit followed by the 8 bits of data (data byte)
void ColorLCD::sendData(byte data)
{
cbi(PORT, CLK);
sbi(PORT, SDA);
sbi(PORT, CLK);
softwareSerialByteOut(data);
}
// Sends a 0 bit followed by the 8 bits of data (command byte)
void ColorLCD::sendCommand(byte command)
{
cbi(PORT, CLK);
cbi(PORT, SDA);
sbi(PORT, CLK);
softwareSerialByteOut(command);
}