⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lcd.c

📁 用atmega64+vs1003(音频解码芯片)+SD制成的板子
💻 C
📖 第 1 页 / 共 2 页
字号:
     
}
void LCD_Write_Char2(unsigned char *mat){
	unsigned char i;
			switch(D_x){
				case 0:    //写入第一行(1-12)
						for(i=0;i<12;i++){
							DispBuff[0][D_y+i]=mat[i];	
						}
						for(i=0;i<12;i++){
							DispBuff[1][D_y+i]&=0xf0;
							DispBuff[1][D_y+i]|=(mat[i+12]&0x0f);
						}
				    break;
				case 1: //写入第二行(13-24)
			 	  for(i=0;i<12;i++){
							DispBuff[1][D_y+i]&=0x0f;
							DispBuff[1][D_y+i]|=(mat[i]<<4);
						}
						for(i=0;i<12;i++){
							DispBuff[2][D_y+i]= ((mat[i]>>4))|(mat[12+i]<<4);
					}
					break; 
				case 2: //写第三行(25-36)同第一行  
						for(i=0;i<12;i++){
							DispBuff[3][D_y+i]=mat[i];	
						}
						for(i=0;i<12;i++){
							DispBuff[4][D_y+i]&=0xf0;
							DispBuff[4][D_y+i]|=(mat[i+12]&0x0f);
						}
				    break;
				case 3: //写第四行(37-48) 同第二行
						for(i=0;i<12;i++){
							DispBuff[4][D_y+i]&=0x0f;
							DispBuff[4][D_y+i]|=(mat[i]<<4);	
						}
						for(i=0;i<12;i++){
							DispBuff[5][D_y+i]= (mat[i]>>4)|(mat[12+i]<<4);
						}
					break; 
		     };    
}

//从字库中查找出字模
void Get_HzMat(unsigned char *code,unsigned char *mat)
{
	 unsigned char qh,wh;
	 unsigned char i,j;
	 unsigned int  sector,clusor,secoff;
	 unsigned long foffset;
	 qh=(*code++)-0xa1;
	 wh=(*code)-0xa1;
	 foffset=(unsigned long)(94*qh+wh)*24;    //得到字库中的字节偏移量
	 sector=foffset/BytesPerSector;           //得到总的完整的扇区数(不要写成(unsigned int ) foffset/512
	 secoff= (unsigned int) foffset%BytesPerSector; //扇区内的字节数偏移
	 wh=(unsigned char)sector%SectorsPerCluster; 
	 clusor=(unsigned int)sector/SectorsPerCluster;    //得到总的簇数
   eeprom_read_block(&foffset,(void*)(clusor*4),4); //为节省时间不从FAT中读取簇号
	 foffset=(unsigned long) (foffset+wh)*BytesPerSector+secoff;
	 i=0;  reading = 0;
	 SD_Write_Command(16,8);     //设置一次读写BLOCK的长度为8个字节
	while(1){
		reading=1;   
		SD_Write_Command(17,foffset);      
		while (Read_Byte_SPI()!= 0xfe) ;
		for(j=0; j<8; j++){
		  mat[i++]=Read_Byte_SPI();
		}
		Read_Byte_SPI();//CRC - Byte 
		Read_Byte_SPI();//CRC - Byte
		reading=0;
		MMC_PORT|=MMC_CS_PIN;        //关闭SD卡 
	    if(i>=24)    break; 
	     foffset+=8;
		 secoff+=8;
		if(secoff>=(BytesPerSector-1)){ 
			secoff=0;		
			if(++wh>=SectorsPerCluster){ wh=0;	 clusor++;  
			 eeprom_read_block(&foffset,(void*)(clusor*4),4);  
			 foffset=foffset*512;
			 foffset=0;
	      }
		}
	}
	SD_Write_Command(16,512);     //设置一次读写BLOCK的长度为512个字节   
}

/*-----------------------------------------------------------------------
LCD_draw_map: 位图绘制函数
输入参数:X、Y:位图绘制的起始X、Y坐标;
*map:位图点阵数据;
Pix_x:位图像素(长)
Pix_y:位图像素(宽)
-----------------------------------------------------------------------*/
void LCD_draw_map(unsigned char X,unsigned char Y,PGM_P map, //unsigned char *map,
unsigned char Pix_x,unsigned char Pix_y)
{
  unsigned int i,n;
  unsigned char row;
  if (Pix_y%8==0) 
    row=Pix_y/8;//计算位图所占行数
  else
    row=Pix_y/8+1;
  for (n=0;n<row;n++)
  {
    LCD_set_XY(X,Y);
    for(i=0; i<Pix_x; i++)
    {
    //  LCD_write_byte(map[i+n*Pix_x], 1);
	  LCD_write_byte(pgm_read_byte(map+i+n*Pix_x));
    }
    Y++;//换行
  }
}
void DispNumber(uchar x,uchar y,unsigned long number)
{
	 unsigned int kmm;
	 unsigned char t1,t2,t3,t4;
	 if(x>3)  return;
//	  t0=number/10000;
//	  number=number%10000;
		t1=number/1000;
		kmm=number%1000;
		t2=kmm/100;
		kmm=kmm%100;
		t3=kmm/10;
		t4=kmm%10;
		D_x=x;
		D_y=y;
//		LCD_write_char(t0+0x30);
		LCD_write_char(t1+0x30);
	 	LCD_write_char(t2+0x30);
	 	LCD_write_char(t3+0x30);
	 	LCD_write_char(t4+0x30);
		TimeFlag|=bLcdUpdate;
}
    
