|
- #include "stm32f10x.h"
- //#include "JPG.h"
- #include "JPG1.h"
- //#include "JPG2.h"
- /*
- 控制線:RS-P3^5; WR-P3^6; RD-P3^7; CS-P1^0; REST-P1^1;
- 數(shù)據(jù)線: DB0-DB7依次連接P0^0-P0^7; DB8-DB15依次連接P2^0-P2^7;
- 觸摸功能連接方式:(不使用觸摸可不連接)
- D_CLK-P1^2; D_CS-P1^3; D_DIN-P1^4; D_OUT-P1^6; D_PENIRQ-P1^7;
- SD卡接線;(不使用觸摸可不連接)
- SD_MISO-P31; SD_SCK-P32; SD_MOSI-P33; SD_CS-P34;
- */
- #define LCD_RS_1 GPIO_SetBits(GPIOB,GPIO_Pin_0)
- #define LCD_RS_0 GPIO_ResetBits(GPIOB,GPIO_Pin_0)
- #define LCD_RW_1 GPIO_SetBits(GPIOB,GPIO_Pin_1)
- #define LCD_RW_0 GPIO_ResetBits(GPIOB,GPIO_Pin_1)
- #define LCD_RD_1 GPIO_SetBits(GPIOE,GPIO_Pin_2)
- #define LCD_RD_0 GPIO_ResetBits(GPIOE,GPIO_Pin_2)
- #define LCD_CS_1 GPIO_SetBits(GPIOE,GPIO_Pin_3)
- #define LCD_CS_0 GPIO_ResetBits(GPIOE,GPIO_Pin_3)
- #define LCD_REST_1 GPIO_SetBits(GPIOE,GPIO_Pin_4)
- #define LCD_REST_0 GPIO_ResetBits(GPIOE,GPIO_Pin_4)
- #define Data GPIOF->ODR
- //#define LCD_DataPortH GPIOF->ODR
- //#define LCD_DataPortL GPIOG->ODR
- void delay_nus(unsigned long n);
- void delay_nms(unsigned long count);
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- /******************************************************
- ** 函數(shù)名:void Lcd_Write_Com( int DH)
- ** 描述 :TFT寫命令
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void Lcd_Write_Com( uint16_t DH) //命令
- {
- LCD_RS_0;
- LCD_CS_0;
- Data=DH;
- LCD_RW_0;
- LCD_RW_1;
- LCD_CS_1;
- }
- /******************************************************
- ** 函數(shù)名:void lcd_write_color(char hh,char ll)
- ** 描述 :TFT寫發(fā)送圖片的高8位數(shù)據(jù)與低8位數(shù)據(jù)的顏色位
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void lcd_write_color(uint16_t hh) //發(fā)送顏色數(shù)據(jù)為提高速度高8位低8位分別傳遞
- {
- LCD_RS_1;
- LCD_CS_0;
- Data=hh;
- LCD_RW_0;
- LCD_RW_1;
- LCD_CS_1;
- }
- /******************************************************
- ** 函數(shù)名:void Lcd_Write_Data(int DH)
- ** 描述 :TFT寫發(fā)送圖片的高8位數(shù)據(jù)與低8位數(shù)據(jù)
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void Lcd_Write_Data(uint16_t DH) //數(shù)據(jù)
- {
- LCD_RS_1;
- LCD_CS_0;
- Data=DH;
- LCD_RW_0;
- LCD_RW_1;
- LCD_CS_1;
- }
- /******************************************************
- ** 函數(shù)名:void Lcd_Write_Com_Data( int com1,int dat1)
- ** 描述 :TFT寫命令數(shù)據(jù)
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void Lcd_Write_Com_Data( uint16_t com1,uint16_t dat1) //命令數(shù)據(jù)一起
- {
- Lcd_Write_Com(com1);
- Lcd_Write_Data(dat1);
- }
- /******************************************************
- ** 函數(shù)名:void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
- ** 描述 :設(shè)置窗口顯示掃描開始地址
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void Address_set(unsigned int x1,unsigned int y1,unsigned int x2,unsigned int y2)
- {
- Lcd_Write_Com_Data(0x0044,(x2<<8)+x1);
- Lcd_Write_Com_Data(0x0045,y1);
- Lcd_Write_Com_Data(0x0046,y2);
- Lcd_Write_Com_Data(0x004e,x1);
- Lcd_Write_Com_Data(0x004f,y1);
- Lcd_Write_Com(0x0022);
- }
- /******************************************************
- ** 函數(shù)名:void main_init(void)
- ** 描述 :TFT控制器初始化配置
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void main_init(void)
- {
- LCD_REST_1;
- delay_nms(5);
- LCD_REST_0;
- delay_nms(10);
- LCD_REST_1;
- LCD_CS_1;
- LCD_RD_1;
- LCD_RW_1;
- delay_nms(20);
- Lcd_Write_Com_Data(0x0000,0x0001); delay_nms(1); //打開晶振
- Lcd_Write_Com_Data(0x0003,0xA8A4); delay_nms(1); //0xA8A4
- Lcd_Write_Com_Data(0x000C,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x000D,0x080C); delay_nms(1);
- Lcd_Write_Com_Data(0x000E,0x2B00); delay_nms(1);
- Lcd_Write_Com_Data(0x001E,0x00B0); delay_nms(1);
- Lcd_Write_Com_Data(0x0001,0x2B3F); delay_nms(1); //驅(qū)動輸出控制320*240 0x6B3F
- Lcd_Write_Com_Data(0x0002,0x0600); delay_nms(1);
- Lcd_Write_Com_Data(0x0010,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0011,0x6070); delay_nms(1); //0x4030 //定義數(shù)據(jù)格式 16位色
- Lcd_Write_Com_Data(0x0005,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0006,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0016,0xEF1C); delay_nms(1);
- Lcd_Write_Com_Data(0x0017,0x0003); delay_nms(1);
- Lcd_Write_Com_Data(0x0007,0x0233); delay_nms(1); //0x0233
- Lcd_Write_Com_Data(0x000B,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x000F,0x0000); delay_nms(1); //掃描開始地址
- Lcd_Write_Com_Data(0x0041,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0042,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0048,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0049,0x013F); delay_nms(1);
- Lcd_Write_Com_Data(0x004A,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x004B,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0044,0xEF00); delay_nms(1);
- Lcd_Write_Com_Data(0x0045,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0046,0x013F); delay_nms(1);
- Lcd_Write_Com_Data(0x0030,0x0707); delay_nms(1);
- Lcd_Write_Com_Data(0x0031,0x0204); delay_nms(1);
- Lcd_Write_Com_Data(0x0032,0x0204); delay_nms(1);
- Lcd_Write_Com_Data(0x0033,0x0502); delay_nms(1);
- Lcd_Write_Com_Data(0x0034,0x0507); delay_nms(1);
- Lcd_Write_Com_Data(0x0035,0x0204); delay_nms(1);
- Lcd_Write_Com_Data(0x0036,0x0204); delay_nms(1);
- Lcd_Write_Com_Data(0x0037,0x0502); delay_nms(1);
- Lcd_Write_Com_Data(0x003A,0x0302); delay_nms(1);
- Lcd_Write_Com_Data(0x003B,0x0302); delay_nms(1);
- Lcd_Write_Com_Data(0x0023,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0024,0x0000); delay_nms(1);
- Lcd_Write_Com_Data(0x0025,0x8000); delay_nms(1);
- Lcd_Write_Com_Data(0x004f,0); //行首址0
- Lcd_Write_Com_Data(0x004e,0); //列首址0
- Lcd_Write_Com(0x0022);
- }
- /******************************************************
- ** 函數(shù)名:void Pant(unsigned int color)
- ** 描述 :TFT初始化清屏顯示
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void Pant(unsigned int color)
- {
- int i,j;
- Address_set(0,0,239,319);
- for(i=0;i<320;i++)
- {
- for (j=0;j<240;j++)
- {
- Lcd_Write_Data(color);
- }
- }
- }
- int main()
- {
- int i;
- uint16_t data=0;
- SystemInit();
- RCC_Configuration();
- GPIO_Configuration();
- main_init(); //tft初始化
- //Pant(0xf800); //紅色
- //Pant(0X07E0); //綠色
- //Pant(0x001f); //藍(lán)色
- Pant(0xffff); //清屏
- delay_nms(10);
- Address_set(0,0,239,319); //設(shè)置圖片掃描的起始位置
- for(i=0;i<76800;i++)
- {
- data=image1[i*2];
- data=data<<8;
- data=data+image1[i*2+1];
- //delay_nms(10);
- lcd_write_color(data); //數(shù)據(jù)的高8位與低8位分別傳送
- // delay_nms(1);
- }
- /*
- for(k=0;k<8;k++)
- {
- for(j=0;j<6;j++)
- {
- Address_set(40*j,40*k,40*j+39,40*k+39); //坐標(biāo)設(shè)置
- for(i=0;i<1600;i++)
- {
- lcd_write_color(image[i*2+1],image[i*2]); //發(fā)送顏色數(shù)據(jù)為提高速度高8位低8位分別傳遞
- }
- }
- }
- */
- while(1);
- }
- /******************************************************
- ** 函數(shù)名:void RCC_Configuration()
- ** 描述 :us延時函數(shù)
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void RCC_Configuration()
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG,ENABLE);
- //RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);
- }
- /******************************************************
- ** 函數(shù)名:void GPIO_Configuration()
- ** 描述 :GPIO端口初始化
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void GPIO_Configuration()
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_All;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOF,&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOG,&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_0|GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOB,&GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin=GPIO_Pin_2|GPIO_Pin_3|GPIO_Pin_4;
- GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
- GPIO_Init(GPIOE,&GPIO_InitStructure);
- }
- /******************************************************
- ** 函數(shù)名:void delay_nus(unsigned long n)
- ** 描述 :us延時函數(shù)
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void delay_nus(unsigned long n)
- {
- unsigned long j;
- while(n--)
- {
- j=8;
- while(j--);
- }
- }
- /******************************************************
- ** 函數(shù)名:void delay_nms(unsigned long n)
- ** 描述 :ms延時函數(shù)
- ** 輸入 : 無
- ** 輸出 :無
- ** 返回 :無
- ******************************************************/
- void delay_nms(unsigned long count) // /* X1ms */
- {
- int i,j;
- for(i=0;i
- for(j=0;j<100;j++);
- }
復(fù)制代碼 |
|