1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/********************************************************************************************************
- FB-EDU-PARM-LPC2138 User Function file - - Author: yelx - - Date: 2018-06-04 - - Guangzhou Windway ********************************************************************************************************/ /**************************************************************************** * 文件名:LCDTEST.C * 功能:显示图像,显示汉字,显示字符 ****************************************************************************/ #include "Config.h" #include "Target.h" #include "iolpc2134.h" #define RED 0XF800 #define GREEN 0X07E0 #define BLUE 0X001F #define WHITE 0XFFFF #define LCD_MOSI (1<<6) #define LCD_MISO (1<<5) #define cs (1<<2) #define sck (1<<4) #define dc (1<<3) #define rst (1<<1) /*---------------延时子程序----------------*/ void delay (uint16 us) { while(us--); } void delay_ms (uint16 ms) { uint16 i,j; for(i=0;i ; } /* unsigned char qufan(unsigned char k) { unsigned char a,b,c,d,e,f,g,h; a=k&0x01;a<<7; b=k&0x02;b<<5; c=k&0x04;c<<3; d=k&0x08;d<<1; e=k&0x10;e>>1; f=k&0x20;f>>3; g=k&0x40;g>>5; h=k&0x80;h>>7; k=(((((((a|b)|c)|d)|e)|f)|g)|h); return k; } */ unsigned char SPI_RW(unsigned char byte) { unsigned char bit_ctr; for(bit_ctr=0;bit_ctr<8;bit_ctr++) { IO0CLR=sck; //qufan(byte); IO0PIN=(IO0PIN&0XFFFFFFFE|byte); byte=(byte<<1); IO0SET=sck; byte|=LCD_MISO; } return byte; } void LCD_CD_DATA(unsigned char val) { IO0CLR=cs; IO0SET=dc; SPI_RW(val); IO0SET=cs; } void LCD_CD_REG(unsigned char reg) { IO0CLR=cs; IO0CLR=dc; SPI_RW(reg); IO0SET=cs; } void LCD_Init() { IO0CLR=rst; delay_ms(50); IO0SET=rst; delay_ms(120); LCD_CD_REG(0xCF); LCD_CD_DATA(0x00); LCD_CD_DATA(0xC1); LCD_CD_DATA(0X30); LCD_CD_REG(0xED); LCD_CD_DATA(0x64); LCD_CD_DATA(0x03); LCD_CD_DATA(0X12); LCD_CD_DATA(0X81); LCD_CD_REG(0xE8); LCD_CD_DATA(0x85); LCD_CD_DATA(0x10); LCD_CD_DATA(0x7A); LCD_CD_REG(0xCB); LCD_CD_DATA(0x39); LCD_CD_DATA(0x2C); LCD_CD_DATA(0x00); LCD_CD_DATA(0x34); LCD_CD_DATA(0x02); LCD_CD_REG(0xF7); LCD_CD_DATA(0x20); LCD_CD_REG(0xEA); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_REG(0xC0); //Power control LCD_CD_DATA(0x1B); //VRH[5:0] LCD_CD_REG(0xC1); //Power control LCD_CD_DATA(0x01); //SAP[2:0];BT[3:0] LCD_CD_REG(0xC5); //VCM control LCD_CD_DATA(0x30); //3F LCD_CD_DATA(0x30); //3C LCD_CD_REG(0xC7); //VCM control2 LCD_CD_DATA(0XB7); LCD_CD_REG(0x36); // Memory Access Control LCD_CD_DATA(0x48); LCD_CD_REG(0x3A); LCD_CD_DATA(0x55); LCD_CD_REG(0xB1); LCD_CD_DATA(0x00); LCD_CD_DATA(0x1A); LCD_CD_REG(0xB6); // Display Function Control LCD_CD_DATA(0x0A); LCD_CD_DATA(0xA2); LCD_CD_REG(0xF2); // 3Gamma Function Disable LCD_CD_DATA(0x00); LCD_CD_REG(0x26); //Gamma curve selected LCD_CD_DATA(0x01); LCD_CD_REG(0xE0); //Set Gamma LCD_CD_DATA(0x0F); LCD_CD_DATA(0x2A); LCD_CD_DATA(0x28); LCD_CD_DATA(0x08); LCD_CD_DATA(0x0E); LCD_CD_DATA(0x08); LCD_CD_DATA(0x54); LCD_CD_DATA(0XA9); LCD_CD_DATA(0x43); LCD_CD_DATA(0x0A); LCD_CD_DATA(0x0F); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_REG(0XE1); //Set Gamma LCD_CD_DATA(0x00); LCD_CD_DATA(0x15); LCD_CD_DATA(0x17); LCD_CD_DATA(0x07); LCD_CD_DATA(0x11); LCD_CD_DATA(0x06); LCD_CD_DATA(0x2B); LCD_CD_DATA(0x56); LCD_CD_DATA(0x3C); LCD_CD_DATA(0x05); LCD_CD_DATA(0x10); LCD_CD_DATA(0x0F); LCD_CD_DATA(0x3F); LCD_CD_DATA(0x3F); LCD_CD_DATA(0x0F); LCD_CD_REG(0x2B); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x01); LCD_CD_DATA(0x3f); LCD_CD_REG(0x2A); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0xef); LCD_CD_REG(0x11); //Exit Sleep delay_ms(120); LCD_CD_REG(0x29); //display on } void LCD_SetArea(unsigned int stx,unsigned int sty,unsigned int endx,unsigned int endy) { LCD_CD_REG(0x2A); LCD_CD_DATA(stx>>8); LCD_CD_DATA(stx&0xff); LCD_CD_DATA(endx>>8); LCD_CD_DATA(endx&0xff); LCD_CD_REG(0x2B); LCD_CD_DATA(sty>>8); LCD_CD_DATA(sty&0xff); LCD_CD_DATA(endy>>8); LCD_CD_DATA(endy&0xff); } void LcdWirteColorData(unsigned int color) { IO0CLR=cs; IO0SET=dc; SPI_RW(color>>8); SPI_RW(color); IO0SET=cs; } void LCD_Clear(unsigned int color) { unsigned int i,j; LCD_SetArea(0,0,239,319); LCD_CD_REG(0x2C); for(i=0;i<320;i++) { for(j=0;j<240;j++) { LcdWirteColorData(color); } } } void main() { TargetResetInit(); PINSEL0 = 0x00000000; // 设置PIN0为GPIO PINSEL1 = 0x00000000; // 设置PIN1为GPIO IO0DIR = 0xfffffffF; delay_ms(100); //spi_init(); LCD_Init(); while(1) { LCD_Clear(RED); delay_ms(300); LCD_Clear(BLUE); delay_ms(300); LCD_Clear(GREEN); delay_ms(300); } } |
|
|
|
怀疑是数据输出上出问题i
|
|
|
|
具体什么问题呢?
|
|
|
|
|
|
|
|
|
|
|
|
目前时序正常但是显示屏黑屏,目测初始化程序有问题
|
|
|
|
/****************************************************************************
* 文件名:SPIDISP.C * 功能:使用硬件SPI接口输出显示。(硬件:TFT ILI9341显示) ****************************************************************************/ #include "Config.h" #include "Target.h" #define RED 0XF800 #define GREEN 0X07E0 #define BLUE 0X001F #define YELLOW 0XFFE0 #define WHITE 0XFFFF #define ssel0 (1<<7) #define LCD_MOSI (1<<6) #define LCD_MISO (1<<5) #define sck (1<<4) #define dc (1<<3) #define cs (1<<2) /*---------------延时子程序----------------*/ void delay_ms(uint32 dly) { uint32 i; for(; dly>0; dly--) for(i=0; i<9000; i++); } /**************************************************************************** * 名称:MSpiIni() * 功能:初始化SPI接口,设置为主机。 * 入口参数:无 * 出口参数:无 ****************************************************************************/ void MSpiInit(void) { S0SPCCR = 0x52; // 设置SPI时钟分频82 S0SPCR = 0x30; // 设置SPI接口模式,MSTR=1 主模式,CPOL=1 SCK低有效, //CPHA=0 SCK第一个时钟沿采样,LSBF=0 位7在先 ,SPIE=0 中断被禁止 } /**************************************************************************** * 名称:SPI_RW() * 功能:向SPI总线发送数据。 * 入口参数:data 待发送的数据 * 出口参数:返回值为读取的数据 ****************************************************************************/ uint8 SPI_RW(uint8 data) { uint8 temp = S0SPDR; S0SPDR = data; while( 0==(S0SPSR&0x80) ); // 等待SPIF置位,即等待数据发送完毕 return(S0SPDR); } void LCD_CD_DATA(unsigned char val) { IO0SET=dc; IO0CLR=cs; SPI_RW(val); IO0SET=cs; } void LCD_CD_REG(unsigned char reg) { IO0CLR=dc; IO0CLR=cs; SPI_RW(reg); IO0SET=cs; } void LCD_Init() { LCD_CD_REG(0xCF); LCD_CD_DATA(0x00); LCD_CD_DATA(0xC1); LCD_CD_DATA(0X30); LCD_CD_REG(0xED); LCD_CD_DATA(0x64); LCD_CD_DATA(0x03); LCD_CD_DATA(0X12); LCD_CD_DATA(0X81); LCD_CD_REG(0xE8); LCD_CD_DATA(0x85); LCD_CD_DATA(0x10); LCD_CD_DATA(0x7A); LCD_CD_REG(0xCB); LCD_CD_DATA(0x39); LCD_CD_DATA(0x2C); LCD_CD_DATA(0x00); LCD_CD_DATA(0x34); LCD_CD_DATA(0x02); LCD_CD_REG(0xF7); LCD_CD_DATA(0x20); LCD_CD_REG(0xEA); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_REG(0xC0); //Power control LCD_CD_DATA(0x1B); //VRH[5:0] LCD_CD_REG(0xC1); //Power control LCD_CD_DATA(0x01); //SAP[2:0];BT[3:0] LCD_CD_REG(0xC5); //VCM control LCD_CD_DATA(0x30); //3F LCD_CD_DATA(0x30); //3C LCD_CD_REG(0xC7); //VCM control2 LCD_CD_DATA(0XB7); LCD_CD_REG(0x36); // Memory Access Control LCD_CD_DATA(0x48); LCD_CD_REG(0x3A); LCD_CD_DATA(0x55); LCD_CD_REG(0xB1); LCD_CD_DATA(0x00); LCD_CD_DATA(0x1A); LCD_CD_REG(0xB6); // Display Function Control LCD_CD_DATA(0x0A); LCD_CD_DATA(0xA2); LCD_CD_REG(0xF2); // 3Gamma Function Disable LCD_CD_DATA(0x00); LCD_CD_REG(0x26); //Gamma curve selected LCD_CD_DATA(0x01); LCD_CD_REG(0xE0); //Set Gamma LCD_CD_DATA(0x0F); LCD_CD_DATA(0x2A); LCD_CD_DATA(0x28); LCD_CD_DATA(0x08); LCD_CD_DATA(0x0E); LCD_CD_DATA(0x08); LCD_CD_DATA(0x54); LCD_CD_DATA(0XA9); LCD_CD_DATA(0x43); LCD_CD_DATA(0x0A); LCD_CD_DATA(0x0F); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_REG(0XE1); //Set Gamma LCD_CD_DATA(0x00); LCD_CD_DATA(0x15); LCD_CD_DATA(0x17); LCD_CD_DATA(0x07); LCD_CD_DATA(0x11); LCD_CD_DATA(0x06); LCD_CD_DATA(0x2B); LCD_CD_DATA(0x56); LCD_CD_DATA(0x3C); LCD_CD_DATA(0x05); LCD_CD_DATA(0x10); LCD_CD_DATA(0x0F); LCD_CD_DATA(0x3F); LCD_CD_DATA(0x3F); LCD_CD_DATA(0x0F); LCD_CD_REG(0x2B); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x01); LCD_CD_DATA(0x3f); LCD_CD_REG(0x2A); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0x00); LCD_CD_DATA(0xef); LCD_CD_REG(0x11); //Exit Sleep delay_ms(120); LCD_CD_REG(0x29); //display on } void LCD_SetArea(unsigned int stx,unsigned int sty,unsigned int endx,unsigned int endy) { LCD_CD_REG(0x2A); LCD_CD_DATA(stx>>8); LCD_CD_DATA(stx&0xff); LCD_CD_DATA(endx>>8); LCD_CD_DATA(endx&0xff); LCD_CD_REG(0x2B); LCD_CD_DATA(sty>>8); LCD_CD_DATA(sty&0xff); LCD_CD_DATA(endy>>8); LCD_CD_DATA(endy&0xff); } void LcdWirteColorData(unsigned int color) { IO0SET=dc; IO0CLR=cs; SPI_RW(color>>8); SPI_RW(color); IO0SET=cs; } void LCD_Clear(unsigned int color) { unsigned int i,j; LCD_SetArea(0,0,239,319); LCD_CD_REG(0x2C); for(i=0;i<320;i++) { for(j=0;j<240;j++) { LcdWirteColorData(color); } } } void main() { TargetResetInit(); PINSEL0=(PINSEL0&(~(0XFF<<8)))|(0x55<<8); // 设置连接4线SPI PINSEL1 = 0x00000000; // 设置PIN1为GPIO IO0DIR = 0xffffffff; IO0SET = ssel0; MSpiInit(); delay_ms(100); LCD_Init(); while(1) { LCD_Clear(RED); delay_ms(300); LCD_Clear(BLUE); delay_ms(300); LCD_Clear(GREEN); delay_ms(300); } } |
|
|
|
时序及最新程序如上
|
|
|
|
解决了,PROTEUS模型问题
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
6043 浏览 3 评论
7311 浏览 1 评论
7550 浏览 0 评论
Protues中自己封装的芯片元件无Program File、Clock Frequency选项怎么解决,求求大神了!
9341 浏览 1 评论
基于51单片机的车辆倒车雷达报警系统,HC-SR04超声波测距,全套资料
1273 浏览 0 评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-22 00:54 , Processed in 0.621434 second(s), Total 59, Slave 51 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号