Marcelo Costanzo Miranda
/
ST7920_TEST_sem_lib_2
ST7920 Testes
Diff: main.cpp
- Revision:
- 1:08481151e25e
- Parent:
- 0:d93bec0d412f
- Child:
- 2:5bcfb7105fa2
--- a/main.cpp Wed Nov 06 10:58:12 2019 +0000 +++ b/main.cpp Mon Dec 14 19:10:22 2020 +0000 @@ -1,257 +1,53 @@ -#include "mbed.h" -#define OFF 0 -#define ON 1 -#define CURSOR 0b00011100 +/* +* ATENÇÃO ST7920_CLEAR DESATIVA O MODO GRÁFICO +* +* +*/ -BusOut DB(D5, D6, D7, D8, D9, D10, D11, D12); // DB0 - DB7 RESPECTIVAMENTE -//BusOut DB(D12, D11, D10, D9, D8, D7, D6, D5); // DB7 - DB0 RESPECTIVAMENTE - -DigitalOut RS(D2); -DigitalOut RW(D3); -DigitalOut EN(D4); +#include "mbed.h" +#include "ST7920.h" Serial pc(USBTX, USBRX); - -//imagem 11x9 trator -unsigned char trator[]={ -0x00, 0x00, 0x1E, 0x00, 0x92, 0x00, 0x92, 0x00, -0xFE, 0x03, 0xFB, 0x07, 0xF1, 0x03, 0x9B, 0x02, -0x8E, 0x03}; - int main() { + unsigned char texto[]={'O','l','a','!', ' ', 'S', 'T', '7', '9', '2', '0'}; pc.printf("OI \n\r"); - wait_ms(100); - - //function set 8-bit mode - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0b00110000; - wait_us(100); - EN = OFF; - //function set 8-bit mode again - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0b00110000; - wait_us(100); - EN = OFF; - - // display on - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0b00001100; - wait_us(100); - EN = OFF; - - // cursor - Display shift right by 1, cursor also follows to shift. - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0b00011100; - wait_us(100); - EN = OFF; + ST7920_Init(); + wait_ms(100); - // clear screen - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0b00000001; - wait_us(2000); - EN = OFF; - - // Returns to home. Cursor moves to starting point - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0b00000010; - wait_us(100); - EN = OFF; + //ST7920_Clear(); + //wait_ms(100); - // Setting location to write characters. In this case 0,0 - Top Left Corner - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0x80; - wait_us(100); - EN = OFF; + //ST7920_SetGraphicsMode(); + //wait_ms(100); - wait(2); - - // Extended instuction set, 8bit // - wait_us(1000); // - RS = 0; // - RW = 0; // - wait_us(100); // - EN = ON; // - DB = 0b00110100; // - wait_us(100); // - EN = OFF; // - wait_us(20); // - //-----> set graphics mode - // Repeat instrution with bit1 set // - wait_us(1000); // - RS = 0; // - RW = 0; // - wait_us(100); // - EN = ON; // - DB = 0b00110110; // - wait_us(100); // - EN = OFF; // - wait_us(20); // + //ST7920_Clear(); + //wait_ms(100); + + //ST7920_SetGraphicsMode(); -//=========== This function set all the pixels to off in the graphic controller ================= - for(int y = 0; y < 64; y++) - { - if(y < 32) - { - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = (0x80 | y); - wait_us(100); - EN = OFF; - wait_us(100); - - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0x80; - wait_us(100); - EN = OFF; - wait_us(100); - } - - else - { - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = (0x80 | (y - 32)); - wait_us(100); - EN = OFF; - wait_us(100); - - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0x88; - wait_us(100); - EN = OFF; - wait_us(100); - } - - for(int x = 0; x < 16; x++) - { - wait_us(1000); - RS = 1; - RW = 0; - wait_us(100); - EN = ON; - DB = 0x00; - wait_us(100); - EN = OFF; - wait_us(20); - } - } - - - //desenhando uma linha de tamanho T em Y, com X offset + //ST7920_Clear(); + + //ST7920_DrawHorizontalLine(0, 0, 100); + //wait_ms(100); + + //ST7920_DrawVerticalLine(0, 0, 50); + //wait_ms(100); - unsigned char X = 0; // 0 até 7 - unsigned char Y = 0; // 0 até 31 - unsigned int T = 5; // 1 até 256 - - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0x80 | Y; - wait_us(100); - EN = OFF; - wait_us(100); - - wait_us(1000); - RS = 0; - RW = 0; - wait_us(100); - EN = ON; - DB = 0x80 | X; - wait_us(100); - EN = OFF; - wait_us(100); + //ST7920_SetTextMode(); + //wait_ms(100); - for(int i = 0; i < (T / 8); i++) - { - wait_us(1000); - RS = 1; - RW = 0; - wait_us(100); - EN = ON; - DB = (255); - wait_us(100); - EN = OFF; - wait_us(20); - } - - if(T%8 != 0) - { - int T_rest = T - ((T / 8) * 8); - int bus_rest; - - switch (T_rest) - { - case 1: bus_rest = 0x80; break; - case 2: bus_rest = 0xC0; break; - case 3: bus_rest = 0xE0; break; - case 4: bus_rest = 0xF0; break; - case 5: bus_rest = 0xF8; break; - case 6: bus_rest = 0xFC; break; - case 7: bus_rest = 0xFE; break; - } - pc.printf("%x\n\r",bus_rest); - wait_us(1000); - RS = 1; - RW = 0; - wait_us(100); - EN = ON; - DB = bus_rest; // tem que ser 254 no exemplo de T 255 - wait_us(100); - EN = OFF; - wait_us(20); - } - + ST7920_Clear(); + //wait_ms(100); - pc.printf("teste 11 \n\r"); - + ST7920_DisplayString(1, 1, texto, sizeof(texto)); + //wait_ms(100); + while(1) { } } +