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

📄 pcf8833_c.h

📁 在基于avr内核的单片机上实现MP3播放器的功能
💻 H
字号:
/*

                         \\\|///
                       \\  - -  //
                        (  @ @  )
+---------------------oOOo-(_)-oOOo-------------------------+
|                                                           |
|                         CPU.c                             |
|                     by Xiaoran Liu                        |
|                        2005.3.16                          |
|                                                           |
|                    ZERO research group                    |
|                        www.the0.net                       |
|                                                           |
|                            Oooo                           |
+----------------------oooO--(   )--------------------------+
                      (   )   ) /
                       \ (   (_/
                        \_)     

*/
// 引入相关芯片的头文件 
#include <avr/io.h>
#include "PCF8833.h"



#define use_hard_isp  1


/*----------------------------------------------------------*\
 | S1D15G00 Initialize                                      |
\*----------------------------------------------------------*/



/*----------------------------------------------------------*\
 | S1D15G00 Write Command                                   |
\*----------------------------------------------------------*/
void  S1D15G00WriteCommand(INT8U Data) {
//	INT16U temp=Data;
	//cbi(LCD_CR_PORT,LCD_CS);
	
	//sbi(LCD_CR_DDR, LCD_DATA);		//set SDI.DDR = 1
		
	SPCR =0;
	cbi(LCD_CR_PORT, LCD_CS);		//set CS = L
	cbi(LCD_CR_PORT, LCD_CLK);		//set SCK = L
	cbi(LCD_CR_PORT, LCD_DATA);		//send 0, for command
	sbi(LCD_CR_PORT, LCD_CLK);		//set SCK = H, latch data
	
#if 	use_hard_isp
		SPCR |= (1<<MSTR)|(1<<SPE)|(1<<CPOL)|(1<<CPHA);//|(1<<SPR1)|(1<<SPR0);
	    
		SPDR =Data;
	while(!(SPSR & _BV(SPIF)));
#else	  
//Bit 0(MSB)
  SPCR =0;
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x80)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 1
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x40)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 2
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x20)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 3
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x10)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 4
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x08)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 5
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x04)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 6
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x02)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 7(LSB)
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x01)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//done
#endif
	
	sbi(LCD_CR_PORT,LCD_CS);
	}
/*----------------------------------------------------------*\
 | S1D15G00 Write Data                                      |
\*----------------------------------------------------------*/
void  S1D15G00WriteData(INT8U Data) {
//	INT16U temp=Data;
	//cbi(LCD_CR_PORT,LCD_CS);
	
	//sbi(LCD_CR_DDR, LCD_DATA);		//set SDI.DDR = 1
	     SPCR =0;
	cbi(LCD_CR_PORT, LCD_CS);		//set CS = L
	cbi(LCD_CR_PORT, LCD_CLK);		//set SCK = L
	sbi(LCD_CR_PORT, LCD_DATA);		//send 1, for command
	sbi(LCD_CR_PORT, LCD_CLK);		//set SCK = H, latch data
		
#if 	use_hard_isp
		SPCR |= (1<<MSTR)|(1<<SPE)|(1<<CPOL)|(1<<CPHA);//|(1<<SPR1)|(1<<SPR0);
	    
		SPDR =Data;
	while(!(SPSR & _BV(SPIF)));
#else	  
//Bit 0(MSB)
  SPCR =0;
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x80)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 1
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x40)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 2
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x20)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 3
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x10)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 4
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x08)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 5
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x04)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 6
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x02)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//Bit 7(LSB)
	cbi(LCD_CR_PORT, LCD_CLK);
	if(Data & 0x01)
		sbi(LCD_CR_PORT, LCD_DATA);
	else
		cbi(LCD_CR_PORT, LCD_DATA);
	sbi(LCD_CR_PORT, LCD_CLK);
//done
#endif
	
	sbi(LCD_CR_PORT,LCD_CS);
	}
