ST7920 Testes

Dependencies:   mbed

Revision:
0:d93bec0d412f
Child:
1:08481151e25e
diff -r 000000000000 -r d93bec0d412f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Nov 06 10:58:12 2019 +0000
@@ -0,0 +1,257 @@
+#include "mbed.h"
+#define OFF 0 
+#define ON 1
+#define CURSOR 0b00011100
+
+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);
+
+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() 
+{ 
+    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;
+    
+    // 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;
+    
+    // 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;
+    
+    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);                             //
+    
+//=========== 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
+    
+    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);
+    
+    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);
+    }
+        
+    
+    pc.printf("teste 11 \n\r"); 
+           
+    while(1) 
+    {
+       
+    }
+}