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

📄 lcd.c

📁 51单片机与LCD接口的C语言驱动程序设计.
💻 C
📖 第 1 页 / 共 5 页
字号:
 E  = 0;
 _nop_();
}

void LcmClear(unsigned char a,unsigned char b,unsigned char c,unsigned char d)
{
 Page = 0;
 Col  = 0;
 for(Page=a;Page<b;Page++)
  for(Col=c;Col<d;Col++)
   WriteData(0);
}

void LcmInit( void )
{
 WriteCommandL(0x3f); //开显示
 WriteCommandM(0x3f);
 WriteCommandR(0x3f);
 
 WriteCommandL(0xc0); //设置起始地址=0
 WriteCommandM(0xc0);
 WriteCommandR(0xc0);

 WriteCommandL(0x3f); //开显示
 WriteCommandM(0x3f);
 WriteCommandR(0x3f);

 LcmClear(0,8,0,192);
 Col = 0;
 Page= 0;
 Locatexy();
}

void LcmPutDots( unsigned char a,unsigned char b,unsigned char c,unsigned char d,unsigned char DotByte )
{
 Page = 0;
 Col  = 0;
 for(Page=a;Page<b;Page++)
 {
  for(Col=c;Col<d;Col++)
  {
   WriteData( DotByte );
  }
 }
}

void LcmPutBMP(unsigned char a,unsigned char b,unsigned char c,unsigned char d,unsigned char *puts )
{
 unsigned int X=0;
 Page = 0;
 Col  = 0;
 for(Page=a;Page<b;Page++)
 {
  for(Col=c;Col<d;Col++)
  {
   WriteData( puts[X] );
   X++;
  }
 }
}