/*----------------------------------------------------------*\
 | S1D15G00 Set Page Area                                   |
\*----------------------------------------------------------*/
void S1D15G00SetPageArea(char x1, char y1, char x2, char y2) {
     if(x1>GLCD_PIXELX) x1=GLCD_PIXELX/2;
	 if(y1>GLCD_PIXELX) y1=GLCD_PIXELX/2;
	 if(x2>GLCD_PIXELX) x2=GLCD_PIXELX;
	 if(y2>GLCD_PIXELX) y2=GLCD_PIXELX;
	 
	 if(x1>x2) x1=x2; if(y1>y2) y1=y2;
	 
	S1D15G00WriteCommand(SET_X_ADDR);
	S1D15G00WriteData(x1);
	S1D15G00WriteData(x2);
	S1D15G00WriteCommand(SET_Y_ADDR);
	S1D15G00WriteData(y1);
	S1D15G00WriteData(y2);
	S1D15G00WriteCommand(MEM_WRITE);
}
/*----------------------------------------------------------*\
 | S1D15G00 Clear LCD                                       |
\*----------------------------------------------------------*/
void S1D15G00ClearLcd(void) {
	unsigned int i;
/**/static  uint8 n6100clrMod=0;


if(n6100clrMod++==0){
S1D15G00WriteCommand(MEM_CONTROL);      //Display control
		S1D15G00WriteData((0 << MEM_MX) | (0 << MEM_MY) | (0 << MEM_RGB) | (0 << MEM_VW) | (0 << MEM_LAO));
               }
else 	{n6100clrMod=0;
S1D15G00WriteCommand(MEM_CONTROL);      //Display control
		S1D15G00WriteData((0 << MEM_MX) | (0 << MEM_MY) | (0 << MEM_RGB) | (1 << MEM_VW) | (0 << MEM_LAO));
               }

	S1D15G00SetPageArea(0, 0, GLCD_X_END, GLCD_Y_END);		   
	for(i=0; i<(GLCD_PIXELX*GLCD_PIXELY);i++)//(GLCD_PIXELX*GLCD_PIXELY)
	{
		S1D15G00WriteData(0x00);
		S1D15G00WriteData(0x00);
	}
	
/**/	S1D15G00WriteCommand(MEM_CONTROL);      //Display control
		S1D15G00WriteData((0 << MEM_MX) | (0 << MEM_MY) | (0 << MEM_RGB) | (0 << MEM_VW) | (0 << MEM_LAO));
}
/*----------------------------------------------------------*\
 | Delay                                                    |
\*----------------------------------------------------------*/
void  Delay(INT32U  dly) {

	for(; dly>0; dly--) 
		_delay_ms(1);
	}
/*----------------------------------------------------------*\
 | S1D15G00 Initial                                         |
\*----------------------------------------------------------*/
void  S1D15G00Init(void) {
	sbi(LCD_CR_DDR,LCD_DATA);
	sbi(LCD_CR_DDR,LCD_CS);
	sbi(LCD_CR_DDR,LCD_CLK);
	sbi(LCD_CR_DDR,LCD_RST);

	sbi(LCD_CR_PORT,LCD_CS);
	Delay(5);
	cbi(LCD_CR_PORT,LCD_RST);
	Delay(20);
	sbi(LCD_CR_PORT,LCD_RST);
	Delay(20);
	sbi(LCD_CR_PORT,LCD_DATA);
	sbi(LCD_CR_PORT,LCD_CLK);
	Delay(20);

//	S1D15G00SpiInit();

	S1D15G00WriteCommand(SOFT_RESET);         //Temperature gradient set
	Delay(10);
	S1D15G00WriteCommand(BOOSTER_ON);      //Internal oscillation on
	Delay(10);
	S1D15G00WriteCommand(SLEEP_OUT);      //Sleep out
    Delay(10);
	S1D15G00WriteCommand(COLOR_INTERFACE);      //Partial display out
		S1D15G00WriteData(COLOR_16_BIT);	//数据格式,一次几位
    Delay(10);
	
    S1D15G00WriteCommand(SET_CONTRAST);//控制对比度
     S1D15G00WriteData(0x3c);
	
	S1D15G00WriteCommand(COLOR_SET);	//256-color position set
		S1D15G00WriteData(0x00);
		S1D15G00WriteData(0x02);
		S1D15G00WriteData(0x04);
		S1D15G00WriteData(0x06);
		S1D15G00WriteData(0x09);
		S1D15G00WriteData(0x0B);
		S1D15G00WriteData(0x0D);
		S1D15G00WriteData(0x0F);

		S1D15G00WriteData(0x00);
		S1D15G00WriteData(0x02);
		S1D15G00WriteData(0x04);
		S1D15G00WriteData(0x06);
		S1D15G00WriteData(0x09);
		S1D15G00WriteData(0x0B);
		S1D15G00WriteData(0x0D);
		S1D15G00WriteData(0x0F);

		S1D15G00WriteData(0x00);
		S1D15G00WriteData(0x04);
		S1D15G00WriteData(0x0B);
		S1D15G00WriteData(0x0F);

	S1D15G00WriteCommand(MEM_CONTROL);      //Display control
		S1D15G00WriteData((0 << MEM_MX) | (0 << MEM_MY) | (0 << MEM_RGB) | (0 << MEM_VW) | (0 << MEM_LAO));	

	Delay(20);
	S1D15G00WriteCommand(DISPLAY_ON);      //Display control
    Delay(20);
	S1D15G00ClearLcd();
	}


