-
Notifications
You must be signed in to change notification settings - Fork 1
/
nokia_6610_lcd.h
175 lines (146 loc) · 5.1 KB
/
nokia_6610_lcd.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
//******************************************************************************
// Nokia 6610 LCD Driver
//
// MSP430G2231
// -----------------
// /|\| |
// | | |
// --|RST |
// | P1.0|-->LED/DIO {0000 0001}
// | P1.6|-->LED/SCK {0100 0000}
// | P1.3|-->S2/CS {0000 1000}
// | P1.4|-->RST {0001 0000}
// -----------------
//
// Nokia 6610 LCD
// ------------------
//(3.3V)VCC|--|VDISPLAY(6) (4)SCLK|--P1.6
//(3.3V)VCC|--|VDIGITAL(1) (3)DIO|--P1.0
// | (5)CS|--P1.3
// 7V--|VLED(10) |
// | (2)RESET|--P1.4
// GND--|LEDGND(9) |
// GND--|GND(8) |
// -------------------
//
// Reference: http://www.sparkfun.com/tutorial/Nokia%206100%20LCD%20Display%20Driver.pdf - James P. Lynch
//
// Dharampal H S
// October 12, 2010
//******************************************************************************
#ifndef NOKIA_6610_LCD_H_
#define NOKIA_6610_LCD_H_
#include <msp430g2231.h>
#include "utils.h"
// LCD Commands (Philips)
#define NOP 0x00
#define SWRESET 0x01 // Software Reset
#define SLEEPIN 0x10 // Sleep out
#define SLEEPOUT 0x11 // Sleep out
#define DALO 0x22 // All pixels off
#define DAL 0x23 // All pixels on
#define SETCON 0x25 // Set Contrast
#define DISPOFF 0x28 // Display Off
#define DISPON 0x29 // Display On
#define MADCTL 0x36 // Memory Access Control
#define COLMOD 0x3A // Pixel format/Color mode
#define INVON 0x21 // Inversion ON
// LCD Data Constants
#define TWELVE_BITS_PER_PIXEL 0x03
#define DEFAULT_LCD_ORIENTATION 0x08
// Other constants
#define DEFAULT_WAIT 10000 // Not in ms, not in sec, not in any time units. Just the number of sheeps to be counted before snapping out :D
void lcd_reset(void)
{
P1OUT &= ~BIT4; // Pull down P1.4 which's tied to LCD's RST
wait(DEFAULT_WAIT);
P1OUT |= BIT4; // Pull back up P1.4 which's tied to LCD's RST
wait(DEFAULT_WAIT);
}
// Assumes serial chip is initialized. Just writes out the byte of data to SPI, starting from the MSB (bit 7) to the LSB (bit 0).
void lcd_serial_write(volatile char byte)
{
volatile int i;
for(i = 7; i >= 0; i--)
{
// 1. Lower the clock
P1OUT &= ~BIT6;
// 2. Set the SDIN/DIO (Serial Data) bit
if(IS_SET(byte, i))
P1OUT |= BIT0; // Turn on DIO
else
P1OUT &= ~BIT0; // Turn off DIO
// 3. Raise the clock. (This is when the serial data is sampled)
P1OUT |= BIT6;
// 4. Wait
wait(DEFAULT_WAIT);
// 5. Lower the clock back (Redundant, but well)
P1OUT &= ~BIT6;
}
}
void lcd_write_command(volatile char command)
{
// Enable serial chip
P1OUT &= ~BIT3; // /CS -> Falling edge enables the Serial chip
// ** In serial communications, SDIN/DIO (Serial Data -> P1.0) is sampled at the rising edge of SCLK (Serial Clock -> P1.6)
// Send the command bit -> LOW to indicate command
// 1. Lower the clock
P1OUT &= ~BIT6;
// 2. Set the SDIN/DIO (Serial Data) bit (to low for command)
P1OUT &= ~BIT0;
// 3. Raise the clock. (This is when the serial data is sampled)
P1OUT |= BIT6;
// 4. Wait
wait(DEFAULT_WAIT);
// 5. Lower the clock back
P1OUT &= ~BIT6;
lcd_serial_write(command);
// Transmission done. Disable the Serial chip.
P1OUT |= BIT3; // /CS -> Falling edge enables the Serial chip
}
void lcd_write_data(volatile char data)
{
// Enable serial chip
P1OUT &= ~BIT3; // /CS -> Falling edge enables the Serial chip
// ** In serial communications, SDIN/DIO (Serial Data -> P1.0) is sampled at the rising edge of SCLK (Serial Clock -> P1.6)
// Send the command bit -> HIGH to indicate data
// 1. Lower the clock
P1OUT &= ~BIT6;
// 2. Set the SDIN/DIO (Serial Data) bit (to high for data)
P1OUT |= BIT0;
// 3. Raise the clock. (This is when the serial data is sampled)
P1OUT |= BIT6;
// 4. Wait
wait(DEFAULT_WAIT);
// 5. Lower the clock back
P1OUT &= ~BIT6;
lcd_serial_write(data);
// Transmission done. Disable the Serial chip.
P1OUT |= BIT3; // /CS -> Falling edge enables the Serial chip
}
void lcd_initialize(void)
{
P1DIR |= 0x59; // Set P1.0, P1.3, P1.4 and P1.6 to output direction (0101 1001) (since they'd be used for sending out signals - CLK/DATA/...)
lcd_reset();
// P1.4 connected to RST
P1OUT |= BIT4; // Keep RST high. Turning RST Low and then back to High resets the LCD.
// P1.3 connected to CS (Chip Select)
P1OUT |= BIT3; // CS -> Select parallel interface or Enable serial chip (Active Low). Falling edge of the pin enables Serial, and rising disables it..
// Exit SLEEPIN
lcd_write_command(SLEEPOUT);
// Invert RGB settings
lcd_write_command(INVON);
// Color interface pixel format
lcd_write_command(COLMOD);
lcd_write_data(TWELVE_BITS_PER_PIXEL);
// Initialize Memory Access Controller for LCD Orientation
lcd_write_command(MADCTL);
lcd_write_data(DEFAULT_LCD_ORIENTATION);
// Initialize LCD Contrast
lcd_write_command(SETCON);
lcd_write_data(0x30);
wait(DEFAULT_WAIT);
// Turn on the display
lcd_write_command(DISPON);
}
#endif /*NOKIA_6610_LCD_H_*/