1 | #include <stdio.h>
|
2 | #include <bcm2835.h>
|
3 |
|
4 |
|
5 | #define LS020_RS RPI_GPIO_P1_22
|
6 | #define LS020_RESET RPI_GPIO_P1_18
|
7 | #define LS020_CS RPI_GPIO_P1_26
|
8 |
|
9 |
|
10 | uint16_t init_data[] =
|
11 | {
|
12 | 0xFDFD, 0xFDFD,
|
13 | // pause
|
14 |
|
15 | 0xEF00, 0xEE04, 0x1B04, 0xFEFE, 0xFEFE,
|
16 | 0xEF90, 0x4A04, 0x7F3F, 0xEE04, 0x4306,
|
17 | // pause
|
18 |
|
19 | 0xEF90, 0x0983, 0x0800, 0x0BAF, 0x0A00,
|
20 | 0x0500, 0x0600, 0x0700, 0xEF00, 0xEE0C,
|
21 | 0xEF90, 0x0080, 0xEFB0, 0x4902, 0xEF00,
|
22 | 0x7F01, 0xE181, 0xE202, 0xE276, 0xE183,
|
23 | 0x8001, 0xEF90, 0x0000
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 | inline void setOutput(int pin, int state)
|
29 | {
|
30 | if(state == HIGH)
|
31 | bcm2835_gpio_write(pin,HIGH);
|
32 | else
|
33 | bcm2835_gpio_write(pin, LOW);
|
34 | }
|
35 |
|
36 | void LCD_sendCommand(uint16_t command)
|
37 | {
|
38 | setOutput(LS020_RS, HIGH); //to command mode
|
39 | bcm2835_spi_transfer((command>>8)&&0xff);
|
40 | bcm2835_spi_transfer(command & 0xff);
|
41 | setOutput(LS020_RS, LOW);
|
42 |
|
43 | }
|
44 |
|
45 |
|
46 | void LCD_sendBlockCommand(uint16_t commands[], int len)
|
47 | {
|
48 |
|
49 |
|
50 | setOutput(LS020_RS, HIGH); //to command mode
|
51 | uint8_t * c_p = (uint8_t*) commands;
|
52 | bcm2835_spi_transfern(c_p, len*2);
|
53 | setOutput(LS020_RS, LOW);
|
54 | }
|
55 |
|
56 | int main()
|
57 | {
|
58 |
|
59 |
|
60 |
|
61 | printf("Start LS020 Display test\n");
|
62 | if(!bcm2835_init())
|
63 | {
|
64 | printf("GPIO Init failed\n");
|
65 | return 1;
|
66 | }
|
67 |
|
68 | printf("Start GPIO init\n");
|
69 | bcm2835_gpio_fsel(LS020_RS, BCM2835_GPIO_FSEL_OUTP);
|
70 | bcm2835_gpio_fsel(LS020_RESET, BCM2835_GPIO_FSEL_OUTP);
|
71 | //bcm2835_gpio_fsel(LS020_CS, BCM2835_GPIO_FSEL_OUTP);
|
72 |
|
73 | printf("Start SPI init\n");
|
74 | bcm2835_spi_begin();
|
75 | bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
|
76 | bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
|
77 | bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_32); // 8 MHz
|
78 | bcm2835_spi_chipSelect(BCM2835_SPI_CS2); // The default
|
79 | bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS2, LOW); // the default
|
80 |
|
81 |
|
82 | setOutput(LS020_RS, LOW);
|
83 | setOutput(LS020_RESET, LOW);
|
84 | delay(100);
|
85 | setOutput(LS020_RESET, HIGH);
|
86 |
|
87 | LCD_sendBlockCommand(init_data,2); delay(50);
|
88 | LCD_sendBlockCommand(init_data+2,10); delay(7);
|
89 | LCD_sendBlockCommand(init_data+12,20); //delay(50);
|
90 | LCD_sendBlockCommand(init_data+32,3); delay(50);
|
91 |
|
92 | delay(10000);
|
93 | bcm2835_spi_end();
|
94 |
|
95 | }
|