由於在電路設計時,已經考慮到會使用串列外設介面 (Serial Peripheral Interface,縮寫:SPI)和 I/O 方式,所以要使用 SPI 方式來驅動 NOKIA 5110 PCD8544 LCD 模塊便來得簡單,電路連接是不用改,祇需要更改程式便可以用 SPI 驅動。
PIC24FJ64GA008 NOKIA 5110 LCD 模塊 SPI 電路圖 |
Microchip
PIC24FJ64GA008和 1.6吋 NOKIA 5110 LCD 液晶屏連接:
LCD
|
Signal
|
Description
|
I/O Bus
|
MCU
|
Signal
|
1
|
RST
|
Reset (Active
Low)
|
11
|
76
|
RE0
|
2
|
CE
|
Chip Enable
(Active Low)
|
12
|
77
|
RE1
|
3
|
DC
|
Data/Command Selection
Low – Write Commnad
High – Write Data
|
13
|
78
|
RE2
|
4
|
DIN
|
Serial Data Input
|
19
|
43
|
SDO1/RF8
|
5
|
CLK
|
Serial Clock Input
|
23
|
45
|
SCK1/RF6
|
6
|
VCC
|
2.7 ~ 3.3V
|
1
|
+3.3V
|
|
7
|
BL
|
Backlight
|
15
|
79
|
RE3
|
8
|
GND
|
Ground
|
6
|
GND
|
工作原理:
Philips PCD8544 控制器芯片與 Microchip PIC24FJ64GA008 是採用串列外設介面 (SPI:Serial Peripheral Interface Bus)連接,而 PCD8544 的 I/O 控制已經連接到 8腳的連接器,DIN(Data Input Line - Pin 4)接至 MCU 的 SDO1/RF8(SPI Data Input 1 / RF8 - Pin 43),CLK(SPI Clock Input Line - Pin 5)接至 MCU 的 SCK1/RF6(SPI Clock Output 1 /RF6 - Pin 45),RST(Reset - Pin 1)接至 MCU 的 PMD0/RE0(RE0 - Pin 76),CE(Chip Enable - Pin 2)接至 MCU 的 PMD1/RE1(RE1 - Pin 77),D/C(Data / Command - Pin 3)接至 MCU 的 PMD2/RE2(RE2 - Pin 78),和BL(Backlight Control - Pin 7)接至 MCU 的 PMD3/RE3(RE3 - Pin 79)。由於 SPI是引腳是可以作 SPI 和一般 I/O使用,所以可試驗 SPI 操作。
Microchip PIC24FJ64GA008 PCD8544 LCD 屏接腳 SPI 程式定義:
// Definitions for Reset pin
#define RST_TRIS_BIT TRISEbits.TRISE0
#define RST_LAT_BIT LATEbits.LATE0
// Definitions for CS pin
#define CS_TRIS_BIT TRISEbits.TRISE1
#define CS_LAT_BIT LATEbits.LATE1
// Definitions for RS pin
#define RS_TRIS_BIT TRISEbits.TRISE2
#define RS_LAT_BIT LATEbits.LATE2
// Definitions for Backlight enable pin
#define LED_TRIS_BIT TRISEbits.TRISE3 // Output
#define LED_LAT_BIT LATEbits.LATE3
// Definitions for CLK pin
#define CLK_TRIS_BIT TRISFbits.TRISF6
#define CLK_LAT_BIT LATFbits.LATF6
//Definition for data BUS
#define
DAT_TRIS_BIT TRISFbits.TRISF8
#define
DAT_LAT_BIT LATFbits.LATF8
#define
DAT_PORT_BIT PORTFbits.RF8
|
Microchip PIC24FJ64GA008 PCD8544 LCD 屏 SPI 設置程式:
void configSPI1(void)
{
SPI1CON1bits.DISSDO = 0; // bit11 Disable SDOx 1=not used 0=Used
SPI1CON1bits.MODE16 = 0; // bit10 Word/Byte 1=16bits 0=8bits
SPI1CON1bits.SMP = 0;
// bit19 SPI Data Input Sample Phase 1=End of data 0=Middle of data
SPI1CON1bits.CKE = 0;
// bit8 SPI Clock Edge 1=Transition from Active to Idle
SPI1CON1bits.SSEN = 0;
// bit7 Slave Select Enable 1= SS for Slave 0=not used
SPI1CON1bits.CKP = 0;
// bit6 Clock Polarity 1=Active=Low, 0=Active=High
SPI1CON1bits.MSTEN = 1;
// bit5 1=Master, 0=Slave
SPI1CON1bits.SPRE = 0b111;
// bit2-4 111=1:1 110=2:1
SPI1CON1bits.PPRE = 0b10;
// bit0-1 11=1:1, 10=4:1, 01=16:1, 00=64:1
SPI1CON2=0;
SPI1STATbits.SPIEN = 1; // Bit15 1=Enable
SCK, SDO, SDI, SS
}
|
Microchip PIC24FJ64GA008 PCD8544 LCD 屏初始化程式:
void nokia_init(void)
{
AD1PCFG = 0xFFFF;
_PMPEN = 0;
// Start Reset Device
// Set I/O as Input=1/Output=0
RST_TRIS_BIT = 0; // Reset = Output = 0
CS_TRIS_BIT
= 0; // Chip Select = Output =
0
RS_TRIS_BIT
= 0; // Command/Data = Output =
0
DAT_TRIS_BIT = 0; // Data D0~D7 = Output = 0
CLK_TRIS_BIT = 0; // SCLK = Output = 0
LED_TRIS_BIT = 0; // Backlight LED = Output = 0
// Backlight LED ON
LED_LAT_BIT = 1; // Backlight LED On = 1
RS_LAT_BIT
= 1; // Data/-Command
CS_LAT_BIT
= 0; // Chip Select ON = 0
// Hardward Reset LCD Device
RST_LAT_BIT = 0; // Reset LCD On = 0 >100ms
delayms(250);
CS_LAT_BIT = 1; // Chip Select Off = 1
RST_LAT_BIT = 1; // Reset LCD Off = 1
delayms(200);
nokia_write_command(0x21); // set extended instruction set
nokia_write_command(0xB1); // 0x90 was 0xc2 LCD=;3.06+162*0.06=4.02
nokia_write_command(0x04);
nokia_write_command(0x14); //0x13
bias 1:48 -> n=4
nokia_write_command(0x0C);
//0x13 bias 1:48 -> n=4
nokia_write_command(0x20); // horiz mode Droite, X autoincremente
delayms(150);
nokia_write_command(0x0C);
// mod control normal change
delayms(50);
CS_LAT_BIT = 1; // Chip Select Off = 1
}
|
PIC24FJ64GA008 NOKIA 5110 LCD 模塊 SPI電路試驗 |
2016年 12月 29日 天氣報告
氣溫:16.2度 @ 22:20
相對濕度:百分之 51%
天氣:大致多雲
沒有留言:
張貼留言