1 | #define _SUPPRESS_PLIB_WARNING 1
|
2 |
|
3 | #include <p32xxxx.h>
|
4 | #include <stdio.h>
|
5 | #include <stdlib.h>
|
6 | #include <plib.h>
|
7 |
|
8 | //#include <math.h>
|
9 |
|
10 | #include "SPI_ERC240.h"
|
11 |
|
12 | // SYSCLK = 80 MHz (8MHz Crystal / FPLLIDIV * FPLLMUL / FPLLODIV)
|
13 | // PBCLK = 80 MHz (SYSCLK / FPBDIV)
|
14 | // Primary Osc w/PLL (XT+,HS+,EC+PLL)
|
15 | // WDT OFF
|
16 | // Other options are don't care
|
17 | #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
|
18 | #pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1 // Primary Oszillator -> HS: High Speed crystal
|
19 | #define SYS_FREQ (80000000L)
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | int main() {
|
25 |
|
26 | // Configure the device for maximum performance but do not change the PBDIV
|
27 | // Given the options, this function will change the flash wait states, RAM
|
28 | // wait state and enable prefetch cache but will not change the PBDIV.
|
29 | // The PBDIV value is already set via the pragma FPBDIV option above.
|
30 | SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
|
31 |
|
32 | ERC_CS_OUT; // Chipselext Ausgang
|
33 | ERC_RES_OUT; // Reset Ausgang
|
34 | ERC_CD_OUT; // CD Ausgang
|
35 |
|
36 | SpiChannel spiChn=SPI_CHANNEL1; // the SPI channel to use
|
37 |
|
38 | // OpenSPI1(SPI_MODE8_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_LOW | SPI_CKE_OFF, SPI_ENABLE);
|
39 | OpenSPI1(SPI_MODE8_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_LOW | SPI_CKE_ON | SEC_PRESCAL_8_1 | PRI_PRESCAL_64_1, SPI_ENABLE);
|
40 | // OpenSPI1(SPI_MODE8_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_HIGH | SPI_CKE_ON | SEC_PRESCAL_8_1 | PRI_PRESCAL_16_1, SPI_ENABLE);
|
41 | // OpenSPI1(SPI_MODE8_ON | MASTER_ENABLE_ON | CLK_POL_ACTIVE_HIGH | SPI_CKE_OFF | SEC_PRESCAL_8_1 | PRI_PRESCAL_16_1, SPI_ENABLE);
|
42 | // ConfigIntSPI1(SPI_TX_INT_EN | SPI_RX_INT_EN | SPI_FAULT_INT_EN);
|
43 |
|
44 | // spi_init();
|
45 |
|
46 | ERC_CS_1;
|
47 |
|
48 | waitlcd(1000);
|
49 | Initial();
|
50 |
|
51 | waitlcd(1000);
|
52 | Clear_Display();
|
53 | while(1)
|
54 | {
|
55 | Display_Picture(pic240120);
|
56 | show_character('A');
|
57 | Display_Picture(pic240120);
|
58 | Delay(65000);
|
59 | Delay(65000);
|
60 | Write_Instruction(0xA7);//--set inverse display
|
61 | Delay(65000);
|
62 | Delay(65000);
|
63 | Write_Instruction(0xA6);//--set normal display
|
64 |
|
65 | Display_Picture(pic2401201);
|
66 | Delay(65000);
|
67 | Delay(65000);
|
68 | Write_Instruction(0xA7);//--set inverse display
|
69 | Delay(65000);
|
70 | Delay(65000);
|
71 | Write_Instruction(0xA6);//--set normal display
|
72 |
|
73 | Display_Picture(pic2401202);
|
74 | Delay(65000);
|
75 | Delay(65000);
|
76 | Write_Instruction(0xA7);//--set inverse display
|
77 | Delay(65000);
|
78 | Delay(65000);
|
79 | Write_Instruction(0xA6);//--set normal display
|
80 |
|
81 |
|
82 | Clear_Display();
|
83 |
|
84 | Display_Chinese(font);
|
85 | Delay(65000);
|
86 | Delay(65000);
|
87 | Write_Instruction(0xA7);//--set inverse display
|
88 | Delay(65000);
|
89 | Delay(65000);
|
90 | Write_Instruction(0xA6);//--set normal display
|
91 | Display_Chinese_Column(font);
|
92 | Delay(65000);
|
93 | Delay(65000);
|
94 | Write_Instruction(0xA7);//--set inverse display
|
95 | Display_Chinese_Column(font);
|
96 | Delay(65000);
|
97 | Delay(65000);
|
98 | Write_Instruction(0xA6);//--set normal display
|
99 | show_character(character);
|
100 | }
|
101 |
|
102 |
|
103 | // return;
|
104 |
|
105 |
|
106 | SPI_ERC240.c:
|
107 |
|
108 | void Write_Data(unsigned char dat)
|
109 | {
|
110 | ERC_CS_0;
|
111 | ERC_CD_1; // Instruction auf 1 ziehen
|
112 | SPI_Write(dat);
|
113 | ERC_CS_1;
|
114 | return;
|
115 | }
|
116 |
|
117 | void Write_Instruction(unsigned char cmd)
|
118 | {
|
119 | ERC_CS_0;
|
120 | ERC_CD_0; // Instruction auf 0 ziehen
|
121 | SPI_Write(cmd);
|
122 | ERC_CS_1;
|
123 | return;
|
124 | }
|
125 |
|
126 | void Initial(void)
|
127 | {
|
128 | ERC_RES_1;
|
129 | // RST=1;
|
130 | // Delay(200);
|
131 | waitlcd(2000);
|
132 | // RST=0;
|
133 | ERC_RES_0;
|
134 | waitlcd(2000);
|
135 | // Delay(200);
|
136 | // RST=1;
|
137 | ERC_RES_1;
|
138 | // Delay(200);
|
139 | waitlcd(2000);
|
140 | Write_Instruction(0xE2);//system reset
|
141 | // Delay(200);
|
142 | waitlcd(200);
|
143 | Write_Instruction(0x27);// Multiples rate :128 set temperature consenpation
|
144 |
|
145 | Write_Instruction(0xC4);//set LCD mapping control MX=1,MY=0
|
146 |
|
147 | Write_Instruction(0xEA);//set bias:1/12bias
|
148 |
|
149 |
|
150 | Write_Instruction(0x81);//Set Gain and Potentiometer
|
151 | Write_Instruction(0x40|Contrast_level);//Set Gain and Potentiometer xx xxxxxx
|
152 |
|
153 | Write_Instruction(0x2f);//Power Control:internal
|
154 | Write_Instruction(0x40);//Set Start Line
|
155 |
|
156 | Write_Instruction(0xA4);//--set normal display
|
157 | // Write_Instruction(0xA5);//--set all pixel on
|
158 | Write_Instruction(0xA6);//--set normal display
|
159 | // Write_Instruction(0xA7);//--set inverse display
|
160 |
|
161 | Write_Instruction(0x89);//set RAM Address control
|
162 |
|
163 | // Write_Instruction(0x90);//set fixed lines 1001xxxx
|
164 |
|
165 | Write_Instruction(0xB0);//set pageaddress
|
166 |
|
167 |
|
168 |
|
169 | Write_Instruction(0xAf);//set Display Enable
|
170 |
|
171 | }
|
172 |
|
173 | void Clear_Display(void)
|
174 | {
|
175 | unsigned char i,j;
|
176 | for(i=0;i<15;i++)
|
177 | {
|
178 | Set_Page_Address(i);
|
179 | Set_Column_Address(0x00);
|
180 | for(j=0;j<240;j++)
|
181 | {
|
182 | Write_Data(00);
|
183 | }
|
184 | }
|
185 | return;
|
186 | }
|
187 |
|
188 | void Display_Picture(unsigned char pic[])
|
189 | {
|
190 | unsigned char i,j,num=0;
|
191 | for(i=0;i<15;i++)
|
192 | {
|
193 | Set_Page_Address(i);
|
194 | Set_Column_Address(0x00);
|
195 | for(j=0;j<240;j++)
|
196 | {
|
197 | Write_Data(pic[num*240+j]);
|
198 | }
|
199 | num++;
|
200 | }
|
201 | return;
|
202 | }
|
203 |
|
204 |
|
205 | }
|
206 |
|
207 | unsigned char SPI_Write (unsigned char c)
|
208 |
|
209 | {
|
210 |
|
211 | SPI1BUF = c; // send data to slave
|
212 |
|
213 | while (SPI1STATbits.SPIBUSY); // wait until SPI transmission complete
|
214 |
|
215 | return SPI1BUF;
|
216 |
|
217 | }
|