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

📄 main.c

📁 用Silabs的C8051F410单片机驱动LCD12864的屏
💻 C
📖 第 1 页 / 共 2 页
字号:
  {
   DispRam[y>>3][x+i]    =StrAddr[0][i]<<(y%8)    |(DispRam[y>>3][x+i]    &(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+1][x+i]=StrAddr[0][i]>>(8-(y%8))|(DispRam[(y>>3)+1][x+i]&(0xFF<<(y%8)));
   DispRam[(y>>3)+1][x+i]=StrAddr[1][i]<<(y%8)    |(DispRam[(y>>3)+1][x+i]&(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+2][x+i]=StrAddr[1][i]>>(8-(y%8))|(DispRam[(y>>3)+2][x+i]&(0xFF<<(y%8)));
  }
 }
}
//-----------------------------------------------------------------------------

void Show_EnglishChar16(unsigned char x,unsigned char y,unsigned char StrAddr[2][8])
{
 unsigned char i;
 if((y%8)==0)
 {
  for(i=0;i<8;i++)
  {
   DispRam[y>>3][x+i]    =StrAddr[0][i];
   DispRam[(y>>3)+1][x+i]=StrAddr[1][i];  
  }
 }
 else
 {
  for(i=0;i<8;i++)
  {
   DispRam[y>>3][x+i]    =StrAddr[0][i]<<(y%8)    |(DispRam[y>>3][x+i]    &(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+1][x+i]=StrAddr[0][i]>>(8-(y%8))|(DispRam[(y>>3)+1][x+i]&(0xFF<<(y%8)));
   DispRam[(y>>3)+1][x+i]=StrAddr[1][i]<<(y%8)    |(DispRam[(y>>3)+1][x+i]&(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+2][x+i]=StrAddr[1][i]>>(8-(y%8))|(DispRam[(y>>3)+2][x+i]&(0xFF<<(y%8)));
  }
 }
}
//-----------------------------------------------------------------------------
void Show_ChineseChar12(unsigned char x,unsigned char y,unsigned char StrAddr[2][12])
{
 unsigned char i;
 if((y%8)==0)
 {
  for(i=0;i<12;i++)
  {
   DispRam[y>>3][x+i]    =StrAddr[0][i];
   DispRam[(y>>3)+1][x+i]=StrAddr[1][i]|(DispRam[(y>>3)+1][x+i]&(0xFF<<4));  
  }
 }
 else
 {
  for(i=0;i<12;i++)
  {
   DispRam[y>>3][x+i]    =StrAddr[0][i]<<(y%8)    |(DispRam[y>>3][x+i]    &(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+1][x+i]=StrAddr[0][i]>>(8-(y%8))|(DispRam[(y>>3)+1][x+i]&(0xFF<<(y%8)));
   DispRam[(y>>3)+1][x+i]=StrAddr[1][i]<<(y%8)    |(DispRam[(y>>3)+1][x+i]&(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+2][x+i]=StrAddr[1][i]>>(8-(y%8))|(DispRam[(y>>3)+2][x+i]&(0xFF<<(y%8)));
  }
 }
}

//-----------------------------------------------------------------------------
void Show_EnglishChar12(unsigned char x,unsigned char y,unsigned char StrAddr[2][6])
{
 unsigned char i;
 if((y%8)==0)
 {
  for(i=0;i<6;i++)
  {
   DispRam[y>>3][x+i]    =StrAddr[0][i];
   DispRam[(y>>3)+1][x+i]=StrAddr[1][i]|(DispRam[(y>>3)+1][x+i]&(0xFF<<4));  
  }
 }
 else
 {
  for(i=0;i<6;i++)
  {
   DispRam[y>>3][x+i]    =StrAddr[0][i]<<(y%8)    |(DispRam[y>>3][x+i]    &(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+1][x+i]=StrAddr[0][i]>>(8-(y%8))|(DispRam[(y>>3)+1][x+i]&(0xFF<<(y%8)));
   DispRam[(y>>3)+1][x+i]=StrAddr[1][i]<<(y%8)    |(DispRam[(y>>3)+1][x+i]&(0xFF>>(8-(y%8))));
   DispRam[(y>>3)+2][x+i]=StrAddr[1][i]>>(8-(y%8))|(DispRam[(y>>3)+2][x+i]&(0xFF<<(y%8)));
  }
 }
}
//-----------------------------------------------------------------------------
void Draw_Point(unsigned char x,unsigned char y)
{
 DispRam[y>>3][x]|=1<<(y%8);
}
//-----------------------------------------------------------------------------
void Clear_Point(unsigned char x,unsigned char y)
{
 DispRam[y>>3][x]&=~(1<<(y%8));
}
//-----------------------------------------------------------------------------
void Circle(unsigned char x,unsigned char y,unsigned char r)
{
 float thete;
 for(thete=0;thete<6.28;thete+=0.1)
 {
  Draw_Point(x+(float)r*sin(thete),y+(float)r*cos(thete));
 }
}

//-----------------------------------------------------------------------------
void Line(unsigned char x0,unsigned char y0,unsigned char x1,unsigned char y1)
{
 float k;
 unsigned char i;
 unsigned char Temp;
 if(x0>x1)
 {
  Temp=x0;
  x0=x1;
  x1=Temp;
 }
 if(y0>y1)
 {
  Temp=y0;
  y0=y1;
  y1=Temp;
 }

 if(x0==x1)
 {
  for(i=y0;i<=y1;i++)
  {
   Draw_Point(x0,i);
  }
 }
 
 else if(y0==y1)
 {
  for(i=x0;i<=x1;i++)
  {
   Draw_Point(i,y0);
  } 
 }
 else
 {
  k=(y1-y0)/(x1-x0);
  for(i=x0;i<x1;i++)
  {
   Draw_Point(i,i*k);
  }
 }
}


//-----------------------------------------------------------------------------
void Oscillator_Init (void)
{
 OSCICN = 0x87;                      // Configure internal oscillator for
 RSTSRC = 0x40;                      // Enable missing clock detector
}

//-----------------------------------------------------------------------------

void Port_Init (void)
{
 P0MDIN = 0xFF;                      
 P0SKIP = 0x00;                      
 P0MDOUT= 0xFF;                      

 P1MDIN = 0xFF;                      
 P1SKIP = 0x00;                      
 P1MDOUT= 0xFF;

 P2MDIN = 0xFF;                      
 P2SKIP = 0x00;                     
 P2MDOUT= 0xFF;

 P0=0xFF;
 P1=0xFF;
 P2=0xFF;

 XBR0 = 0x00;                       
 XBR1 = 0x40;                      
  
}
//-----------------------------------------------------------------------------
void Timer2_Init (void)
{
 TMR2CN = 0x00;                      // Stop Timer2; Clear TF2;
                                       // use SYSCLK as timebase, 16-bit
                                       // auto-reload
 CKCON |= 0x10;                      // Select SYSCLK for timer 2 source
 TMR2RL = 65535 - (SYSCLK /10000);   // Init reload value for 100 us
 TMR2 = 0xffff;                      // Set to reload immediately
 ET2 = 1;                            // Enable Timer2 interrupts
 TR2 = 1;                            // Start Timer2
}
/*----------------------------------------------------------------------------------------------*/

void Timer2_ISR (void) interrupt 5
{
 TF2H = 0;  
                          // Clear Timer2 interrupt flag
 UpData_LCD(DispRam);
}

//-----------------------------------------------------------------------------
// MAIN Routine
//-----------------------------------------------------------------------------

void main (void)
{
 PCA0MD &=~0x40;                    // WDTE = 0 (clear watchdog timerenable)
 Oscillator_Init ();                 // Initialize system clock to
 Port_Init (); 						 // Initialize crossbar and GPIO

 memset(DispRam,0x00,1024*sizeof(unsigned char));




 Timer2_Init ();                       
							
 Clear_LCD();
 Show_ChineseChar16(16,0,Zhongguo);	
 Show_ChineseChar16(16,16,Zhongguo);	
 Show_ChineseChar16(16,32,Zhongguo);	 						
 Show_ChineseChar16(16,40,Zhongguo);
 Show_ChineseChar16(32,31,Zhongguo);
 Show_ChineseChar16(80,31,Zhongguo);

 Show_EnglishChar16(50,0,Eight);
 Show_EnglishChar16(50,16,Eight);
 Show_EnglishChar16(50,31,Eight);

 Show_ChineseChar12(65,0,Zhongguo12);
 Show_ChineseChar12(65,12,Zhongguo12);
 Show_ChineseChar12(65,31,Zhongguo12);

 Show_EnglishChar12(80,0,Five);
 Show_EnglishChar12(80,12,Five);
 Show_EnglishChar12(80,25,Five);

 Line(10,10,100,60);
 Draw_Point(20,50);
 Circle(50,30,25);
 Clear_Point(70,32);

 		
 EA=1;
		    
 //LCD_Delay(255);				//Delay
					
 while(1)					
 {			
 
	
//  gotoxy(0,0);							
//  Display_LCD_NumberAB(2);
//  gotoxy(0,2);
//  Display_LCD_NumberB(5);
//  gotoxy(5,4);	   
//  Display_LCD_string(Zhongguo,2);
//  gotoxy(64,4);
//  Display_LCD_Data(digit[1]);
//  gotoxy(72,4);
//  Display_LCD_Data(digit[2]);
 }		 
}

//-----------------------------------------------------------------------------


⌨️ 快捷键说明

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