#include "8X16.h"

void PutChar(INT8U x, INT8U y, char c, INT16U f, INT16U b) {
	unsigned int i,j;
	INT8U fRed,fGreenBlue,bRed,bGreenBlue;
	fRed = (f>>8) & 0xFF; fGreenBlue = f & 0xFF;
	bRed = (b>>8) & 0xFF; bGreenBlue = b & 0xFF;
	
	
	
	S1D15G00SetPageArea(x, y, x+8-1, y+16-1);
	for(i=0; i<16;i++) {
		INT8U m=pgm_read_byte(font+c*16+i);
		for(j=0;j<8;j++) {
			if((m&0x80)==0x80) {
				S1D15G00WriteData(fRed);
				S1D15G00WriteData(fGreenBlue);
				}
			else {
				S1D15G00WriteData(bRed);
				S1D15G00WriteData(bGreenBlue);
				}
			m<<=1; 
			}
		}
	}

void PutGb(INT8U x, INT8U y,uint16 GbData,uint8 size,uint16 frgb,uint16 brgb) {
	unsigned int i;
	INT16U  j;
	INT8U  ByteTp;
	INT8U  fRedGre,fGreBlu,bRedGre,bGreBlu;
	fRedGre=frgb>>8;fGreBlu=frgb;	
	bRedGre=brgb>>8;bGreBlu=brgb;
	
	S1D15G00SetPageArea(x, y, x+size-1, y+size-1);
	
	for(i=0; i<((size*size)/8);i++) {
	       
            ByteTp=pgm_read_byte(Gbfont+GbData*((size*size)/8)+i);
			 for(j=0;j<8;j++) {
			if((ByteTp&0x80)==0x80) {
				S1D15G00WriteData(fRedGre);
				S1D15G00WriteData(fGreBlu);
				}
			else {
				S1D15G00WriteData(bRedGre);
				S1D15G00WriteData(bGreBlu);
				}
			ByteTp<<=1; 
			}
	        
				}
		}
		
void Put2Gb(INT8U x, INT8U y,uint8 *S,uint8 size,uint16 frgb,uint16 brgb) {
	unsigned int i;
	INT16U  j;
	INT8U  ByteTp;
	INT8U  fRedGre,fGreBlu,bRedGre,bGreBlu;
	fRedGre=frgb>>8;fGreBlu=frgb;	
	bRedGre=brgb>>8;bGreBlu=brgb;
	
	S1D15G00SetPageArea(x, y, x+size-1, y+size-1);
	
	for(i=0; i<((size*size)/8);i++) {
	       
            ByteTp=*S++;//pgm_read_byte(Gbfont+i);
			 for(j=0;j<8;j++) {
			if((ByteTp&0x80)==0x80) {
				S1D15G00WriteData(fRedGre);
				S1D15G00WriteData(fGreBlu);
				}
			else {
				S1D15G00WriteData(bRedGre);
				S1D15G00WriteData(bGreBlu);
				}
			ByteTp<<=1; 
			}
	        
				}
		}		
