📄 hyj.c
字号:
#include <avr/io.h>
#include <util/delay.h>
#include "lcd.h"
#include "gui.h"
#include "FAT.h"
uint16 image_count = 0 ,image_all = 0 ;
extern uint16 SectorsPerClust;//每簇扇区数
extern uint8 FAT32_Enable;
void disp_image(void)
{
WORD count= 1 ,i =0 ;
uint8 *buffer ;
uint8 type ,x , rgb,first ,color_byte,byte1,byte2,byte3 ;
uint16 y ,color,tmp_color ;
uint32 p; //簇指示值 //cluster
type = 1 ;
struct FileInfoStruct FileInfo;//文件信息
struct direntry BMPInfo; //要播放的mp3文件信息 //the mp3 file item whichi will be played
if( image_all == 0 ) //读取总图片数
{
image_count = 0 ;
byte1 = Search(&BMPInfo,&image_count,&type) ;
image_all = image_count ;
image_count = 1 ;
/*
image_count = 0 ;
Search(&BMPInfo,&image_count,&type) ;
image_all = image_count ;
GUI_sprintf_chartohex(10,300,0x00,0xffff,0x0000) ;
GUI_sprintf_chartohex(30,300,image_count,0xffff,0x0000) ;
GUI_sprintf_chartohex(60,300,image_all,0xffff,0x0000) ;
*/
}
else
{
byte1 = Search(&BMPInfo,&image_count,&type) ;
}
p = BMPInfo.deStartCluster+(((uint32)BMPInfo.deHighClust)<<16);//读文件首簇 //the first cluster of the file
x = 0 ;
y = 319 ;
rgb = 0 ;
count = 0 ;
first = 0 ;
buffer=malloc(512);
while(1)
{
i = 0 ;
for( ; i < SectorsPerClust ; i++ ) //簇
{
FAT_LoadPartCluster(p,i,buffer);//读一个扇区 //read a sector
if(i==0 && first==0) { count= buffer[0x0a] ; color_byte = buffer[0x1c] / 8 ; first = 1 ; }
else { count=0 ; }
while(count<512) //读取一簇512扇区 (SectorsPerClust 每簇扇区数)
{
if(color_byte == 3) //24位颜色图
{
switch ( rgb )
{
case 0 : tmp_color = buffer[count]>>3 ;
color |= tmp_color;
break ;
case 1 : tmp_color = buffer[count]>>2 ;
tmp_color <<= 5 ;
color |= tmp_color ;
break ;
case 2 : tmp_color = buffer[count]>>3 ;
tmp_color <<= 11 ;
color |= tmp_color ;
break ;
}
rgb ++ ;
}
else
{
if(color_byte==2) //16位颜色图
{
switch ( rgb )
{
case 0 : byte1 = buffer[count] ;
break ;
case 1 :
color = buffer[count] ;
color<<=8 ;
color |= byte1 ;
break ;
}
rgb ++ ;
}
else
{
if(color_byte==4) //32位颜色图
{
switch ( rgb )
{
case 0 : byte1 = buffer[count] ;
break ;
case 1 : byte2 = buffer[count] ;
break ;
case 2 : byte3 = buffer[count] ;
break ;
case 3 : tmp_color = byte1 >> 3 ;
color |= tmp_color;
tmp_color = byte2 >>2 ;
tmp_color <<= 5 ;
color |= tmp_color ;
tmp_color = byte3 >>3 ;
tmp_color <<= 11 ;
color |= tmp_color ;
break ;
}
rgb ++ ;
}
}
}
count ++ ;
if(rgb == color_byte) //读取1像素数数据后显示
{
GUI_Point(x, y,color) ;
color = 0x00 ;
x++ ;
if(x>=240)
{
y-- ;
if( y<=0 )
{
free(buffer) ;
return ;
}
x = 0 ;
}
rgb = 0 ;
}
}
} // 读取完一簇数据
free(buffer) ;
p=FAT_NextCluster(p);//读下一簇数据 //read next cluster
buffer=malloc(512);
if(p == 0x0fffffff || p == 0x0ffffff8 || (FAT32_Enable == 0 && p == 0xffff))//如果无后续簇则结束, //no more cluster
{
free(buffer) ;
return ;
}
}
free(buffer) ;
}
//主程序
int main(void)
{
unsigned char i, x,retry=0;
uint8 ok,er,r1 ;
uint32 capacity ;
unsigned int y ;
LCD_Init(); //LCD初始化
x = 0 ;
y = 0 ;
GUI_ClearSCR() ;
for(i=0 ; i<10 ;i++)
{
GUI_sprintf_nu(x,y,i,0x07E0,0x0000) ;
x+= 10 ;
}
ok = 0 ;
er = 0 ;
OSCCAL = 0x00;//最小RC振荡频率
delay_us(0xffff);
MMC_SD_Init();//初始化spi口
delay_us(0xffff);
while(MMC_SD_Reset())//初始化SD卡 //sd card initialize
{
retry++;
if(retry>20)
{
while(1) //初始化失败显示
{
GUI_sprintf_chartobit(120,0,0x55,0xffff,0x0000) ;
delay_us(0xffff);
GUI_sprintf_chartobit(120,0,0xaa,0xffff,0x0000) ;
delay_us(0xffff);
}
}
}
GUI_sprintf_chartobit(120,0,0xf0,0xffff,0x0000) ;
OSCCAL = 0xff;//最大RC振荡频率 //normal operation maximum the frequency
delay_us(0xffff);
if(FAT_Init())//初始化文件系统 支持FAT16和FAT32 //initialize file system FAT16 and FAT32 are supported
{
while(1)
{
while(1)
{
GUI_sprintf_chartobit(120,0,0x00,0xffff,0x0000) ;
delay_us(0xffff);
GUI_sprintf_chartobit(120,0,0xff,0xffff,0x0000) ;
delay_us(0xffff);
}
}
}
SearchInit(); //搜索文件初始化
while(1)
{
disp_image() ;
_delay_ms(6000) ;
//Print_hz(72,30,16,"汉字显示测试",0xffff,0x0000) ;
if(image_count<image_all)
{
image_count ++ ;
}
else
{
image_count = 1 ;
}
}
//LCD_test(); //彩色测试
//read_data() ;
//GUI_ClearSCR() ;
//LCD_test(); //彩色测试
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -