STM32设计,里面各种外设
立即下载
资源介绍:
STM32设计,里面各种外设
#include "tftlcd.h"
#include "stdlib.h"
#include "font.h"
#include "usart.h"
#include "Sys_Tick.h"
//LCD的画笔颜色和背景色
u16 FRONT_COLOR=GREEN; //画笔颜色
u16 BACK_COLOR=WHITE; //背景色
_tftlcd_data tftlcd_data;
//写寄存器函数
//cmd:寄存器值
void LCD_WriteCmd(u16 cmd)
{
#ifdef TFTLCD_HX8357D
TFTLCD->LCD_CMD=cmd;//写入要写的寄存器序号
#endif
#ifdef TFTLCD_HX8357DN
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_R61509V
TFTLCD->LCD_CMD=cmd;//写入要写的寄存器序号
#endif
#ifdef TFTLCD_R61509VN
TFTLCD->LCD_CMD=(cmd>>8)<<1;
TFTLCD->LCD_CMD=(cmd&0xff)<<1;
#endif
#ifdef TFTLCD_R61509V3
TFTLCD->LCD_CMD=cmd;//写入要写的寄存器序号
#endif
#ifdef TFTLCD_HX8352C
TFTLCD->LCD_CMD=cmd<<8;
#endif
#ifdef TFTLCD_ILI9341
TFTLCD->LCD_CMD=cmd<<8;
#endif
#ifdef TFTLCD_ILI9327
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_ILI9325
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_ILI9486
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_ST7793
TFTLCD->LCD_CMD=cmd>>8;
TFTLCD->LCD_CMD=cmd&0xff;
#endif
#ifdef TFTLCD_SSD1963
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_NT35510
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_ILI9481
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_R61509VE
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_SSD1963N
TFTLCD->LCD_CMD=cmd;
#endif
#ifdef TFTLCD_ILI9488
TFTLCD->LCD_CMD=cmd;
#endif
}
//写数据
//data:要写入的值
void LCD_WriteData(u16 data)
{
#ifdef TFTLCD_HX8357D
TFTLCD->LCD_DATA=data;//写入要写的寄存器序号
#endif
#ifdef TFTLCD_HX8357DN
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_R61509V
TFTLCD->LCD_DATA=data;//写入要写的寄存器序号
#endif
#ifdef TFTLCD_R61509VN
TFTLCD->LCD_DATA=(data>>8)<<1;
TFTLCD->LCD_DATA=(data&0xff)<<1;
#endif
#ifdef TFTLCD_R61509V3
TFTLCD->LCD_DATA=data;//写入要写的寄存器序号
#endif
#ifdef TFTLCD_HX8352C
TFTLCD->LCD_DATA=data<<8;
#endif
#ifdef TFTLCD_ILI9341
TFTLCD->LCD_DATA=data<<8;
#endif
#ifdef TFTLCD_ILI9327
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_ILI9325
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_ILI9486
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_ST7793
TFTLCD->LCD_DATA=data>>8;
TFTLCD->LCD_DATA=data&0xff;
#endif
#ifdef TFTLCD_SSD1963
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_NT35510
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_ILI9481
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_R61509VE
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_SSD1963N
TFTLCD->LCD_DATA=data;
#endif
#ifdef TFTLCD_ILI9488
TFTLCD->LCD_DATA=data;
#endif
}
void LCD_WriteCmdData(u16 cmd,u16 data)
{
LCD_WriteCmd(cmd);
LCD_WriteData(data);
}
u32 LCD_RGBColor_Change(u16 color)
{
u8 r,g,b=0;
r=(color>>11)&0x1f;
g=(color>>5)&0x3f;
b=color&0x1f;
return ((r<<13)|(g<<6)|(b<<1));
}
void LCD_WriteData_Color(u16 color)
{
#ifdef TFTLCD_HX8357D
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_HX8357DN
TFTLCD->LCD_DATA=color>>8;
TFTLCD->LCD_DATA=color&0xff;
#endif
#ifdef TFTLCD_R61509V
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_R61509VN
u32 recolor=0;
recolor=LCD_RGBColor_Change(color);
TFTLCD->LCD_DATA=(recolor>>9);
TFTLCD->LCD_DATA=recolor;
#endif
#ifdef TFTLCD_R61509V3
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_HX8352C
TFTLCD->LCD_DATA=color&0xff00;
TFTLCD->LCD_DATA=color<<8;
#endif
#ifdef TFTLCD_ILI9341
TFTLCD->LCD_DATA=color&0xff00;
TFTLCD->LCD_DATA=color<<8;
#endif
#ifdef TFTLCD_ILI9327
TFTLCD->LCD_DATA=color>>8;
TFTLCD->LCD_DATA=color&0xff;
#endif
#ifdef TFTLCD_ILI9325
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_ILI9486
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_ST7793
TFTLCD->LCD_DATA=color>>8;
TFTLCD->LCD_DATA=color&0xff;
#endif
#ifdef TFTLCD_SSD1963
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_NT35510
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_ILI9481
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_R61509VE
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_SSD1963N
TFTLCD->LCD_DATA=color;
#endif
#ifdef TFTLCD_ILI9488
TFTLCD->LCD_DATA=color>>8;
TFTLCD->LCD_DATA=color&0xff;
#endif
}
//读数据
//返回值:读到的值
u16 LCD_ReadData(void)
{
#ifdef TFTLCD_HX8357D
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_HX8357DN
// u16 ram1,ram2;
// ram1=TFTLCD->LCD_DATA;
// printf("ram1=%x ",ram1);
// ram2=TFTLCD->LCD_DATA;
// printf("ram2=%x \r\n",ram2);
// ram2=ram2<<8|ram1;
// return ram2;
return TFTLCD->LCD_DATA;
// return ((TFTLCD->LCD_DATA<<8)|(TFTLCD->LCD_DATA));
#endif
#ifdef TFTLCD_R61509V
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_R61509VN
// return TFTLCD->LCD_DATA;
u16 ram;
ram=(TFTLCD->LCD_DATA)>>1;
ram=ram<<8;
ram|=(TFTLCD->LCD_DATA)>>1;
return ram;
#endif
#ifdef TFTLCD_R61509V3
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_HX8352C
return ((TFTLCD->LCD_DATA<<8)|(TFTLCD->LCD_DATA));
#endif
#ifdef TFTLCD_ILI9341
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_ILI9327
u16 ram;
ram=TFTLCD->LCD_DATA;
ram=ram<<8;
ram|=TFTLCD->LCD_DATA;
return ram;
#endif
#ifdef TFTLCD_ILI9325
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_ILI9486
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_ST7793
u16 ram;
ram=TFTLCD->LCD_DATA;
ram=ram<<8;
ram|=TFTLCD->LCD_DATA;
return ram;
#endif
#ifdef TFTLCD_SSD1963
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_NT35510
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_ILI9481
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_R61509VE
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_SSD1963N
return TFTLCD->LCD_DATA;
#endif
#ifdef TFTLCD_ILI9488
u16 ram;
ram=TFTLCD->LCD_DATA;
ram=ram<<8;
ram|=TFTLCD->LCD_DATA;
return ram;
#endif
}
//设置LCD显示方向
//dir:0,竖屏;1,横屏
void LCD_Display_Dir(u8 dir)
{
tftlcd_data.dir=dir; //横屏/竖屏
if(dir==0) //默认竖屏方向
{
#ifdef TFTLCD_HX8357D
LCD_WriteCmd(0x36); //设置彩屏显示方向的寄存器
LCD_WriteData(0x4c);
tftlcd_data.height=480;
tftlcd_data.width=320;
#endif
#ifdef TFTLCD_HX8357DN
LCD_WriteCmd(0x36); //设置彩屏显示方向的寄存器
LCD_WriteData(0x4c);
tftlcd_data.height=480;
tftlcd_data.width=320;
#endif
#ifdef TFTLCD_R61509V
LCD_WriteCmd(0x0001);
LCD_WriteData(0x0100);
LCD_WriteCmd(0x0003);
LCD_WriteData(0x1030);
tftlcd_data.height=400;
tftlcd_data.width=240;
#endif
#ifdef TFTLCD_R61509VN
LCD_WriteCmd(0x0001);
LCD_WriteData(0x0100);
LCD_WriteCmd(0x0003);
LCD_WriteData(0x1030);
tftlcd_data.height=400;
tftlcd_data.width=240;
#endif
#ifdef TFTLCD_R61509V3
LCD_WriteCmd(0x0001);
LCD_WriteData(0x0100);
LCD_WriteCmd(0x0003);
LCD_WriteData(0x1030);
tftlcd_data.height=400;
tftlcd_data.width=240;
#endif
#ifdef TFTLCD_HX8352C
LCD_WriteCmd(0x36); //设置彩屏显示方向的寄存器
LCD_WriteData(0x03); //03:U-D,L-R; 06:D-U,R-L;
tftlcd_data.height=400;
tftlcd_data.width=240;
#endif
#ifdef TFTLCD_ILI9341
LCD_WriteCmd(0x36); //设置彩屏显示方向的寄存器
LCD_WriteData(0x08);
tftlcd_data.height=320;
tftlcd_data.width=240;
#endif
#ifdef TFTLCD_ILI9327
LCD_WriteCmd(0x36); //设置彩屏显示方向的寄存器
LCD_WriteData(0x48);
tftlcd_data.height=400;
tftlcd_data.width=240;
#endif
#ifdef TFTLCD_ILI9325
LCD_WriteCmd(0x0001);
LCD_WriteData(0x0100);
LCD_WriteCmd(0x0003); //设置彩屏显示方向的寄存器
LCD_WriteData(0x1030);
tftlcd_data.height=320;
tftlcd_data.width=240;
#endif
#ifdef TFTLCD_ILI9486
LCD_WriteCmd(0x36); //设置彩屏显示方向的寄存器
LCD_WriteData(0x00);
tftlcd_data.height=480;
tftlcd_data.width=320;
#endif
#ifdef TFTLCD_ST7793
LCD_WriteCmd(0x0001);
LCD_WriteData(0x0100);
LCD_WriteCmd(0x00
资源文件列表:
32 design.zip 大约有375个文件