uint16	rgb2clor12(uint8 Red,uint8 Gre,uint8 Blu)	
{
     INT8U  GreTp;
	INT8U RedGre,GreBlu;
	
    GreTp=Gre;
	Gre=(Gre>>5) & 0x07;
	Red = (Red) & 0xF8;
	RedGre=Red | Gre;
	
	GreTp=(GreTp<<3) & 0xe0;
	Blu=(Blu>>3)& 0x1f;
	GreBlu=Blu | GreTp;
	
	return (RedGre*256+GreBlu);
}
		
		
void N6100_display_string(INT8U Axc, INT8U Ayc,uint8 size,unsigned char * point)
{unsigned char i,k,x,y,Ax,Ay;



Ax=Axc;Ay=Ayc;
for(;*point!='\0';point++)

//========================
   {if( 0x80>=(*point) )  k=0;//w_wod(*point);
    else {x=*point;
	      point++;
	      y=*point;
		  k=0;
         while(k< sizeof(hz_tab))
               { i=hz_tab[k];k++;
			     if(i==x && hz_tab[k]==y)
			     {i=k; PutGb(Ax,Ay,i/=2,size,rgb2clor12(155,65,238),0xffe0);
				 Ax+=size;if(Ax>GLCD_PIXELX) {Ax=Axc; Ay+=size;}
				 goto exit;}
				 
                 k++;
              
               } 
		  //w_wod('@');
	    exit :k=0;
	     } 
   }       
}		


		
	
void draw1pic(INT8U x, INT8U y) {
	uint32 i,size;
	INT16U  j;
	INT8U  GreTp;
	INT8U fRed,fGre,fBlu,fRedGre,fGreBlu;
	
	//F_handle=OpenFile("a.bmp",dir_org_clusId);
	
	
	//S1D15G00ClearLcd();
	
	Read_current_File_one_sec(&F_handle);//开始一个文件的读
	ReadBmpInf(sd_buf);
	
	S1D15G00SetPageArea(x, y, x+BmpFileHd.BiWidth-1, y+BmpFileHd.BiHeight-1);
	j=BmpFileHd.BmpOffBits;
	
	size=BmpFileHd.BmpSize;
	/*set_addr(1,0);
	get_hex(BmpFileHd.BmpSize>>8);
	get_hex(BmpFileHd.BmpSize);*/
	for(i=BmpFileHd.BmpOffBits; i<size;i+=3) {
	
	if(j<509)  {fBlu=sd_buf[j++];fGre=sd_buf[j++];fRed=sd_buf[j++];}//511
	else {fBlu=sd_buf[j++];if(j>=512) {j=0;Read_current_File_one_sec(&F_handle);}
	      fGre=sd_buf[j++]; if(j>=512) {j=0;Read_current_File_one_sec(&F_handle);}
	      fRed=sd_buf[j++]; if(j>=512) {j=0;Read_current_File_one_sec(&F_handle);}
	     }
	
	GreTp=fGre;
	fGre=(fGre>>5) & 0x07;
	fRed = (fRed) & 0xF8;
	fRedGre=fRed | fGre;
	
	GreTp=(GreTp<<3) & 0xe0;
	fBlu=(fBlu>>3)& 0x1f;
	fGreBlu=fBlu | GreTp;
		S1D15G00WriteData(fRedGre);
		S1D15G00WriteData(fGreBlu);
			}
	}	




void PutString(INT8U x, INT8U y, char *s, INT16U f, INT16U b) {
	 
	INT8U i=0;
	i=x;
	while(*s) {
		PutChar(i,y,*s,f,b);
		s++; i+=8 ;if(i>GLCD_PIXELX) {i=x; y+=16;}
		}
	}

//==================================
void displayherestring(INT8U x, INT8U y, char *s)
{
PutString(x,y,s,0xF800,0xFFE0);
}

void put2asii(INT8U x, INT8U y, char s)
{
PutChar(x,y,s,0xF800,0xFFE0);
}


	/*S1D15G00WriteCommand(PARTIAL_AREA );
	S1D15G00WriteData(4);
	S1D15G00WriteData(20);
	 
	S1D15G00WriteCommand(PARTIAL_MODE_ON);*/
    
	   
	  //S1D15G00WriteCommand(PIXELS_ON);
	//S1D15G00WriteCommand(DISPLAY_ON);  

⌨️ 快捷键说明

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