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

📄 lcd.c

📁 基于s3c2410硬件的 U-boot代码
💻 C
字号:
#include "main.h"

#define CS1 RC7
#define CS2 RC6
#define E  RC2
#define R_W RC4
#define R_W RC4
#define RS RC3
#define Reset RC5
#define LcdPD RA4
#define LcdDelay  15


#define shuzioffet 8 
#define fuhaooffet 4
#define hanzioffet 16
bit Zimo,Data9;
unsigned char LcdCom,LcdAll,LcdLeft;

unsigned char a,b,c,d,e,f,g;
void Delay(unsigned long value)		/*延时副程式*/
 {
      while (value!=0) value--;		/*10US延时*/
 } 

void
WrLcd(unsigned char LcdCom,unsigned char LcdAll,unsigned char LcdLeft,unsigned char LcdXX)
{
     E=0;     
    R_W=0;              
    if(LcdCom==1)
    {
    RS=0;
    }
    else
    {
     RS=1;
     if(Zimo==1)
     LcdXX=(0xFF-LcdXX);   	 
     if(Data9==1)
     LcdXX=0x00;     	 
    }    
    if(LcdAll==1)
    {
    CS1=0;
    CS2=0;
    }
    else
    {
     if(LcdLeft==1)
     {   
      CS1=0;
      CS2=1;
     }
     else
     {
      CS1=1;
      CS2=0;
     }            
               
    }
    
    Delay(LcdDelay);
    E=1;
    PORTB=LcdXX;
    Delay(LcdDelay);
    E=0;
    //Delay(LcdDelay);    
    //E=1;
}
 
