Landtiger (LPC1768) graphics LCD demo.

Dependencies:   mbed

Committer:
wim
Date:
Sun Nov 04 18:13:01 2012 +0000
Revision:
1:ea0f7b1c5daf
Parent:
0:a8090b59eb05
Child:
2:43ede88fb5a3
werkende versie, text en bitmap correct

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 0:a8090b59eb05 1 #include "mbed.h"
wim 0:a8090b59eb05 2 #include "GLCD.h"
wim 0:a8090b59eb05 3
wim 0:a8090b59eb05 4 #include "Bg_16bpp_t.h"
wim 0:a8090b59eb05 5 #include "Bg_16bpp_l.h"
wim 0:a8090b59eb05 6 #include "Bg_16bpp_r.h"
wim 0:a8090b59eb05 7 #include "Bg_16bpp_b.h"
wim 0:a8090b59eb05 8 #include "ARM_Ani_16bpp.h"
wim 0:a8090b59eb05 9
wim 0:a8090b59eb05 10 //Host PC Baudrate (Virtual Com Port on USB)
wim 0:a8090b59eb05 11 #define D_BAUDRATE 9600
wim 0:a8090b59eb05 12 //#define D_BAUDRATE 57600
wim 0:a8090b59eb05 13
wim 0:a8090b59eb05 14 //extern unsigned short driverCode;
wim 0:a8090b59eb05 15
wim 0:a8090b59eb05 16 #define LANDTIGER 1
wim 0:a8090b59eb05 17
wim 0:a8090b59eb05 18 // Variables for Heartbeat and Status monitoring
wim 0:a8090b59eb05 19 #ifdef LANDTIGER
wim 0:a8090b59eb05 20 DigitalOut myled1(P2_0);
wim 0:a8090b59eb05 21 DigitalOut myled2(P2_1);
wim 0:a8090b59eb05 22 DigitalOut myled3(P2_2);
wim 0:a8090b59eb05 23 DigitalOut myled4(P2_3);
wim 0:a8090b59eb05 24 DigitalOut myled5(P2_4);
wim 0:a8090b59eb05 25 DigitalOut myled6(P2_5);
wim 0:a8090b59eb05 26 DigitalOut myled7(P2_6);
wim 0:a8090b59eb05 27 DigitalOut myled8(P2_7);
wim 0:a8090b59eb05 28
wim 0:a8090b59eb05 29
wim 0:a8090b59eb05 30 //DigitalOut heartbeatLED(LED4);
wim 0:a8090b59eb05 31 DigitalOut heartbeatLED(P3_26); //SD_PWR, active low
wim 0:a8090b59eb05 32 //DigitalOut USB_Host_Power(P1_19); //USB Power, active low
wim 0:a8090b59eb05 33
wim 0:a8090b59eb05 34 // Need this override function on non-mbed hardware to provide the MAC address.
wim 0:a8090b59eb05 35 //
wim 0:a8090b59eb05 36 // The mbed Ethernet library sets the MAC address by calling a weak function
wim 0:a8090b59eb05 37 // extern "C" void mbed_mac_address(char * mac) to copy in a 6 Byte (12 character) MAC address.
wim 0:a8090b59eb05 38 // This function performs a semihosting request to the mbed interface to get the serial number,
wim 0:a8090b59eb05 39 // which contains a MAC address unique to every mbed device.
wim 0:a8090b59eb05 40 // If you are using the eth library on your own board (i.e. not an mbed board),
wim 0:a8090b59eb05 41 // you should implement your own extern "C" void mbed_mac_address(char * mac) function
wim 0:a8090b59eb05 42 // to overwrite the existing one and avoid a call to the interface (which doesnt exist).
wim 0:a8090b59eb05 43
wim 0:a8090b59eb05 44
wim 0:a8090b59eb05 45 extern "C" void mbed_mac_address(char * mac) {
wim 0:a8090b59eb05 46
wim 0:a8090b59eb05 47 //mbed module clone
wim 0:a8090b59eb05 48 // mac[0] = 0x00;
wim 0:a8090b59eb05 49 // mac[1] = 0x02;
wim 0:a8090b59eb05 50 // mac[2] = 0xF7;
wim 0:a8090b59eb05 51 // mac[3] = 0xF0;
wim 0:a8090b59eb05 52 // mac[4] = 0x56;
wim 0:a8090b59eb05 53 // mac[5] = 0x90;
wim 0:a8090b59eb05 54
wim 0:a8090b59eb05 55 //KPN Experia
wim 0:a8090b59eb05 56 mac[0] = 0x00;
wim 0:a8090b59eb05 57 mac[1] = 0x01;
wim 0:a8090b59eb05 58 mac[2] = 0xE3;
wim 0:a8090b59eb05 59 mac[3] = 0x55;
wim 0:a8090b59eb05 60 mac[4] = 0xA1;
wim 0:a8090b59eb05 61 mac[5] = 0xC7;
wim 0:a8090b59eb05 62
wim 0:a8090b59eb05 63 };
wim 0:a8090b59eb05 64
wim 0:a8090b59eb05 65 #else
wim 0:a8090b59eb05 66 DigitalOut myled1(LED1);
wim 0:a8090b59eb05 67 DigitalOut myled2(LED2);
wim 0:a8090b59eb05 68 DigitalOut myled3(LED3);
wim 0:a8090b59eb05 69 DigitalOut heartbeatLED(LED4);
wim 0:a8090b59eb05 70 #endif
wim 0:a8090b59eb05 71
wim 0:a8090b59eb05 72
wim 0:a8090b59eb05 73 // Host PC Communication channels
wim 0:a8090b59eb05 74 Serial pc(USBTX, USBRX); // tx, rx
wim 0:a8090b59eb05 75
wim 0:a8090b59eb05 76 // Variables for Heartbeat and Status monitoring
wim 0:a8090b59eb05 77 Ticker heartbeat;
wim 0:a8090b59eb05 78 bool heartbeatflag=false;
wim 0:a8090b59eb05 79
wim 0:a8090b59eb05 80 Ticker LCD_Ani;
wim 0:a8090b59eb05 81
wim 0:a8090b59eb05 82 void clear_screen() {
wim 0:a8090b59eb05 83 //ANSI Terminal Commands
wim 0:a8090b59eb05 84 pc.printf("\x1B[2J");
wim 0:a8090b59eb05 85 pc.printf("\x1B[H");
wim 0:a8090b59eb05 86 }
wim 0:a8090b59eb05 87
wim 0:a8090b59eb05 88 void init_interfaces() {
wim 0:a8090b59eb05 89 // Init Host PC communication, default is 9600
wim 0:a8090b59eb05 90 pc.baud(D_BAUDRATE);
wim 0:a8090b59eb05 91
wim 0:a8090b59eb05 92 //Done, Tell me about it
wim 0:a8090b59eb05 93 // show_LEDS();
wim 0:a8090b59eb05 94 }
wim 0:a8090b59eb05 95
wim 0:a8090b59eb05 96
wim 0:a8090b59eb05 97 // Heartbeat monitor
wim 0:a8090b59eb05 98 void pulse() {
wim 0:a8090b59eb05 99 heartbeatLED = !heartbeatLED;
wim 0:a8090b59eb05 100
wim 0:a8090b59eb05 101 #ifdef LANDTIGER
wim 0:a8090b59eb05 102 // myled1 = heartbeatLED;
wim 0:a8090b59eb05 103 // myled2 = heartbeatLED;
wim 0:a8090b59eb05 104 // myled3 = heartbeatLED;
wim 0:a8090b59eb05 105 // myled4 = heartbeatLED;
wim 0:a8090b59eb05 106
wim 0:a8090b59eb05 107 // myled5 = !heartbeatLED;
wim 0:a8090b59eb05 108 // myled6 = !heartbeatLED;
wim 0:a8090b59eb05 109 // myled7 = !heartbeatLED;
wim 0:a8090b59eb05 110 // myled8 = !heartbeatLED;
wim 0:a8090b59eb05 111
wim 0:a8090b59eb05 112 #endif
wim 0:a8090b59eb05 113
wim 0:a8090b59eb05 114 }
wim 0:a8090b59eb05 115
wim 0:a8090b59eb05 116 void heartbeat_start() {
wim 0:a8090b59eb05 117 heartbeatLED = 1;
wim 0:a8090b59eb05 118 heartbeat.attach(&pulse, 0.5);
wim 0:a8090b59eb05 119 }
wim 0:a8090b59eb05 120
wim 0:a8090b59eb05 121 void heartbeat_stop() {
wim 0:a8090b59eb05 122 heartbeat.detach();
wim 0:a8090b59eb05 123 }
wim 0:a8090b59eb05 124
wim 0:a8090b59eb05 125
wim 0:a8090b59eb05 126 // LCD Animation
wim 0:a8090b59eb05 127 void LCD_pulse() {
wim 0:a8090b59eb05 128 static int pic = 0;
wim 0:a8090b59eb05 129
wim 0:a8090b59eb05 130 if (pic++ > 8) pic = 0;
wim 0:a8090b59eb05 131 GLCD_Bmp (99, 99, 120, 45, (unsigned char*) &ARM_Ani_16bpp[pic*(120*45*2)]);
wim 0:a8090b59eb05 132 }
wim 0:a8090b59eb05 133
wim 0:a8090b59eb05 134 void LCD_Ani_start() {
wim 0:a8090b59eb05 135 // LCD_Ani.attach(&LCD_pulse, 0.05);
wim 0:a8090b59eb05 136 LCD_Ani.attach(&LCD_pulse, 0.25);
wim 0:a8090b59eb05 137 }
wim 0:a8090b59eb05 138
wim 0:a8090b59eb05 139 void LCD_Ani_stop() {
wim 0:a8090b59eb05 140 LCD_Ani.detach();
wim 0:a8090b59eb05 141 }
wim 0:a8090b59eb05 142
wim 0:a8090b59eb05 143
wim 0:a8090b59eb05 144
wim 0:a8090b59eb05 145 int main() {
wim 0:a8090b59eb05 146 init_interfaces();
wim 0:a8090b59eb05 147
wim 0:a8090b59eb05 148 heartbeat_start();
wim 0:a8090b59eb05 149
wim 0:a8090b59eb05 150 clear_screen();
wim 0:a8090b59eb05 151
wim 0:a8090b59eb05 152 pc.printf("Hello World!\n\r");
wim 0:a8090b59eb05 153
wim 0:a8090b59eb05 154 GLCD_Init();
wim 0:a8090b59eb05 155 GLCD_Clear(White);
wim 0:a8090b59eb05 156 // GLCD_Clear(Blue);
wim 0:a8090b59eb05 157 // GLCD_Bmp( 0, 0, 320, 69, (unsigned char*) Bg_16bpp_t+70);
wim 0:a8090b59eb05 158 // GLCD_Bmp( 0, 69, 4, 102, (unsigned char*) Bg_16bpp_l+70);
wim 0:a8090b59eb05 159 // GLCD_Bmp(316, 69, 4, 102, (unsigned char*) Bg_16bpp_r+70);
wim 0:a8090b59eb05 160 // GLCD_Bmp( 0, 171, 320, 69, (unsigned char*) Bg_16bpp_b+70);
wim 0:a8090b59eb05 161 // GLCD_Bmp( 0, 171, 320, 69, (unsigned char*) Bg_16bpp_t+70);
wim 0:a8090b59eb05 162
wim 0:a8090b59eb05 163 GLCD_SetTextColor (Red);
wim 0:a8090b59eb05 164 GLCD_SetBackColor (White);
wim 1:ea0f7b1c5daf 165 GLCD_DisplayString (8, 1, (unsigned char*) "Hi Willem");
wim 0:a8090b59eb05 166
wim 0:a8090b59eb05 167 LCD_Ani_start();
wim 0:a8090b59eb05 168
wim 1:ea0f7b1c5daf 169 GLCD_drawRect (10, 10, 100, 100);
wim 0:a8090b59eb05 170
wim 0:a8090b59eb05 171 GLCD_SetTextColor (Green);
wim 1:ea0f7b1c5daf 172 GLCD_drawHLine (20, 20, 50);
wim 0:a8090b59eb05 173 GLCD_drawVLine (30, 30, 50);
wim 0:a8090b59eb05 174
wim 0:a8090b59eb05 175 pc.printf("LCD Controller ID = 0x%04X\n\r", GLCD_DriverCode());
wim 0:a8090b59eb05 176
wim 0:a8090b59eb05 177 while(1) {
wim 0:a8090b59eb05 178 pc.printf("+");
wim 0:a8090b59eb05 179
wim 0:a8090b59eb05 180 wait(0.1);
wim 0:a8090b59eb05 181 };
wim 0:a8090b59eb05 182
wim 0:a8090b59eb05 183 pc.printf("Bye World!\n\r");
wim 0:a8090b59eb05 184 }