AVR驱动TFT(内含颜色设置)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

AVR128驱动2.4寸TFT(主控芯片ILI9325)单片机2010-08-2903:46:53阅读139评论0字号:大中小订阅1、原理图:AVR128与TFT最小系统原理图。2、程序/************************************/*lcd.c************************************/#includelcd.hintmain(void){InitIO();/*IO口初始化*/ILI9325_Initial();/*LCD初始化*/ClearScreen(0xFFFF);/*清屏*///LCD_SetPos(0,0,239,319);while(1){Pant(0xf800,0,240,0,40);//红色Pant(0X07E0,0,240,40,80);//绿色Pant(0x001f,0,240,80,120);//蓝色Pant(0xf800,0,240,120,160);//红色Pant(0X07E0,0,240,160,200);//绿色Pant(0x001f,0,240,200,240);//蓝色Pant(0xf800,0,240,240,280);//红色Pant(0X07E0,0,240,280,320);//绿色delayms(1000);delayms(1000);ClearScreen(0xFFFF);Pant(0xf800,0,240,0,320);//红色delayms(1000);delayms(1000);ClearScreen(0xFFFF);Pant(0X07E0,0,240,0,320);//绿色delayms(1000);delayms(1000);ClearScreen(0xFFFF);Pant(0x001f,0,240,0,320);//蓝色delayms(1000);delayms(1000);ClearScreen(0xFFFF);}return1;}/************************************/*lcd.h************************************//*********************包含文件*************************/#includeavr/io.h#includeutil/delay.h#includeavr/pgmspace.h/*********************类型定义*************************/typedefunsignedcharuint8;typedefunsignedintuint16;typedefunsignedlonguint32;#defineWINDOW_XADDR_START0x0050//HorizontalStartAddressSet#defineWINDOW_XADDR_END0x0051//HorizontalEndAddressSet#defineWINDOW_YADDR_START0x0052//VerticalStartAddressSet#defineWINDOW_YADDR_END0x0053//VerticalEndAddressSet#defineGRAM_XADDR0x0020//GRAMHorizontalAddressSet#defineGRAM_YADDR0x0021//GRAMVerticalAddressSet#defineGRAMWR0x0022//memorywrite#define_nop_()asm(NOP)#defineLCD_RS_DDRDDRG//数据/命令切换#defineLCD_RS_PORTPORTG#defineLCD_RS_BIT2#defineLCD_CS_DDRDDRG//片选#defineLCD_CS_PORTPORTG#defineLCD_CS_BIT3#defineLCD_WR_DDRDDRG//写控制#defineLCD_WR_PORTPORTG#defineLCD_WR_BIT0#defineLCD_RD_DDRDDRG//读控制#defineLCD_RD_PORTPORTG#defineLCD_RD_BIT1#defineLCD_RST_DDRDDRG//复位#defineLCD_RST_PORTPORTG#defineLCD_RST_BIT4#defineLCD_CS_HLCD_CS_PORT|=1LCD_CS_BIT#defineLCD_CS_LLCD_CS_PORT&=~(1LCD_CS_BIT)//SCE#defineLCD_RS_HLCD_RS_PORT|=1LCD_RS_BIT#defineLCD_RS_LLCD_RS_PORT&=~(1LCD_RS_BIT)//A0#defineLCD_RST_HLCD_RST_PORT|=1LCD_RST_BIT#defineLCD_RST_LLCD_RST_PORT&=~(1LCD_RST_BIT)//RST#defineLCD_WR_HLCD_WR_PORT|=1LCD_WR_BIT#defineLCD_WR_LLCD_WR_PORT&=~(1LCD_WR_BIT)#defineLCD_RD_HLCD_RD_PORT|=1LCD_RD_BIT#defineLCD_RD_LLCD_RD_PORT&=~(1LCD_RD_BIT)#defineComCtrlPORTG#defineComCtrlDDRDDRG#defineDataHPORTC#defineDataLPORTA#defineDataDDRHDDRC#defineDataDDRLDDRA/****************************************************************************作者:jundg函数名:voidInitIO(void)函数功能:IO口初始化函数参数:无返回值:无********************************************************************************/voidInitIO(void){ComCtrlDDR=0x1f;DataDDRH=0xff;DataDDRL=0xff;DataH=0xff;DataL=0xff;ComCtrl=0x1f;}/****************************************************************************作者:jundg函数名:voiddelayms(unsignedintcount)函数功能:延时函数函数参数:时间值返回值:无********************************************************************************/voiddelayms(unsignedintcount){inti,j;for(i=0;icount;i++){for(j=0;j260;j++);}}/****************************************************************************作者:jundg函数名:voidWrite_Cmd(unsignedcharDH,unsignedcharDL)函数功能:写命令函数参数:16bitCOM返回值:无********************************************************************************/voidWrite_Cmd(unsignedcharDH,unsignedcharDL){LCD_CS_L;LCD_RS_L;DataH=DH;LCD_WR_L;LCD_WR_H;DataL=DL;LCD_WR_L;LCD_WR_H;LCD_CS_H;}/****************************************************************************作者:jundg函数名:voidWrite_Data(unsignedcharDH,unsignedcharDL)函数功能:写数据函数参数:16bitDATA返回值:无********************************************************************************/voidWrite_Data(unsignedcharDH,unsignedcharDL){LCD_CS_L;LCD_RS_H;DataH=DH;LCD_WR_L;LCD_WR_H;DataL=DL;LCD_WR_L;LCD_WR_H;LCD_CS_H;}/****************************************************************************作者:jundg函数名:voidWrite_Cmd_Data(unsignedcharx,unsignedinty)函数功能:写命令、数据函数参数:8bitCOM、8bitDATA返回值:无********************************************************************************/voidWrite_Cmd_Data(unsignedcharx,unsignedinty){unsignedcharm,n;m=y8;n=y;Write_Cmd(0x00,x);Write_Data(m,n);}/****************************************************************************作者:jundg函数名:staticvoidLCD_SetPos(unsignedintx0,unsignedintx1,unsignedinty0,unsignedinty1)函数功能:设置显示区域函数参数:x0行起始点,x1行结束点,y0列起始点,y1列结束点返回值:无********************************************************************************/staticvoidLCD_SetPos(unsignedintx0,unsignedintx1,unsignedinty0,unsignedinty1){Write_Cmd_Data(WINDOW_XADDR_START,x0);Write_Cmd_Data(WINDOW_XADDR_END,x1);Write_Cmd_Data(WINDOW_YADDR_START,y0);Write_Cmd_Data(WINDOW_YADDR_END,y1);Write_Cmd_Data(GRAM_XADDR,x0);Write_Cmd_Data(GRAM_YADDR,y0);Write_Cmd(0x00,0x22);//LCD_WriteCMD(GRAMWR);}/****************************************************************************作者:jundg函数名:voidPant(intdcolor,unsignedintx0,unsignedintx1,unsignedinty0,unsignedinty1)函数功能:设置显示区域并显示颜色函数参数:dcolor颜色值,x0行起始点,x1行结束点,y0列起始点,y1列结束点返回值:无***********

1 / 10
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功