void 
LcdSet(void)
{
 ULPWUE=0;
 SBOREN=0;
 SWDTEN-0;
 //C1ON=0;
 //ANSEL=0X27;
 //PORTA=0XFF;
 TRISA=0X07; 

 PSTRCON=0X00;
 ANSELH=0X00;
 RBPU=0;
 PORTB=0XFF;
 TRISB=0X00; 

 PORTC=0XFc;
 TRISC=0X03;

 
LcdPD=0;

Zimo=0;
Data9=0; 

Reset=0;
Delay(100);
Reset=1;

 
WrLcd(1,1,0,0xC0);
WrLcd(1,1,0,0x3F);            
}
void 
LcdClear(void)
{  
 
 unsigned char AA,a;
 Zimo=0;
 for(AA=0xB8;AA<0xC0;AA++)
 { 
  
 WrLcd(1,1,0,AA);
 WrLcd(1,1,0,0x40);
  
 for(a=0;a<64;a++) 
 {  
   WrLcd(0,1,0,0x00); 
 }
  
 } 
}
 

 
const hanzi[500]=
{
0x00,0x00,0x00,0x20,0x12,0x2A,0x42,0x3F,0x0A,0x52,0x20,0x1F,0x00,0x00,0x7F,0x00,
0x00,0x00,0x00,0x40,0x40,0x20,0x10,0x0C,0x03,0x00,0x20,0x40,0x20,0x1F,0x00,0x00,
0x00,0x40,0x40,0x20,0x10,0x08,0x07,0x00,0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00,
0x04,0x7C,0x43,0x20,0x18,0x27,0x10,0x0B,0x42,0x7E,0x02,0x0A,0x13,0x20,0x00,0x00,
0x00,0x00,0x00,0x40,0x48,0x58,0x6A,0xCC,0x68,0x58,0x00,0xFC,0x48,0x48,0xC4,0x66,
0x44,0x00,0x00,0x00,0x20,0x20,0x20,0x20,0xFE,0x20,0x20,0x20,0x20,0xF0,0x20,0x00,
0x00,0x80,0x80,0x88,0x90,0xA0,0x80,0xFE,0x80,0x80,0xA0,0x90,0x88,0x80,0x80,0x00,
0x20,0xC2,0x0C,0xC0,0x00,0xFC,0x04,0xF4,0x94,0x9C,0x94,0x94,0xF6,0x04,0x00,0x00,
};
const TuKu[1000]=
{
0xe0,0xa0,0xa0,0xa0,0xa0,0xe0,//1-3
0xfc,0x84,0x84,0x84,0x84,0xfc,//1-6
0xff,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xff,0x80,//2-9
0xff,0xf0,0x80,0x10,0x80,0x10,0x80,0x10,0x80,0x10,0xff,0xf0,//2-12
0xff,0xfe,0x80,0x02,0x80,0x02,0x80,0x02,0x80,0x02,0xff,0xfe,//2-15
0xff,0xff,0xc0,0x80,0x00,0x40,0x80,0x00,0x40,0x80,0x00,0x40,0x80,0x00,0x40,0xff,0xff,0xc0,//3-18
0xff,0xff,0xf8,0x80,0x00,0x08,0x80,0x00,0x08,0x80,0x00,0x08,0x80,0x00,0x08,0xff,0xff,0xf8,//3-21
0xff,0xff,0xff,0x80,0x00,0x01,0x80,0x00,0x01,0x80,0x00,0x01,0x80,0x00,0x01,0xff,0xff,0xff,//3-24
0xff,0xff,0xff,0xe0,0x80,0x00,0x00,0x20,0x80,0x00,0x00,0x20,0x80,0x00,0x00,0x20,0x80,0x00,0x00,0x20,0xff,0xff,0xff,0xe0,//4-27
0xff,0xff,0xff,0xfc,0x80,0x00,0x00,0x04,0x80,0x00,0x00,0x04,0x80,0x00,0x00,0x04,0x80,0x00,0x00,0x04,0xff,0xff,0xff,0xfc,//4-30
0xff,0xff,0xff,0xff,0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x80,0xff,0xff,0xff,0xff,0x80,//5-33
0xff,0xff,0xff,0xff,0xf0,0x80,0x00,0x00,0x00,0x10,0x80,0x00,0x00,0x00,0x10,0x80,0x00,0x00,0x00,0x10,0x80,0x00,0x00,0x00,0x10,0xff,0xff,0xff,0xff,0xf0,//5-36
0xff,0xff,0xff,0xff,0xfe,0x80,0x00,0x00,0x00,0x02,0x80,0x00,0x00,0x00,0x02,0x80,0x00,0x00,0x00,0x02,0x80,0x00,0x00,0x00,0x02,0xff,0xff,0xff,0xff,0xfe,//5-39
0xff,0xff,0xff,0xff,0xff,0xc0,0x80,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x00,0x00,0x00,0x40,0x80,0x00,0x00,0x00,0x00,0x40,0xff,0xff,0xff,0xff,0xff,0xc0,//6-42
0xff,0xff,0xff,0xff,0xff,0xf8,0x80,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x00,0x00,0x00,0x08,0x80,0x00,0x00,0x00,0x00,0x08,0xff,0xff,0xff,0xff,0xff,0xf8,//6-45
0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0x80,0x00,0x00,0x00,0x00,0x01,0xff,0xff,0xff,0xff,0xff,0xff,//6-48
 
};
const TuKuFull[1000]=
{
0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,//1-3//0
0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,//1-6//6
0xff,0x80,0xff,0x80,0xff,0x80,0xff,0x80,0xff,0x80,0xff,0x80,//2-9//12
0xff,0xf0,0xff,0xf0,0xff,0xf0,0xff,0xf0,0xff,0xf0,0xff,0xf0,//2-12//24
0xff,0xfe,0xff,0xfe,0xff,0xfe,0xff,0xfe,0xff,0xfe,0xff,0xfe,//2-15//36
0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xc0,0xff,0xff,0xc0,//3-18//48
0xff,0xff,0xf8,0xff,0xff,0xf8,0xff,0xff,0xf8,0xff,0xff,0xf8,0xff,0xff,0xf8,0xff,0xff,0xf8,//3-21//66
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//3-24
0xff,0xff,0xff,0xe0,0xff,0xff,0xff,0xe0,0xff,0xff,0xff,0xe0,0xff,0xff,0xff,0xe0,0xff,0xff,0xff,0xe0,0xff,0xff,0xff,0xe0,//4-27
0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,0xff,0xff,0xff,0xfc,//4-30
0xff,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0xff,0x80,0xff,0xff,0xff,0xff,0x80,//5-33
0xff,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,0xf0,0xff,0xff,0xff,0xff,0xf0,//5-36
0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xfe,0xff,0xff,0xff,0xff,0xfe,//5-39
0xff,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xff,0xc0,//6-42
0xff,0xff,0xff,0xff,0xff,0xf8,0xff,0xff,0xff,0xff,0xff,0xf8,0xff,0xff,0xff,0xff,0xff,0xf8,0xff,0xff,0xff,0xff,0xff,0xf8,0xff,0xff,0xff,0xff,0xff,0xf8,0xff,0xff,0xff,0xff,0xff,0xf8,//6-45
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//6-48
 
};
void
LcdEmpty(unsigned char XX)
{
//a 高度,b 宽度,c 间距高度,d 间距宽度,e 多少个
//AA开始高度,
//aa高度寄存器
unsigned char i,j,k,a1,a2,hang,lie;
unsigned int a3;
a=3;
b=6;
c=3;
d=2;
e=16;
     

         hang=8;
          
        
        
         
       a1=3;
       a2=1;
       a3=0;
       //for(k=0;k<XX;k++)
       //{
        //a1=XX*a
         switch(XX)
         {
         case 1:a3=0;a2=1;break;
         case 2:  a3=6;a2=1;break;
         case 3:  a3=12;a2=2;break;
         case 4:  a3=24;a2=2;break;
         case 5: a3=36;a2=2;break;
         case 6: a3=48;a2=3;break;
         case 7: a3=66;a2=3;break;
         case 8: a3=84;a2=3;break;
         case 9: a3=102;a2=4;break;
         case 10: a3=126;a2=4;break;
         case 11: a3=150;a2=5;break;
         case 12: a3=180;a2=5;break;
         case 13: a3=210;a2=5;break;
         case 14: a3=240;a2=6;break;
         case 15: a3=276;a2=6;break;
         case 16: a3=312;a2=6;break;
          
         default :break;
         } 
 
         if(XX>8)
         {
           LcdLeft=0;
           XX=XX-8;
          
         }
         else
         LcdLeft=1;
         lie=3+(XX-1)*(b+d);
         
         

          for(j=0;j<a2;j++)
          {
             WrLcd(1,0,LcdLeft,hang+0xb7-j);
             WrLcd(1,0,LcdLeft,lie+0x3f); 
             for(i=1;i<=b;i++)
             WrLcd(0,0,LcdLeft,TuKu[a3+a2*i-a2+j]); 
          }
           
           
         
        
          



       
          
      //}
      
      
}
void
LcdFull(unsigned char XX)
{
//a 高度,b 宽度,c 间距高度,d 间距宽度,e 多少个
//AA开始高度,
//aa高度寄存器
unsigned char i,j,k,a1,a2,hang,lie;
unsigned int a3;
a=3;
b=6;
c=3;
d=2;
e=16;
     

         hang=8;
          
        
        
         
       a1=3;
       a2=1;
       a3=0;
       //for(k=0;k<XX;k++)
       //{
        //a1=XX*a
         switch(XX)
         {
         case 1:a3=0;a2=1;break;
         case 2:  a3=6;a2=1;break;
         case 3:  a3=12;a2=2;break;
         case 4:  a3=24;a2=2;break;
         case 5: a3=36;a2=2;break;
         case 6: a3=48;a2=3;break;
         case 7: a3=66;a2=3;break;
         case 8: a3=84;a2=3;break;
         case 9: a3=102;a2=4;break;
         case 10: a3=126;a2=4;break;
         case 11: a3=150;a2=5;break;
         case 12: a3=180;a2=5;break;
         case 13: a3=210;a2=5;break;
         case 14: a3=240;a2=6;break;
         case 15: a3=276;a2=6;break;
         case 16: a3=312;a2=6;break;
          
         default :break;
         } 
 
         if(XX>8)
         {
           LcdLeft=0;
           XX=XX-8;
          
         }
         else
         LcdLeft=1;
         lie=3+(XX-1)*(b+d);
         
         

          for(j=0;j<a2;j++)
          {
             WrLcd(1,0,LcdLeft,hang+0xb7-j);
             WrLcd(1,0,LcdLeft,lie+0x3f); 
             for(i=1;i<=b;i++)
             WrLcd(0,0,LcdLeft,TuKuFull[a3+a2*i-a2+j]); 
          }
           
           
         
        
          



       
          
      //}
      
} 
void 
LCD_hanzi(unsigned char hang,unsigned char lie,int wordadd,unsigned char wordlen)
{ 
 unsigned char a;
 if(lie<=64)
 {
  LcdLeft=1;   
 }
 else
 {
  LcdLeft=0;
  lie=lie%64;
 }
     wordlen=wordlen*hanzioffet;
	 wordadd=(wordadd-1)*2*hanzioffet;
     if((64-lie)<wordlen)
     {
       WrLcd(1,0,LcdLeft,hang+0xb7);
       WrLcd(1,0,LcdLeft,lie+0x3f);    
       for(a=0;a<=(64-lie);a++)
       {  
        WrLcd(0,0,LcdLeft,hanzi[wordadd+wordlen+a]);     
       }
       WrLcd(1,0,!LcdLeft,hang+0xb7);
       WrLcd(1,0,!LcdLeft,0x40);
       for(a=0;a<(wordlen-(64-lie)-1);a++)
       {  
        WrLcd(0,0,!LcdLeft,hanzi[wordadd+wordlen+64-lie+1+a]);     
       }
	   WrLcd(1,0,LcdLeft,hang+1+0xb7);
       WrLcd(1,0,LcdLeft,lie+0x3f);    
       for(a=0;a<=(64-lie);a++)
       {  
        WrLcd(0,0,LcdLeft,hanzi[wordadd+a]);     
       }
       WrLcd(1,0,!LcdLeft,hang+1+0xb7);
       WrLcd(1,0,!LcdLeft,0x40);
       for(a=0;a<(wordlen-(64-lie)-1);a++)
       {  
        WrLcd(0,0,!LcdLeft,hanzi[wordadd+64-lie+1+a]);     
       }
     }
     else
	 {
	   WrLcd(1,0,LcdLeft,hang+0xb7);
       WrLcd(1,0,LcdLeft,lie+0x3f);     
       for(a=0;a<wordlen;a++)
       {  
        WrLcd(0,0,LcdLeft,hanzi[wordadd+wordlen+a]);     
       }
       WrLcd(1,0,LcdLeft,hang+1+0xb7);
       WrLcd(1,0,LcdLeft,lie+0x3f); 
       for(a=0;a<wordlen;a++)
       {  
        WrLcd(0,0,LcdLeft,hanzi[wordadd+a]);     
       }
	 } 
 
} 
 

⌨️ 快捷键说明

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