完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
为什么从sd卡读取出来的图片在TFT显示是这样的,屏幕上怎会出现这么多白色的斜线,求大神指点啊~~~
这是SD卡操作: #include //===========================================================//写一字节到SD卡,模拟SPI总线方式void SdWrite(unsigned char n){ unsigned char i; for(i=8;i;i--){SD_CLK=0;SD_DI=(n&0x80);n<<=1;SD_CLK=1;}SD_DI=1; } //===========================================================//从SD卡读一字节,模拟SPI总线方式unsigned char SdRead(){unsigned char n,i;for(i=8;i;i--){SD_CLK=0;SD_CLK=1;n<<=1;if(SD_DO) n|=1; }return n;}//============================================================//检测SD卡的响应unsigned char SdResponse(){unsigned char i=0,response; while(i<=8){response = SdRead();if(response==0x00)break;if(response==0x01)break;i++;}return response;} //================================================================//发命令到SD卡void SdCommand(unsigned char command, unsigned long argument, unsigned char CRC){ SdWrite(command|0x40);SdWrite(((unsigned char *)&argument)[0]);SdWrite(((unsigned char *)&argument)[1]);SdWrite(((unsigned char *)&argument)[2]);SdWrite(((unsigned char *)&argument)[3]);SdWrite(CRC);}//================================================================//初始化SD卡unsigned char SdInit(void){int delay=0, trials=0;unsigned char i;unsigned char response=0x01; SD_CS=1;for(i=0;i<=9;i++)SdWrite(0xff);SD_CS=0; //Send Command 0 to put MMC in SPI modeSdCommand(0x00,0,0x95); response=SdResponse(); if(response!=0x01){return 0;} while(response==0x01){SD_CS=1;SdWrite(0xff);SD_CS=0;SdCommand(0x01,0x00ffc000,0xff);response=SdResponse();} SD_CS=1;SdWrite(0xff);return 1; }//================================================================//往SD卡指定地址写数据,一次最多512字节unsigned char SdWriteBlock(unsigned char *Block, unsigned long address,int len){unsigned int count;unsigned char dataResp;//Block size is 512 bytes exactly//First Lower SS SD_CS=0;//Then send write commandSdCommand(0x18,address,0xff); if(SdResponse()==00){SdWrite(0xff);SdWrite(0xff);SdWrite(0xff);//command was a success - now send data//start with DATA TOKEN = 0xFESdWrite(0xfe);//now send datafor(count=0;count while(SdRead()==0); dataResp=dataResp&0x0f; //mask the high byte of the DATA RESPONSE tokenSD_CS=1;SdWrite(0xff);if(dataResp==0x0b){//printf("DATA WAS NOT ACCEPTED BY CARD -- CRC ERRORn");return 0;}if(dataResp==0x05)return 1; //printf("Invalid data Response token.n");return 0;}//printf("Command 0x18 (Write) was not received by the MMC.n");return 0;} //=======================================================================//从SD卡指定地址读取数据,一次最多512字节unsigned char SdReadBlock(unsigned char *Block, unsigned long address,int len){unsigned int count;//Block size is 512 bytes exactly//First Lower SS //printf("MMC_read_blockn"); SD_CS=0;//Then send write commandSdCommand(0x11,address,0xff); if(SdResponse()==00){//command was a success - now send data//start with DATA TOKEN = 0xFEwhile(SdRead()!=0xfe); for(count=0;count //data block sent - now send checksumSdRead();SdRead();//Now read in the DATA RESPONSE tokenSD_CS=1;SdRead();return 1;} //printf("Command 0x11 (Read) was not received by the MMC.n");return 0;} //============================================================//主程序main(){ unsigned int x,y; //定义液晶屏坐标 unsigned long j; //执行循环需要的临时变量 unsigned int i; unsigned long AddTemp=262144;//SD卡地址第一个数据物理地址初始值,可以用winhex查看,这里是512扇区,512x512=262144,根据实际SD卡内容更改 //CS=1;delayms(25);RES=0;delayms(150);RES=1;delayms(25);ILI9325_Initial();//液晶屏初始化SdInit(); //SD卡初始化 while(1) { for(j=0;j<300;j++) //300表示一幅图片含有300x512字节的信息 { SdReadBlock(DATA,AddTemp+(j*512),512);//每次读出512字节放到缓冲区 for(i=0;i<256;i++) //然后写到液晶屏,可以显示256个像素,每个像素16位即2个字节 { LCD_SetPos(x,x,y,y); Write_Data(DATA[2*i+1],DATA[2*i]); x++; if(x==240) //检测是否写到屏的边缘 240x320 { y++; x=0; if(y==320) y=0; } } } AddTemp = AddTemp+((j+20)*512); //写完一幅图片后把SD地址加300x512到下一个图片地址 while(KEY); //等待按键按下继续执行循环显示下一幅图片,如果没有按下则等待 } } 这是9325TP.h #include"reg52.h"//============================================================//根据芯片资料定义#define WINDOW_XADDR_START0x0050 // Horizontal Start Address Set#define WINDOW_XADDR_END0x0051 // Horizontal End Address Set#define WINDOW_YADDR_START0x0052 // Vertical Start Address Set#define WINDOW_YADDR_END0x0053 // Vertical End Address Set#define GRAM_XADDR 0x0020 // GRAM Horizontal Address Set#define GRAM_YADDR 0x0021 // GRAM Vertical Address Set#define GRAMWR 0x0022 // memory write //=============================================================//定义液晶屏接口***it CS=P2^1;//片选***it RES=P2^3;//复位***it RS=P2^4;//数据/命令选择***it RW=P2^5; //数据口使用P0//====================================================////函数声明void ILI9325_Initial(void);void Write_Cmd_Data(unsigned char x, unsigned int y);void Write_Cmd(unsigned char DH,unsigned char DL);void Write_Data(unsigned char DH,unsigned char DL);void delayms(unsigned int tt);void Write_Data_U16(unsigned int y);static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1);void ClearScreen(unsigned int bColor); //===============================================================//清屏void ClearScreen(unsigned int bColor){ unsigned int i,j; LCD_SetPos(0,240,0,320);//320x240 for (i=0;i<320;i++){ for (j=0;j<240;j++) Write_Data_U16(bColor);}} //===============================================================//写命令数据void Write_Cmd_Data (unsigned char x,unsigned int y){unsigned char m,n;m=y>>8;n=y;Write_Cmd(0x00,x);Write_Data(m,n); } //==============================================================//写16位数据void Write_Data_U16(unsigned int y){unsigned char m,n;m=y>>8;n=y;Write_Data(m,n); }//=============================================================//写命令 void Write_Cmd(unsigned char DH,unsigned char DL){ CS=0;RS=0; P0=DH;RW=0;RW=1; P0=DL;RW=0;RW=1;CS=1;} //===================================================================//写数据 void Write_Data(unsigned char DH,unsigned char DL){ CS=0;RS=1;P0=DH;RW=0; RW=1; P0=DL;RW=0;RW=1;CS=1;} //============================================================//延时程序void delayms(unsigned int count){ int i,j; for(i=0;i void ILI9325_Initial(void){ delayms(50); //根据不同晶振速度可以调整延时,保障稳定显示 Write_Cmd_Data(0x0001,0x0010); Write_Cmd_Data(0x0002,0x0700); Write_Cmd_Data(0x0003,0x0030); Write_Cmd_Data(0x0004,0x0000); Write_Cmd_Data(0x0008,0x0207); Write_Cmd_Data(0x0009,0x0000); Write_Cmd_Data(0x000A,0x0000); Write_Cmd_Data(0x000C,0x0000); Write_Cmd_Data(0x000D,0x0000); Write_Cmd_Data(0x000F,0x0000);//power on sequence VGHVGL Write_Cmd_Data(0x0010,0x0000); Write_Cmd_Data(0x0011,0x0007); Write_Cmd_Data(0x0012,0x0000); Write_Cmd_Data(0x0013,0x0000); //vgh Write_Cmd_Data(0x0010,0x1290); Write_Cmd_Data(0x0011,0x0227); delayms(100); //vregiout Write_Cmd_Data(0x0012,0x001d); //0x001b delayms(100); //vom amplitude Write_Cmd_Data(0x0013,0x1500); delayms(100); //vom H Write_Cmd_Data(0x0029,0x0018); Write_Cmd_Data(0x002B,0x000D); //gamma Write_Cmd_Data(0x0030,0x0004); Write_Cmd_Data(0x0031,0x0307); Write_Cmd_Data(0x0032,0x0002);// 0006 Write_Cmd_Data(0x0035,0x0206); Write_Cmd_Data(0x0036,0x0408); Write_Cmd_Data(0x0037,0x0507); Write_Cmd_Data(0x0038,0x0204);//0200 Write_Cmd_Data(0x0039,0x0707); Write_Cmd_Data(0x003C,0x0405);// 0504 Write_Cmd_Data(0x003D,0x0F02); //ram Write_Cmd_Data(0x0050,0x0000); Write_Cmd_Data(0x0051,0x00EF); Write_Cmd_Data(0x0052,0x0000); Write_Cmd_Data(0x0053,0x013F); Write_Cmd_Data(0x0060,0xA700); Write_Cmd_Data(0x0061,0x0001); Write_Cmd_Data(0x006A,0x0000); // Write_Cmd_Data(0x0080,0x0000); Write_Cmd_Data(0x0081,0x0000); Write_Cmd_Data(0x0082,0x0000); Write_Cmd_Data(0x0083,0x0000); Write_Cmd_Data(0x0084,0x0000); Write_Cmd_Data(0x0085,0x0000); // Write_Cmd_Data(0x0090,0x0010); Write_Cmd_Data(0x0092,0x0600); Write_Cmd_Data(0x0093,0x0003); Write_Cmd_Data(0x0095,0x0110); Write_Cmd_Data(0x0097,0x0000); Write_Cmd_Data(0x0098,0x0000); Write_Cmd_Data(0x0007,0x0133); //Write_Cmd_Data(0x0022);//} //===============================================================//定义坐标static void LCD_SetPos(unsigned int x0,unsigned int x1,unsigned int y0,unsigned int y1){ 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);} |
|
相关推荐
5个回答
|
|
|
|
|
|
清屏的没问题,我试了
|
|
|
|
原子哥,你知道这是怎回事不,我都检查了好几遍了,还是不知哪错了
|
|
|
|
那就是你解码哪里出问题了,呵呵.
|
|
|
|
我的也出现这个问题,特地进来求教
|
|
|
|
只有小组成员才能发言,加入小组>>
3318 浏览 9 评论
2995 浏览 16 评论
3494 浏览 1 评论
9063 浏览 16 评论
4088 浏览 18 评论
1185浏览 3评论
609浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
601浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2337浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1897浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-25 07:30 , Processed in 1.713503 second(s), Total 86, Slave 67 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号