Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <c8051f340.h>
- #include <math.h>
- #include <stdlib.h>
- #include "time.h"
- #include "TFT.h"
- void OSCILLATOR_Init (void);
- void main(void)
- {
- int i;
- byte buf[126];
- int x, x2;
- int y, y2;
- int r;
- PCA0MD &= ~0x40; // Watchdog tajmer iskljucen
- OSCILLATOR_Init(); // Inicijalizacija oscilatora (Fosc = 22.1184 MHz)
- TIME_Init(); // Inicijalizacija sistemskog vremena (koristi se prekid tajmera 2)
- TFT_Init(); // Inicijalizacija displeja
- while(1)
- {
- TFT_clrScr();
- TFT_setColor(255, 0, 0);
- TFT_fillRect(0, 0, 127, 12);
- TFT_setColor(64, 64, 64);
- TFT_fillRect(0,117,127,127);
- TFT_setColor(255, 255, 255);
- TFT_setBackColor(255,0,0);
- TFT_print("TFT 1.44\" DEMO", CENTER, 0, 0);
- TFT_setBackColor(64,64,64);
- TFT_setColor(255,255,0);
- TFT_print("C8051F340", CENTER, 116, 0);
- TFT_setColor(0,255,0);
- TFT_drawRect(0,13,127,116);
- // Draw crosshairs
- TFT_setColor(0,0,255);
- TFT_drawLine(63,14,63,115);
- TFT_drawLine(1,63,126,63);
- for (i=3; i<128; i+=10)
- TFT_drawLine(i, 61, i, 65);
- for (i=14; i<118; i+=10)
- TFT_drawLine(61, i, 65, i);
- // Draw sin-, cos- and tan-lines
- TFT_setColor(0,255,255);
- TFT_setBackColor(0,0,0);
- TFT_print("Sin", 2, 14 ,0);
- for (i=1; i<126; i++)
- {
- TFT_drawPixel(i,63+(sin(((i*2.85)*3.14)/180)*45));
- }
- TFT_setColor(255,0,0);
- TFT_print("Cos", 2, 26, 0);
- for (i=1; i<126; i++)
- {
- TFT_drawPixel(i,63+(cos(((i*2.85)*3.14)/180)*45));
- }
- TFT_setColor(255,255,0);
- TFT_print("Tan", 2, 38, 0);
- for (i=1; i<126; i++)
- {
- TFT_drawPixel(i,63+(tan(((i*2.85)*3.14)/180)));
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- TFT_setColor(0,0,255);
- TFT_drawLine(63,14,63,115);
- TFT_drawLine(1,63,126,63);
- // Draw a moving sinewave
- x=1;
- for (i=1; i<3654; i++)
- {
- x++;
- if (x==127)
- x=1;
- if (i>127)
- {
- if ((x==63)||(buf[x-1]==63))
- TFT_setColor(0,0,255);
- else
- TFT_setColor(0,0,0);
- TFT_drawPixel(x,buf[x-1]);
- }
- TFT_setColor(0,255,255);
- y=63+(sin(((i*1.3)*3.14)/180)*45);
- TFT_drawPixel(x,y);
- buf[x-1]=y;
- delay_ms(3);
- }
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some filled rectangles
- for (i=1; i<6; i++)
- {
- switch (i)
- {
- case 1:
- TFT_setColor(255,0,255);
- break;
- case 2:
- TFT_setColor(255,0,0);
- break;
- case 3:
- TFT_setColor(0,255,0);
- break;
- case 4:
- TFT_setColor(0,0,255);
- break;
- case 5:
- TFT_setColor(255,255,0);
- break;
- }
- TFT_fillRect(10+(i*10),10+(i*10), 60+(i*10), 60+(i*10));
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some filled, rounded rectangles
- for (i=1; i<6; i++)
- {
- switch (i)
- {
- case 1:
- TFT_setColor(255,0,255);
- break;
- case 2:
- TFT_setColor(255,0,0);
- break;
- case 3:
- TFT_setColor(0,255,0);
- break;
- case 4:
- TFT_setColor(0,0,255);
- break;
- case 5:
- TFT_setColor(255,255,0);
- break;
- }
- TFT_fillRoundRect(70-(i*10),10+(i*10), 120-(i*10), 60+(i*10));
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some filled circles
- for (i=1; i<6; i++)
- {
- switch (i)
- {
- case 1:
- TFT_setColor(255,0,255);
- break;
- case 2:
- TFT_setColor(255,0,0);
- break;
- case 3:
- TFT_setColor(0,255,0);
- break;
- case 4:
- TFT_setColor(0,0,255);
- break;
- case 5:
- TFT_setColor(255,255,0);
- break;
- }
- TFT_fillCircle(30+(i*10),35+(i*10), 25);
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some lines in a pattern
- TFT_setColor (255,0,0);
- for (i=11; i<115; i+=3)
- {
- TFT_drawLine(1, i, i-10, 115);
- }
- TFT_setColor (255,0,0);
- for (i=112; i>14; i-=3)
- {
- TFT_drawLine(126, i, i+14, 14);
- }
- TFT_setColor (0,255,255);
- for (i=115; i>14; i-=3)
- {
- TFT_drawLine(1, i, 116-i, 14);
- }
- TFT_setColor (0,255,255);
- for (i=14; i<115; i+=3)
- {
- TFT_drawLine(126, i, 140-i, 115);
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some random circles
- for (i=0; i<100; i++)
- {
- TFT_setColor(rand() % 255, rand() % 255, rand() % 255);
- x=22+rand() % 85;
- y=35+rand() % 59;
- r=rand() % 20;
- TFT_drawCircle(x, y, r);
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some random rectangles
- for (i=0; i<100; i++)
- {
- TFT_setColor(rand() % 255, rand() % 255, rand() % 255);
- x=2+rand() % 124;
- y=15+rand() % 101;
- x2=2+rand() % 124;
- y2=15+rand() % 101;
- TFT_drawRect(x, y, x2, y2);
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some random rounded rectangles
- for (i=0; i<100; i++)
- {
- TFT_setColor(rand() % 255, rand() % 255, rand() % 255);
- x=2+rand() % 124;
- y=15+rand() % 101;
- x2=2+rand() % 124;
- y2=15+rand() % 101;
- TFT_drawRoundRect(x, y, x2, y2);
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some random lines
- for (i=0; i<100; i++)
- {
- TFT_setColor(rand() % 255, rand() % 255, rand() % 255);
- x=2+rand() % 124;
- y=15+rand() % 101;
- x2=2+rand() % 124;
- y2=15+rand() % 101;
- TFT_drawLine(x, y, x2, y2);
- }
- delay_ms(2000);
- TFT_setColor(0,0,0);
- TFT_fillRect(1,14,126,115);
- // Draw some random pixels
- for (i=0; i<5000; i++)
- {
- TFT_setColor(rand() % 255, rand() % 255, rand() % 255);
- TFT_drawPixel(2+rand() % 124, 15+rand() % 101);
- }
- delay_ms(2000);
- //Set up the "Finished"-screen
- TFT_fillScr(0,0,255);
- TFT_setColor(255,0,0);
- TFT_fillRoundRect(2, 40, 125, 88);
- TFT_setColor(255,255,255);
- TFT_setBackColor(255,0,0);
- TFT_print("That's it!", CENTER, 46, 0);
- TFT_print("Restarting in a", CENTER, 66, 0);
- TFT_print("few seconds...", CENTER, 76, 0);
- TFT_setColor(0,0,0);
- TFT_setBackColor(0,0,255);
- TFT_print("Runtime: (msecs)", CENTER, 108, 0);
- TFT_printNumI(millis(), CENTER, 118, 0, ' ');
- delay_ms(2000);
- }
- }
Add Comment
Please, Sign In to add comment