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

📄 key.c

📁 MSP430F1611+LCD12864_st7920+Key刚完成调试.请有需要的朋下载!
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "msp430X16x.h"
#include "KEY.h"
#include "LCDdriver.h"
#include "PCF8563.h"
#include "stdbool.h"

unsigned  char flagA,flagB,flagC,flagD;
 bool           K2_Value,K3_Value;
static unsigned  int  K1_Count=0;
bool           K4_Value;
static unsigned char  Count;


/*
static unsigned char PCF_time[6]={      //将数据暂存于PCF_time
0x18,//秒(vl、00~59BCD码)
0x28,//分(-、00~59BCD码)
0x22,//时(-、-、00~23BCD码)
0x26,//日(-、-、01~31BCD码)
0x06,//世纪月(c、-、-、01~12BCD码)
0x08,//年(00~99BCD码)
};
*/


//延时子程序
void Delay_Interrupt_MS(char ms){
    uint i;
    while(ms--){
    for(i=0; i<800;i++);
    }
}

/*
void Interrupt_Key_Port()
{
 // P2SEL=0x00;//P2口所有引脚设置为一般的IO口
 // P5SEL=0x00;//P5口所有引脚设置为一般的IO口
 // P2DIR=0xFF;//P2口所有引脚设置为输出方向
 // P5DIR=0x7F;//P5口所有引脚设置为输出方向
  
 // P4DIR=0XFF;
 // P4SEL=0X00;
  
  P1DIR=0x00;
  P1SEL=0X00;  // 所有引脚为一般引脚
  //P1OUT=0X00;  //所有引脚为输入引脚
  P1IE|=0xf0;
  P1IES|=0xf0;
}
*/

void Lcd_Fill_Area_AllWhite()
{  
  Fill_Area(16,16,2,16,0);
  Fill_Area(16,48,2,16,0);
  Fill_Area(16,80,2,16,0);
  Fill_Area(32,16,2,16,0);
  Fill_Area(32,48,2,16,0);
  Fill_Area(32,80,2,16,0);  
}