void DispDecodeTime(uchar x,uchar y,unsigned int second)
{
	unsigned int kmm;
	unsigned char t1,t2,t3,t4;
	if(x>3)  return;
	t1= second%60; kmm=second/60;
	t3=t1/10; 	t4=t1%10;
	t1=kmm/10;	t2=kmm%10;
	D_x=x;	    D_y=y;
	LCD_write_char(t1+0x30);
	LCD_write_char(t2+0x30);  //
	LCD_write_char(':');
	LCD_write_char(t3+0x30);
	LCD_write_char(t4+0x30);
	TimeFlag|=bLcdUpdate;
}
    
void LcdWrite(void)
{
	uchar t1,t2;
	uchar *p;    
	uchar line;
	if(LcdFlag==0){ 
		if(TimeFlag&bLcdUpdate) 
		{
			TimeFlag&=~bLcdUpdate;  
			p=(uchar *) &DispBuff[0][0];
			for(t1=0;t1<6;t1++){   
				LCD_set_XY(0,t1);
				switch(t1){
					case 0:
						  if(InverseLine&0x01) {
						  	for(t2=0;t2<84;t2++)			LCD_write_byte(~(*p++));
						  }else{
						  	for(t2=0;t2<84;t2++)	    LCD_write_byte(*p++);
						  }
					     break;	
					case 1:
						 line=(InverseLine&0x03);
						 if(line==0){
						 		for(t2=0;t2<84;t2++)	    LCD_write_byte(*p++);
						 }else if(line==1){
							  for(t2=0;t2<84;t2++)      LCD_write_byte((*p++)^0x0f);
						 }else if(line==2){
						 	  for(t2=0;t2<84;t2++)      LCD_write_byte((*p++)^0xf0);
						 }else{
						    for(t2=0;t2<84;t2++)			LCD_write_byte(~(*p++));
						 }
							break;							
					case 2:
							if(InverseLine&0x02) {
						  	for(t2=0;t2<84;t2++)			LCD_write_byte(~(*p++));
						  }else{
						  	for(t2=0;t2<84;t2++)	    LCD_write_byte(*p++);
						  }	
						  break;
					case 3:
							if(InverseLine&0x04) {
						  	for(t2=0;t2<84;t2++)			LCD_write_byte(~(*p++));
						  }else{
						  	for(t2=0;t2<84;t2++)	    LCD_write_byte(*p++);
						  }
						  break;
									
					case 4:
						 line=(InverseLine>>2)&0x03;
						 if(line==0){
						 		for(t2=0;t2<84;t2++)	    LCD_write_byte(*p++);
						 }else if(line==1){
							  for(t2=0;t2<84;t2++)      LCD_write_byte((*p++)^0x0f);
						 }else if(line==2){
							  for(t2=0;t2<84;t2++)      LCD_write_byte((*p++)^0xf0);
						 }else{
						    for(t2=0;t2<84;t2++)			LCD_write_byte(~(*p++));
						 }
							break;		
										
					case 5:
						 if(InverseLine&0x08) {
						  	for(t2=0;t2<84;t2++)			LCD_write_byte(~(*p++));
						  }else{
						  	for(t2=0;t2<84;t2++)	    LCD_write_byte(*p++);
						  }
						  break;
				}
		 	}
		}   	
		return;
	}
	
	if(LcdFlag&bUpdate1){  
		LCD_write_String(0,lcd[0].y,lcd[0].pStr);
		LcdFlag&=~bUpdate1; TimeFlag|=bLcdUpdate;
	}else if(LcdFlag&bUpdate2){        
		LCD_write_String(1,lcd[1].y,lcd[1].pStr);
		LcdFlag&=~bUpdate2; TimeFlag|=bLcdUpdate;
	}else if(LcdFlag&bUpdate3){ 
		LCD_write_String(2,lcd[2].y,lcd[2].pStr);
        LcdFlag&=~bUpdate3; TimeFlag|=bLcdUpdate;
	}else if(LcdFlag&bUpdate4){
		LCD_write_String(3,lcd[3].y,lcd[3].pStr);
		LcdFlag&=~bUpdate4;  TimeFlag|=bLcdUpdate;
	}

}
void DispVolume(void)
{
  unsigned char t1,t2;
	D_x=3;	    D_y=63;
	t1=(vol+1)/10;
	t2=(vol+1)%10;
	LCD_write_icon(0);
	D_y+=2;
	if(t1==0){
	LCD_write_char(' ');
	}else{
	LCD_write_char(t1+0x30);
	}
	LCD_write_char(t2+0x30);  //
	TimeFlag|=bLcdUpdate;
}
void PrintString(uchar x,uchar y,uchar *str)
{                   

    if(x>3)  return;
	LcdFlag|=(1<<x);
/*	if(x==0){
		LcdFlag|=bUpdate1;
	}else if(x==1){
		LcdFlag|=bUpdate2;
	}else if(x==2){
		LcdFlag|=bUpdate3;
	}else if(x==3){
		LcdFlag|=bUpdate4;
	}	
*/	
	lcd[x].y=y;
	lcd[x].pStr=str;
}
void ClrLyricScreen(void)
{   unsigned char i;
	for(i=0;i<84;i++){
		DispBuff[1][i]&=0x0f;
	  }
 		for(i=0;i<84;i++){
		DispBuff[2][i]=0;
		DispBuff[3][i]=0;
	  }
	  for(i=0;i<84;i++){
	  	DispBuff[4][i]&=0xf0;
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -