funcionando

Dependencies:   EPD_GDE021A1 mbed reScale

Fork of DISCO-L053C8_ePD_demo by ST

Committer:
Marcelocostanzo
Date:
Tue Oct 23 18:07:57 2018 +0000
Revision:
6:f36e6f7b67a1
Parent:
5:03c1a5788923
Funcionando o epaper como lcd20x4

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Marcelocostanzo 3:9229fd269ed0 1 /*Código escrito por Marcelo Costanzo Miranda
Marcelocostanzo 3:9229fd269ed0 2 *Projeto feito conforme pedido do professor Silvio Szafir
Marcelocostanzo 3:9229fd269ed0 3 *
Marcelocostanzo 6:f36e6f7b67a1 4 * Placa ST discovery com display ePaper funcionando como LCD 20x4
Marcelocostanzo 3:9229fd269ed0 5 *
Marcelocostanzo 3:9229fd269ed0 6 * São Paulo, SP
Marcelocostanzo 3:9229fd269ed0 7 * 30 de agosto de 2018
Marcelocostanzo 3:9229fd269ed0 8 *
Marcelocostanzo 3:9229fd269ed0 9 */
Marcelocostanzo 3:9229fd269ed0 10
bcostm 0:e5732175b08b 11 #include "mbed.h"
bcostm 0:e5732175b08b 12 #include "EPD_GDE021A1.h"
Marcelocostanzo 3:9229fd269ed0 13
Marcelocostanzo 3:9229fd269ed0 14
bcostm 0:e5732175b08b 15
bcostm 0:e5732175b08b 16 #define EPD_CS PA_15
bcostm 0:e5732175b08b 17 #define EPD_DC PB_11
bcostm 0:e5732175b08b 18 #define EPD_RESET PB_2
bcostm 0:e5732175b08b 19 #define EPD_BUSY PA_8
bcostm 0:e5732175b08b 20 #define EPD_POWER PB_10
bcostm 0:e5732175b08b 21 #define EPD_SPI_MOSI PB_5
bcostm 0:e5732175b08b 22 #define EPD_SPI_MISO PB_4
bcostm 0:e5732175b08b 23 #define EPD_SPI_SCK PB_3
bcostm 0:e5732175b08b 24
bcostm 0:e5732175b08b 25 EPD_GDE021A1 epd(EPD_CS, EPD_DC, EPD_RESET, EPD_BUSY, EPD_POWER, EPD_SPI_MOSI, EPD_SPI_MISO, EPD_SPI_SCK);
bcostm 0:e5732175b08b 26
bcostm 0:e5732175b08b 27 DigitalOut led1(LED1);
Marcelocostanzo 3:9229fd269ed0 28 DigitalIn button(PA_0);
Marcelocostanzo 3:9229fd269ed0 29 Ticker flipper;
Marcelocostanzo 3:9229fd269ed0 30 Serial pc(USBTX, USBRX); // tx, rx
bcostm 0:e5732175b08b 31
bcostm 0:e5732175b08b 32 //width 48
bcostm 0:e5732175b08b 33 //height 26
Marcelocostanzo 3:9229fd269ed0 34
bcostm 0:e5732175b08b 35 static uint8_t Battery_img[] = {
bcostm 0:e5732175b08b 36 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 37 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 38 0xfe, 0xff, 0xff, 0xff, 0xff, 0x0f,
bcostm 0:e5732175b08b 39 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x0c,
bcostm 0:e5732175b08b 40 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 41 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 42 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 43 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 44 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x18,
bcostm 0:e5732175b08b 45 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 46 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 47 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 48 0xfe, 0xff, 0xff, 0x3f, 0xff, 0x39,
bcostm 0:e5732175b08b 49 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 50 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 51 0xfe, 0xff, 0xff, 0x3f, 0x10, 0x38,
bcostm 0:e5732175b08b 52 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x38,
bcostm 0:e5732175b08b 53 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x18,
bcostm 0:e5732175b08b 54 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 55 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 56 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x08,
bcostm 0:e5732175b08b 57 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x0c,
bcostm 0:e5732175b08b 58 0xfe, 0xff, 0xff, 0x3f, 0x00, 0x0c,
bcostm 0:e5732175b08b 59 0xfe, 0xff, 0xff, 0xff, 0xff, 0x0f,
bcostm 0:e5732175b08b 60 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 61 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
bcostm 0:e5732175b08b 62 };
bcostm 0:e5732175b08b 63
Marcelocostanzo 6:f36e6f7b67a1 64 void flip()
Marcelocostanzo 3:9229fd269ed0 65 {
Marcelocostanzo 3:9229fd269ed0 66 led1=!led1;
Marcelocostanzo 3:9229fd269ed0 67 }
Marcelocostanzo 3:9229fd269ed0 68
Marcelocostanzo 5:03c1a5788923 69 uint16_t x=0, y=0, i=0;
Marcelocostanzo 5:03c1a5788923 70 char c, c1, c2;
Marcelocostanzo 3:9229fd269ed0 71 char s[100];
Marcelocostanzo 5:03c1a5788923 72
Marcelocostanzo 5:03c1a5788923 73
bcostm 0:e5732175b08b 74 int main()
bcostm 0:e5732175b08b 75 {
Marcelocostanzo 3:9229fd269ed0 76
Marcelocostanzo 3:9229fd269ed0 77 flipper.attach(&flip, 0.1);//interrupção para piscar o led, debug para saber se o uC travou
bcostm 0:e5732175b08b 78
Marcelocostanzo 3:9229fd269ed0 79
Marcelocostanzo 3:9229fd269ed0 80 //mensagens de boas vindas
bcostm 0:e5732175b08b 81 epd.Clear(EPD_COLOR_WHITE);
bcostm 0:e5732175b08b 82 epd.DisplayStringAtLine(5, (uint8_t*)"MBED", CENTER_MODE);
bcostm 0:e5732175b08b 83 epd.DisplayStringAtLine(3, (uint8_t*)"Epaper display", LEFT_MODE);
bcostm 0:e5732175b08b 84 epd.DisplayStringAtLine(2, (uint8_t*)"demo", LEFT_MODE);
bcostm 0:e5732175b08b 85 epd.DrawImage(130, 0, 48, 26, Battery_img);
bcostm 0:e5732175b08b 86 epd.DrawRect(50, 4, 60, 4);
bcostm 0:e5732175b08b 87 epd.RefreshDisplay();
Marcelocostanzo 3:9229fd269ed0 88 wait(1);
Marcelocostanzo 3:9229fd269ed0 89 epd.Clear(EPD_COLOR_WHITE);
Marcelocostanzo 3:9229fd269ed0 90 epd.RefreshDisplay();
Marcelocostanzo 3:9229fd269ed0 91 epd.Clear(EPD_COLOR_WHITE);
Marcelocostanzo 3:9229fd269ed0 92
Marcelocostanzo 3:9229fd269ed0 93
Marcelocostanzo 5:03c1a5788923 94 epd.SetFont(&Font16);
Marcelocostanzo 3:9229fd269ed0 95 while(1)
Marcelocostanzo 3:9229fd269ed0 96 {
Marcelocostanzo 5:03c1a5788923 97
Marcelocostanzo 5:03c1a5788923 98 //----------ROTINA PARA ESCREVER NO EPAPER------------------------
Marcelocostanzo 3:9229fd269ed0 99
Marcelocostanzo 5:03c1a5788923 100 pc.printf("\nEscolha a linha Y, de 0 a 3:");
Marcelocostanzo 5:03c1a5788923 101 c = pc.getc();
Marcelocostanzo 5:03c1a5788923 102 switch (c)
Marcelocostanzo 5:03c1a5788923 103 {
Marcelocostanzo 5:03c1a5788923 104 case '3': y = 0;break;
Marcelocostanzo 5:03c1a5788923 105 case '2': y = 4;break;
Marcelocostanzo 5:03c1a5788923 106 case '1': y = 8;break;
Marcelocostanzo 5:03c1a5788923 107 case '0': y = 12;break;
Marcelocostanzo 5:03c1a5788923 108 }
Marcelocostanzo 5:03c1a5788923 109 pc.printf("\n%u",y);
Marcelocostanzo 3:9229fd269ed0 110
Marcelocostanzo 5:03c1a5788923 111 pc.printf("\nEscolha a coluna X, de 00 a 19:");
Marcelocostanzo 5:03c1a5788923 112 c1 = pc.getc();
Marcelocostanzo 5:03c1a5788923 113 c2 = pc.getc();
Marcelocostanzo 5:03c1a5788923 114 switch (c2)
Marcelocostanzo 4:38ce0cfb14e2 115 {
Marcelocostanzo 5:03c1a5788923 116 case '0': x = 0;break;
Marcelocostanzo 5:03c1a5788923 117 case '1': x = 1;break;
Marcelocostanzo 5:03c1a5788923 118 case '2': x = 2;break;
Marcelocostanzo 5:03c1a5788923 119 case '3': x = 3;break;
Marcelocostanzo 5:03c1a5788923 120 case '4': x = 4;break;
Marcelocostanzo 5:03c1a5788923 121 case '5': x = 5;break;
Marcelocostanzo 5:03c1a5788923 122 case '6': x = 6;break;
Marcelocostanzo 5:03c1a5788923 123 case '7': x = 7;break;
Marcelocostanzo 5:03c1a5788923 124 case '8': x = 8;break;
Marcelocostanzo 5:03c1a5788923 125 case '9': x = 9;break;
Marcelocostanzo 5:03c1a5788923 126 }
Marcelocostanzo 5:03c1a5788923 127
Marcelocostanzo 5:03c1a5788923 128 switch (c1)
Marcelocostanzo 5:03c1a5788923 129 {
Marcelocostanzo 5:03c1a5788923 130 case '0': x = x + 0;break;
Marcelocostanzo 5:03c1a5788923 131 case '1': x = x + 10;break;
Marcelocostanzo 5:03c1a5788923 132
Marcelocostanzo 5:03c1a5788923 133 }
Marcelocostanzo 5:03c1a5788923 134
Marcelocostanzo 5:03c1a5788923 135 x = x * 10;
Marcelocostanzo 5:03c1a5788923 136 pc.printf("\n%u",x);
Marcelocostanzo 4:38ce0cfb14e2 137
Marcelocostanzo 5:03c1a5788923 138 pc.printf("\nEntre com seu texto (com # no final):");
Marcelocostanzo 4:38ce0cfb14e2 139
Marcelocostanzo 3:9229fd269ed0 140 do
Marcelocostanzo 3:9229fd269ed0 141 {
Marcelocostanzo 3:9229fd269ed0 142 c = pc.getc();
Marcelocostanzo 3:9229fd269ed0 143 s[i] = c;
Marcelocostanzo 3:9229fd269ed0 144 ++i;
Marcelocostanzo 3:9229fd269ed0 145 }
Marcelocostanzo 6:f36e6f7b67a1 146 while(c!='#'); //entra em loop, coletando os caracteres até achar o #, e então sai do loop
Marcelocostanzo 3:9229fd269ed0 147
Marcelocostanzo 3:9229fd269ed0 148 s[i-1] = '\0'; //elimina o caracter terminador de strings
Marcelocostanzo 3:9229fd269ed0 149 pc.printf("%s", s);
Marcelocostanzo 5:03c1a5788923 150 for(int o = 0; o < i - 1; o++)
Marcelocostanzo 5:03c1a5788923 151 {
Marcelocostanzo 5:03c1a5788923 152 epd.DisplayChar(x, y,s[o]);
Marcelocostanzo 5:03c1a5788923 153 x = x + 10;
Marcelocostanzo 5:03c1a5788923 154 }
Marcelocostanzo 3:9229fd269ed0 155 epd.RefreshDisplay();
Marcelocostanzo 3:9229fd269ed0 156 i=0;
Marcelocostanzo 3:9229fd269ed0 157
Marcelocostanzo 5:03c1a5788923 158 //FIM DA ROTINA PARA ESCREVER NO EPAPER
Marcelocostanzo 3:9229fd269ed0 159
Marcelocostanzo 3:9229fd269ed0 160 }//FIM DA WHILE
Marcelocostanzo 3:9229fd269ed0 161 }//FIM DO PROGRAMA