void Lcd_Fill_Area_AllBlack()
{
  Fill_Area(16,16,2,16,1);
  Fill_Area(16,48,2,16,1);
  Fill_Area(16,80,2,16,1);
  Fill_Area(32,16,2,16,1);
  Fill_Area(32,48,2,16,1);
  Fill_Area(32,80,2,16,1);  
}
void Intrrupt_K4_Value()
{
  
    if(flagD&0x08)
    {   //Delay_Interrupt_MS(10);
      //WriteCommand(0x90);
      //for(i=0;i<16;i++) WriteData(Data4[i]);
      //得到K4_Value的真值   确认后将所有黑幕 清除
      if(K4_Value)
      {
       Lcd_Fill_Area_AllWhite();
        //将所有的整数值及布尔值 清0及
       K1_Count=0;
       K2_Value=false;
       K3_Value=false;
       K4_Value=false;
      }
      flagD=0x00;
    }
}
void Intrrupt_K3_Value()
{
   if(flagC&0x04)
    {  //Delay_Interrupt_MS(10);
      flagC=0x00;
      //得到K3_Value的真值
      
      if(K3_Value)
      {
        K3_Value=false;
        switch(Count)     //值减1后再从新设置
        {
        case 1:
          {
            PCF_time[5]=PCF_time[5]-1;   //年月日的显示是倒的 如果是Count+5的话刚永远写的是"年"
            if(PCF_time[5]>=0x0a&&PCF_time[5]<=0x0f)
            {
              PCF_time[5]=0x09;
            }
            else if(PCF_time[5]>=0x1a&&PCF_time[5]<=0x1f)
            {
              PCF_time[5]=0x19; 
            }
            else if(PCF_time[5]>=0x2a&&PCF_time[5]<=0x2f)
            {
              PCF_time[5]=0x29; 
            }
            else if(PCF_time[5]>=0x3a&&PCF_time[5]<=0x3f)
            {
              PCF_time[5]=0x39;
            }
            else if(PCF_time[5]>=0x4a&&PCF_time[5]<=0x4f)
            {
              PCF_time[5]=0x49; 
            }
            else if(PCF_time[5]>=0x5a&&PCF_time[5]<=0x5f)
            {
              PCF_time[5]=0x59; 
            }
            else if(PCF_time[5]>=0x6a&&PCF_time[5]<=0x6f)
            {
              PCF_time[5]=0x69; 
            }
            else if(PCF_time[5]>=0x7a&&PCF_time[5]<=0x7f)
            {
              PCF_time[5]=0x79; 
            }
            else if(PCF_time[5]>=0x8a&&PCF_time[5]<=0x8f)
            {
              PCF_time[5]=0x80; 
            }
            else if(PCF_time[5]>=0x9a&&PCF_time[5]<=0x9f)
            {
              PCF_time[5]=0x00; 
            }
            //PCF_time[Count+5]=PCF_time[Count+5]-1;   //年月日的显示是倒的
            SetTime();
          }        break;
        case 2:
          {
            PCF_time[4]=PCF_time[4]-1;
            if(PCF_time[4]>=0x0a&&PCF_time[4]<=0x0f)
            {
              PCF_time[4]=0x09;
            }
            SetTime();
          }          break;
        case 3:
          {
            PCF_time[3]=PCF_time[3]-1;
            if(PCF_time[3]>=0x0a&&PCF_time[3]<=0x0f)
            {
              PCF_time[3]=0x09;
            }
            else if(PCF_time[3]>=0x1a&&PCF_time[3]<=0x1f)
            {
              PCF_time[3]=0x19; 
            }
            else if(PCF_time[3]>=0x2a&&PCF_time[3]<=0x2f)
            {
              PCF_time[3]=0x29; 
            }
            SetTime();
          }          break;
        case 4:
          {
            PCF_time[2]=PCF_time[2]-1;
            if(PCF_time[2]>=0x0a&&PCF_time[2]<=0x0f)
            {
              PCF_time[2]=0x09;
            }
            else if(PCF_time[2]>=0x1a&&PCF_time[2]<=0x1f)
            {
              PCF_time[2]=0x19; 
            }
            
            SetTime();
          }          break;
        case 5:    // 分
          {
            PCF_time[1]=PCF_time[1]-1;
            if(PCF_time[1]>=0x0a&&PCF_time[1]<=0x0f)
            {
              PCF_time[1]=0x09;
            }
            else if(PCF_time[1]>=0x1a&&PCF_time[1]<=0x1f)
            {
              PCF_time[1]=0x19; 
            }
            else if(PCF_time[1]>=0x2a&&PCF_time[1]<=0x2f)
            {
              PCF_time[1]=0x29; 
            }
            else if(PCF_time[1]>=0x3a&&PCF_time[1]<=0x3f)
            {
              PCF_time[1]=0x39;
            }
            else if(PCF_time[1]>=0x4a&&PCF_time[1]<=0x4f)
            {
              PCF_time[1]=0x49; 
            }
            else if(PCF_time[1]>=0x5a&&PCF_time[1]<=0x5f)
            {
              PCF_time[1]=0x59; 
            }
            SetTime();
          }          break;
        case 6:
          {
            PCF_time[0]=PCF_time[0]-1;
            if(PCF_time[0]>=0x0a&&PCF_time[0]<=0x0f)
            {
              PCF_time[0]=0x09;
            }
            else if(PCF_time[0]>=0x1a&&PCF_time[0]<=0x1f)
            {
              PCF_time[0]=0x19; 
            }
            else if(PCF_time[0]>=0x2a&&PCF_time[0]<=0x2f)
            {
              PCF_time[0]=0x29; 
            }
            else if(PCF_time[0]>=0x3a&&PCF_time[0]<=0x3f)
            {
              PCF_time[0]=0x39;
            }
            else if(PCF_time[0]>=0x4a&&PCF_time[0]<=0x4f)
            {
              PCF_time[0]=0x49; 
            }
            else if(PCF_time[0]>=0x5a&&PCF_time[0]<=0x5f)
            {
              PCF_time[0]=0x59; 
            }
            SetTime();
          }           break;    
        default :
          {
            for(unsigned char t=0;t<0x10;t--);
          }         // break;
                    
        }        
       // K3_Value=false;     // 直接从default 跳出从而没有将K3_Value赋值
      }
      
      //flagC=0x00;
    }
}
void Intrrupt_K2_Value()
{
  if(flagB&0x02)
    {  //Delay_Interrupt_MS(10);
      flagB=0x00;
      //得到K2_Value的真值.
      if(K2_Value)
      { 
         K2_Value=false; 
        //GetTime();
        switch(Count)
        {
        case 1:        //将值加工1后再写入到PCF8563
          {
            PCF_time[5]=PCF_time[5]+1;     //如果大于9,为10 如>19 则为20 .>29 则为30. >39 则为40 . >49 为50  >59 则为 00 
            //SetTime();
             //Time_Add_Chk(*PCF_time);
            if(PCF_time[5]==0x0A)
            {
              PCF_time[5]=0x10; 
            }
            else if(PCF_time[5]==0x1A)
            {
             PCF_time[5]=0x20;  
            }
            else if(PCF_time[5]==0x2A)
            {
              PCF_time[5]=0x30; 
            }
            else if(PCF_time[5]==0x3a)
            {
              PCF_time[5]=0x40; 
            }
            else if(PCF_time[5]==0x4A)
            {
              PCF_time[5]=0x50; 
            }
            else if(PCF_time[5]==0x5A)
            {
              PCF_time[5]=0x60; 
            }
            else if(PCF_time[5]==0x6A)
            {
              PCF_time[5]=0x70; 
            }
            else if(PCF_time[5]==0x7A)
            {
              PCF_time[5]=0x80; 
            }
            else if(PCF_time[5]==0x8A)
            {
              PCF_time[5]=0x90; 
            }
            else if(PCF_time[5]==0x9A)
            {
              PCF_time[5]=0x00; 
            }                
            SetTime();
          }   ;      break;
        case 2:         // 月
          {
            PCF_time[4]=PCF_time[4]+1;
           
            if(PCF_time[4]==0x0A)
            {
              PCF_time[4]=0x10;
            }
            else if(PCF_time[4]==0x13)
            {
             PCF_time[4]=0x00; 
            }                     
            SetTime();
          } ;        break;
        case 3:     //   日
          {
            PCF_time[3]=PCF_time[3]+1;
            if(PCF_time[3]==0x0A)
            {
              PCF_time[3]=0x10;
            }
            else if(PCF_time[3]==0x1A)
            {
             PCF_time[3]=0x20; 
            }
            else if(PCF_time[3]==0x2A)
            {
              PCF_time[3]=0x30;
            }
            else if(PCF_time[3]==0x31)
            {
              PCF_time[3]=0x00;
            }
            SetTime();     
          }     ;    break;
        case 4:       //  时
          {
            PCF_time[2]=PCF_time[2]+1;
            if(PCF_time[2]==0x0A)
            {
              PCF_time[2]=0x10;
            }
            else if(PCF_time[2]==0x1A)
            {
             PCF_time[2]=0x20; 
            }
            else if(PCF_time[2]==0x24)
            {
              PCF_time[2]=0x00;
            }
            
            SetTime();
          }     ;    break;
        case 5:     //  分
          {
            PCF_time[1]=PCF_time[1]+1;
            if(PCF_time[1]==0x0A)
            {
              PCF_time[1]=0x10;
            }
            else if(PCF_time[1]==0x1A)
            {
             PCF_time[1]=0x20; 
            }
            else if(PCF_time[1]==0x2A)
            {
              PCF_time[1]=0x30;
            }
            else if(PCF_time[1]==0x3a)
            {
              PCF_time[1]=0x40; 
            }
            else if(PCF_time[1]==0x4A)
            {
              PCF_time[1]=0x50; 
            }
            else if(PCF_time[1]==0x5A)
            {
              PCF_time[1]=0x00; 
            }
            SetTime();
          }      ;   break;
        case 6:   //   秒
          {
            PCF_time[0]=PCF_time[0]+1;
            if(PCF_time[0]==0x0A)
            {
             PCF_time[0]=0x10;
            }
            else if(PCF_time[0]==0x1A)
            {
             PCF_time[0]=0x20; 
            }
            else if(PCF_time[0]==0x2A)
            {
              PCF_time[0]=0x30;
            }
            else if(PCF_time[0]==0x3a)
            {
              PCF_time[0]=0x40; 
            }
            else if(PCF_time[0]==0x4A)
            {
              PCF_time[0]=0x50; 
            }
            else if(PCF_time[0]==0x5A)
            {
              PCF_time[0]=0x00; 
            }
            SetTime();
          }      ;   break;
        default:
          {
            for(unsigned char i=0;i<0x10;i++); 
          }        // break;
                      
        }
        // K2_Value=false;  
      }
         
      //flagB=0x00;
    }
}
void Intrrupt_K1_Count()
{
  Count=K1_Count%7;   
    if(flagA&0x01)
    {
      // 得到K1_Count 的值将之放到相应用的LCD12864的显示位置.
     // Count=K1_Count%6;     //是总数年的和才会显示正确
       //Delay_Interrupt_MS(10);
      flagA=0x00;
      switch(Count)
      {
      case 1:     //直接先将所有清0 再将选定的区域画面
        { 
          Lcd_Fill_Area_AllWhite();
          Fill_Area(16,16,2,16,1);   
        }         break;//黑背景
      case 2: 
        {
          Lcd_Fill_Area_AllWhite();
          Fill_Area(16,48,2,16,1);    
        }         break;
      case 3: 
        {
          Lcd_Fill_Area_AllWhite();
          Fill_Area(16,80,2,16,1);    
        }         break; 
      case 4:
        {
          Lcd_Fill_Area_AllWhite();
          Fill_Area(32,16,2,16,1);    
        }         break; 
      case 5: 
        { 
          Lcd_Fill_Area_AllWhite();
          Fill_Area(32,48,2,16,1);    
        }         break;
      case 6: 
        {
          Lcd_Fill_Area_AllWhite();
          Fill_Area(32,80,2,16,1);   
        }         break;
      default:
        {
           for(unsigned char i=0;i<0x10;i++);
            //  Lcd_Fill_Area_AllWhite();
            //  Fill_Area(16,16,2,16,1);    //默认为'年'字背景为黑  

⌨️ 快捷键说明

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