-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathn1202img.c
151 lines (98 loc) · 2.8 KB
/
n1202img.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
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
/* n1202img --- display an image on the Nokia 1202 LCD 2012-02-22 */
#include <msp430.h>
#include "dorkdemo.h"
#include "popup.h"
#define SDA BIT5
#define SCK BIT7
#define CS BIT4
#define RESET BIT2
#define LCD_DATA 0x100
void n1202init(void);
void n1202clear(void);
void n1202goto(const int row, const int col);
void n1202write(int d);
void dally(const int dally);
int main(void)
{
int i;
int row, col;
WDTCTL = WDTHOLD | WDTPW; // Disable watchdog timer
P1SEL = 0x00; // Set up GPIO pins
P1DIR = SDA | SCK | CS | RESET;
n1202init();
n1202goto(0, 0);
// Display 96x68 pixel image
for (i = 0; i < (9 * 96); i++)
n1202write(LCD_DATA | Dorkdemo[i]);
for (i = 0; i < 100; i++)
dally(10000);
// Display popup image
for (row = 0; row < 4; row++) {
n1202goto(row + 2, (96 - 48) / 2);
for (col = 0; col < 48; col++)
n1202write(LCD_DATA | Popup[(row * 48) + col]);
}
while (1)
;
// Never returns
}
/* n1202init --- initialise the Nokia 1202 LCD (STE2007 controller) */
void n1202init(void)
{
P1OUT |= RESET;
n1202write(0xE2); // Software reset
n1202write(0xA4); // Power saver OFF
n1202write(0x2F); // Power control set
n1202write(0xAF); // Display ON
n1202write(0xC0); // Display common driver normal
n1202write(0x80 | 16); // Electronic volume to 16
n1202clear();
n1202write(0xef); // Set refresh rate
n1202write(3); // 65 Hz
n1202write(0x3d); // Set Charge Pump multiply factor
n1202write(0); // 5x
n1202write(0x36); // Bias ratio 1/4
n1202write(0xad); // set contrast
n1202write(0x20 | 20); // 20/32
n1202write(0xe1);
n1202write(0);
n1202write (0xa6); // Display normal
}
/* n1202clear --- clear the LCD display memory */
void n1202clear(void)
{
int i;
n1202goto(0, 0);
for (i = 0; i < (9 * 96); i++) {
n1202write(LCD_DATA | 0x00);
}
}
/* n1202goto --- move the cursor in the STE2007 to a given row, column */
void n1202goto(const int row, const int col)
{
n1202write(0xB0 | (row & 0x0F)); // Set page address
n1202write(0x10 | (col >> 4)); // Set DDRAM column addr: upper 3-bits
n1202write(0x00 | (col & 0x0F)); // ...lower 4-bits
}
/* n1202write --- write a 9-bit word to the STE2007 via SPI */
void n1202write(int d)
{
unsigned char i;
P1OUT &= ~CS;
for (i = 0; i < 9; i++) {
P1OUT &= ~SDA;
if (d & 0x100)
P1OUT |= SDA;
P1OUT &= ~SCK;
P1OUT |= SCK;
d <<= 1;
}
P1OUT |= CS;
}
/* dally --- rudimentary delay loop */
void dally(const int dally)
{
volatile int i;
for (i = 0; i < dally; i++)
;
}