/*void date(void)
{
LcmPutBMP(0,2,42,50,number_0);               //0
LcmPutBMP(0,2,50,58,number_8);               //8年

LcmPutBMP(0,2,62,70,number_0);               //(0-1)月
LcmPutBMP(0,2,70,78,number_5);               //(0-9)月  

LcmPutBMP(0,2,82,90,number_2);                //0-3日
LcmPutBMP(0,2,90,98,number_6);                //0-9日            
}*/
void Delay(unsigned int MS)
{
 unsigned char us,usn;
 while(MS!=0)
 {
  usn = 2; //for 12M
  while(usn!=0)
  {
   us=0xf6;
   while (us!=0){us--;};
   usn--;
  }
  MS--;
 }
}
void key_scan(void)
{  
     if(KEY_YES==0){Delay(100);if(KEY_YES==0){KEY=1;}}
     if(KEY_UP==0){Delay(100);if(KEY_UP==0){KEY=2;a+=1;if(a==5)a=1;}}
     if(KEY_DOWN==0){Delay(100);if(KEY_DOWN==0){KEY=3;a-=1;if(a==0)a=4;}}
     if(KEY_NO==0){Delay(100);if(KEY_NO==0){KEY=4;}}               
}
void main_menu(void)
{    KEY=0;
     for(;;)
     {       
             LcmPutBMP(0,2,2,34,DATE);
             LcmPutBMP(0,2,34,42,Symbol);
             LcmPutBMP(0,2,106,138,TIME);
             LcmPutBMP(0,2,138,146,Symbol);
             LcmPutBMP(2,4,2,66,Company_Profile);
             LcmPutBMP(2,4,66,74,Symbol);
             LcmPutBMP(2,4,100,164,Contact);
             LcmPutBMP(2,4,164,172,Symbol);
             LcmPutBMP(4,6,2,66,Information);
             LcmPutBMP(4,6,66,74,Symbol);
             LcmPutBMP(6,8,2,66,parameters);
             LcmPutBMP(6,8,66,74,Symbol);
             
             LcmPutBMP(0,2,42,50,number_0);               //0
             LcmPutBMP(0,2,50,58,number_8);               //8年

             LcmPutBMP(0,2,62,70,number_0);               //(0-1)月
             LcmPutBMP(0,2,70,78,number_5);               //(0-9)月  

             LcmPutBMP(0,2,82,90,number_2);                //0-3日
             LcmPutBMP(0,2,90,98,number_6);                //0-9日
             
             time_display();
             key_scan();
             if(KEY==4){break;}
             if(a==1)
             {
                    
                     LcmClear(4,8,75,91);
                     LcmClear(2,4,175,191);
                     KEY=0;
                     for(;;)
                     {
                            LcmPutBMP(2,4,75,91,Cursor);
                            if(count_min_1==0){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_0);}
                if(count_min_1==1){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_1);}
                if(count_min_1==2){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_2);}                                //8年
                if(count_min_1==3){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_3);}
                if(count_min_1==4){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_4);}
                if(count_min_1==5){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_5);}
                if(count_min_1==6){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_6);}
                if(count_min_1==7){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_7);}
                if(count_min_1==8){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_8);}
                if(count_min_1==9){LcmClear(0,2,50,58);LcmPutBMP(0,2,50,58,number_9);}
                
                if(count_min_2==0){LcmClear(0,2,42,50);LcmPutBMP(0,2,42,50,number_0);}
                if(count_min_2==1){LcmClear(0,2,42,50);LcmPutBMP(0,2,42,50,number_1);}
                if(count_min_2==2){LcmClear(0,2,42,50);LcmPutBMP(0,2,42,50,number_2);}                                //8年
                if(count_min_2==3){LcmClear(0,2,42,50);LcmPutBMP(0,2,42,50,number_3);}
                if(count_min_2==4){LcmClear(0,2,42,50);LcmPutBMP(0,2,42,50,number_4);}
                if(count_min_2==5){LcmClear(0,2,42,50);LcmPutBMP(0,2,42,50,number_5);}
                
                if(count_min_1==0){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_0);}
                if(count_min_1==1){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_1);}
                if(count_min_1==2){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_2);}                                //8年
                if(count_min_1==3){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_3);}
                if(count_min_1==4){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_4);}
                if(count_min_1==5){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_5);}
                if(count_min_1==6){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_6);}
                if(count_min_1==7){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_7);}
                if(count_min_1==8){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_8);}
                if(count_min_1==9){LcmClear(0,2,70,78);LcmPutBMP(0,2,70,78,number_9);}
                
                if(count_min_2==0){LcmClear(0,2,62,70);LcmPutBMP(0,2,62,70,number_0);}
                if(count_min_2==1){LcmClear(0,2,62,70);LcmPutBMP(0,2,62,70,number_1);}
                            key_scan();
                            if(KEY==4){break;}
                            if(a!=1)break;
                            if(KEY==1)
                            {
                                   Delay(300);
                                   if(KEY==1)
                                   {
                                          LcmClear(0,8,0,192);
                                          KEY=0;
                                          for(;;)
                                          {
                                                     LcmPutBMP(0,8,0,192,BMP4);
                                                     key_scan();
                                                     if(KEY==4)
                                                     {         KEY=0;
                                                               LcmClear(0,8,0,192);
                                                               break;
                                                     }
                                           }
                                    }
                             }
                      }
             }
             if(a==2)
             {
                     LcmClear(2,4,75,91);
                     
                     LcmClear(6,8,75,91);
                    
                     for(;;)
                     {
                            LcmPutBMP(4,6,75,91,Cursor);
                            key_scan();
                            if(KEY==4){KEY=0;break;}
                            if(a!=2)break;
                            if(KEY==1)
                            {
                                   Delay(300);
                                   if(KEY==1)
                                   {
                                          LcmClear(0,8,0,192);
                                          for(;;)
                                          {
                                                     LcmPutBMP(0,8,0,192,BMP2);
                                                     key_scan();
                                                     if(KEY==4)
                                                     {         KEY=0;
                                                               LcmClear(0,8,0,192);
                                                               break;
                                                      }
                                           }
                                    }
                             }
                      }
             }
             if(a==3)
             {
                   
                     LcmClear(4,6,75,91);
                     
                     LcmClear(2,4,175,191);
                     for(;;)
                     {
                            LcmPutBMP(6,8,75,91,Cursor);
                            key_scan();
                            if(KEY==4){break;}
                            if(a!=3)break;
                            if(KEY==1)
                            {
                                   Delay(300);
                                   if(KEY==1)
                                   {
                                          LcmClear(0,8,0,192);
                                          KEY=0;
                                          for(;;)
                                          {
                                                     LcmPutBMP(0,8,0,192,BMP3);
                                                     key_scan();
                                                     if(KEY==4)
                                                     {         KEY=0;
                                                               LcmClear(0,8,0,192);
                                                               break;
                                                     }

⌨️ 快捷键说明

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