📄 main.c
字号:
#include <stdlib.h>#include <stdarg.h>#include <string.h>#include "def.h"#include "option.h"#include "2440addr.h"#include "2440lib.h"#include "myTFT.h"#include "color.h"#include "graphic.h"#include "..\images\flower.h"#include "..\images\mouse.h"#include "..\images\test.h"void myTFT_DemoPutpixel(void);void myTFT_DrawBMP(int x, int y, const unsigned char *fp);void myTFT_Box(int x1, int y1, int x2, int y2, int color);int mix=50;int overwrite=1; void Main(void){ int i, index;; ChangeMPllValue(110,3,1); //FCLK=399.65MHz, 1:3:6, HCLK=(1/3)FCLK=133.2MHz Uart_Init(PCLK, 115200); Uart_Select(1); Uart_TxEmpty(1); Uart_Printf("\n\rEx18.Test TFT LCD(640*480) \n"); myTFT_Init(LCDFRAMEBUFFER, LCD_XSIZE, LCD_YSIZE, SCR_XSIZE, SCR_YSIZE); clear_LCD(); for(i=0;i<640*480*2;i+=4) *(volatile int *)(LCDFRAMEBUFFER+i)=0xFFFFFFFF; Uart_Printf("*********************\n"); Uart_Printf("1. Draw Box. \n"); Uart_Printf("2. Draw Bitmap.\n"); Uart_Printf("3. Draw Filled Box.\n"); Uart_Printf("4. Display English Character!\n"); Uart_Printf("*********************\n"); Uart_Printf("Select number!!\n\n "); while(1) { index = Uart_Getch(); switch(index) { case '1' : Uart_Printf("Draw box Test....\n"); for(i=0;i<640*480*2;i+=4) *(volatile int *)(LCDFRAMEBUFFER+i)=0xFFFFFFFF;//clear myTFT_Box(0,0, 319, 239, RED); Delay(1000); myTFT_Box(320,0,640,239, YELLOW); Delay(1000); myTFT_Box(0,239, 319, 479, GREEN); Delay(1000); myTFT_Box(319,239, 639, 479, VIOLET); Delay(1000); break; case '2' : Uart_Printf("Draw bitmap Test....\n"); for(i=0;i<640*480*2;i+=4) *(volatile int *)(LCDFRAMEBUFFER+i)=0xFFFFFFFF;//clear myTFT_DrawBMP(200,100,flower); break; case '3' : // use your function in graphic.c, draw a filled box (30,40,80,100) with color RED //draw_fill_rectangle(30,40,80,100,RED); draw_vline(30, 80, 100, RED); break; case '4': //display character 'Hello World!' from (0,0) display_ascii(0, 0, "Hello World!"); display_chinese(0, 50, "你好!"); break; } } } // end of main(...)int random(int val){ return rand()%val; }void myTFT_DemoPutpixel(void){ int i, j; int seed = 1958; Uart_Printf("\n\rDemo PutPixel/GetPixel \n\r" ); srand(seed); // Restart random # function while( !Uart_GetKey() ) { myTFT_Putpixel(random(LCD_XSIZE-1), random(LCD_YSIZE-1), random(0xFFFF) ); Delay(3); } for(i=0;i<SCR_XSIZE;i++) for(j=0;j<SCR_YSIZE;j++) myTFT_Putpixel(i,j,0x00); }void myTFT_DrawBMP(int x, int y, const unsigned char *fp){ int xx=0, yy=0; unsigned int tmp; unsigned char tmpR, tmpG, tmpB; unsigned short bfType; unsigned int bfSize; unsigned int bfOffbits; unsigned int biWidth, biWidth2; unsigned int biHeight; bfType=*(unsigned short *)(fp+0); bfSize=*(unsigned short *)(fp+2); tmp=*(unsigned short *)(fp+4); bfSize=(tmp<<16)+bfSize; bfOffbits=*(unsigned short *)(fp+10); biWidth=*(unsigned short *)(fp+18); biHeight=*(unsigned short *)(fp+22); biWidth2=(bfSize-bfOffbits)/biHeight; //biWidth2=(biWidth/4)*4;/* Uart_Printf("FileSize : %d \n", bfSize); Uart_Printf("Offset : %d \n", bfOffbits); Uart_Printf("Width : %d \n", biWidth); Uart_Printf("Height : %d \n", biHeight); Uart_Printf("Width2 : %d \n", biWidth2);*/ for(yy=0;yy<biHeight;yy++) { for(xx=0;xx<biWidth2/3;xx++) { tmpB=*(unsigned char *)(fp+bfOffbits+3*xx+(biHeight-yy-1)*biWidth2+0); tmpG=*(unsigned char *)(fp+bfOffbits+3*xx+(biHeight-yy-1)*biWidth2+1); tmpR=*(unsigned char *)(fp+bfOffbits+3*xx+(biHeight-yy-1)*biWidth2+2); if(tmpB==0xff && tmpG==0x00 && tmpR==0x00 && overwrite==0) { } else { tmpR>>=3; tmpG>>=3; tmpB>>=3; if(xx<biWidth2) myTFT_Putpixel(x+xx,y+yy,(tmpR<<11)+(tmpG<<6)+(tmpB<<0)); } } } } // end of Lcd_DrawBMP(...) void myTFT_Box(int x1, int y1, int x2, int y2, int color){ int xx, yy; int r1,g1,b1; int r2,g2,b2; int tmp; for(yy=y1;yy<=y2;yy++) { for(xx=x1;xx<=x2;xx++) { tmp=myTFT_Getpixel(xx, yy); r1=(tmp>>11)&0x1F; g1=(tmp>>5)&0x3F; b1=(tmp>>0)&0x1F; r2=(color>>11)&0x1F; g2=(color>>5)&0x3F; b2=(color>>0)&0x1F; if(mix>100) mix=100; r1=((r1*mix)+(100-mix)*r2)/100; g1=((g1*mix)+(100-mix)*g2)/100; b1=((b1*mix)+(100-mix)*b2)/100; tmp=(r1<<11)|(g1<<5)|(b1); myTFT_Putpixel(xx, yy, tmp); } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -