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

📄 main.c

📁 一个msp430与HGO12864加4*4键盘的菜单程序... ...!
💻 C
📖 第 1 页 / 共 2 页
字号:
           WriteChinese(80, 0 ,20, 0);//"息"
           WriteAbc(96, 0 ,10, 0);//":"
           WriteAbc(32, 2 ,32, 0);//"V"
           WriteAbc(41, 2 ,16, 0);//"E"
           WriteAbc(49, 2 ,28, 0);//"R"
           //WriteAbc(51, 2 ,10, 0);//":"
           WriteAbc(60, 2 ,2, 0);//"2"
           WriteAbc(69, 2 ,11,0); //"."
           WriteAbc(78, 2 ,0, 0); //"0"
           WriteAbc(87, 2 ,0, 0); //"0"
           
           WriteChinese(0, 6 ,9, 0);  //"确"
           WriteChinese(16, 6 ,10, 0);//"认"
          
}
//******************************************************************************
void Init_Port()
{
    //将P1口所有的管脚在初始化的时候设置为输入方式
    P1DIR = 0;
    //将P1口所有的管脚设置为一般I/O口
    P1SEL = 0;
    
    // 将P1.0 P1.1 P1.2 P1.3设置为输出方向
    P1DIR |= BIT4;
    P1DIR |= BIT5;
    P1DIR |= BIT6;
    P1DIR |= BIT7;

   //先输出低电平
    P1OUT = 0x00;
   // 将中断寄存器清零
    P1IE = 0;
    P1IES = 0;
    P1IFG = 0;
    //打开管脚的中断功能
     //对应的管脚由高到低电平跳变使相应的标志置位
    P1IE |= BIT0;      
    P1IES|= BIT0;      
    P1IE |= BIT1;      
    P1IES|= BIT1;
    P1IE |= BIT2;      
    P1IES|= BIT2;      
    P1IE |= BIT3;      
    P1IES |= BIT3;
}

void Delay(unsigned int i)  //延时子程序
{
  while(i--);
}
int KeyProcess(void)
{
       Delay(1000);
     unsigned char  nP10,nP11,nP12,nP13;
        nP10=0;
        nP11=0;
        nP12=0;
        nP13=0;
     int nRes = 0;
        
        //P1.7输出低电平
     P1OUT = ~(BIT7);
        Delay(50);
     
        nP10 = P1IN & BIT0;
     if (nP10 == 0) 
        {
          nRes = 13;
        }
        
        nP11 = P1IN & BIT1;
     if (nP11 == 0)
        {
          nRes = 14;
        }
        
        nP12 = P1IN & BIT2;
     if (nP12 == 0) 
        {
          nRes = 15;
        }
     
        nP13 = P1IN & BIT3;
     if (nP13 == 0) 
        {
          nRes = 16;
        }
        //P1.6输出低电平  
     P1OUT = ~(BIT6);
        Delay(50);
     
        nP10 = P1IN & BIT0;
     if (nP10 == 0) 
        {
          nRes = 9;
          //P5OUT|=BIT5;
        }
     nP11 = P1IN & BIT1;
     if (nP11 == 0) 
        {
          nRes = 10;
          //P5OUT|=BIT5;
        }
        nP12 = P1IN & BIT2;
     if (nP12 == 0) 
        {  
          nRes = 11;
        }
        nP13 = P1IN & BIT3;
     if (nP13 == 0) 
        {
         nRes = 12;
        }
        //P1.5输出低电平
     P1OUT = ~(BIT5);
        Delay(50);
     nP10 = P1IN & BIT0;
     if (nP10 == 0) 
        {
          nRes = 5;
        }
        nP11 = P1IN & BIT1;
     if (nP11 == 0) 
        {
          nRes = 6;
        }
        nP12 = P1IN & BIT2;
        if (nP12 == 0) 
        {
         nRes = 7;
        }
        nP13 = P1IN & BIT3;
     if (nP13 == 0) 
        {
          nRes = 8;
        }
     //P1.4输出低电平
        P1OUT = ~(BIT4);
        nP10 = P1IN & BIT0;
     if (nP10 == 0) 
        {
         nRes = 1;
        }
        nP11 = P1IN & BIT1;
     if (nP11 == 0) 
        {
          nRes = 2;
        }
        nP12 = P1IN & BIT2;
     if (nP12 == 0)
        {
          nRes = 3;
        }
        nP13 = P1IN & BIT3;
     if (nP13 == 0)
        {
          nRes = 4;  
        }
        

     P1OUT = 0x00;//恢复以前值。

     //读取各个管脚的状态

     for(;;)
     {
          if((P1IN&0x0f)==0x0f )
           {
                 
                 break;//等待松开按键
           }
     }
   
     return nRes;
}

// 处理来自端口 1 的中断
#pragma vector=PORT1_VECTOR
__interrupt void PORT1_ISR(void) 
{
  int key_value;
  Delay(1000);
  key_value=KeyProcess();
  switch(key_value)
  {
  case 1://----------------------------"0"-------------------
        if(tempp<10000)
        tempp = tempp*10;
        break;          
  case 2://----------------------------"9"-------------------
        if(tempp<10000)
        tempp = tempp*10+9;
        break;      
  case 3://----------------------------"8"-------------------
        if(tempp<10000)
        tempp = tempp*10+8;
        break; 
  case 4://----------------------------"7"-------------------
        if(tempp<10000)
        tempp = tempp*10+7;
        break;
  case 5://----------------------------"."------------------- 
        
        break; 
  case 6://----------------------------"6" ------------------
        if(tempp<10000)
        tempp = tempp*10+6;
        break; 
  case 7://----------------------------"5" ------------------
        if(tempp<10000)
        tempp = tempp*10+5;
        break; 
  case 8://----------------------------"4" ------------------   
        if(tempp<10000)
        tempp = tempp*10+4;
        break;
  case 9://----------------------------"kong" ---------------
        tempp =(long int)tempp/10;       
        break; 
  case 10://---------------------------"3" ------------------
        if(tempp<10000)
        tempp = tempp*10+3;      
        break; 
  case 11://---------------------------"2" ------------------
        if(tempp<10000)
        tempp = tempp*10+2;     
        break; 
  case 12://---------------------------"1" ------------------
        if(tempp<10000)
        tempp = tempp*10+1;
        break;
  case 13://---------------------------"取消"----------------
          //取消键,找出新的菜单状态编号
        KeyFuncIndex=KeyTab[KeyFuncIndex].KeyQuxiao;       
        break; 
  case 14://---------------------------"↓下翻" -------------
          //向下键,找出新的菜单状态编号
        KeyFuncIndex=KeyTab[KeyFuncIndex].KeyDnState;       
        break; 
  case 15://---------------------------"↑上翻" -------------
          //向上键,找出新的菜单状态编号
        KeyFuncIndex=KeyTab[KeyFuncIndex].KeyUpState;       
        break; 
  case 16://---------------------------"确认" ---------------
          //回车键,找出新的菜单状态编号
        KeyFuncIndex=KeyTab[KeyFuncIndex].KeyCrState;    
        break;  
  default:  break;       
  }
  KeyFuncPtr=KeyTab[KeyFuncIndex].CurrentOperate;
  (*KeyFuncPtr)();//执行当前按键的操作   
  
   if(P1IFG & BIT0)
    {          
         P1IFG &= ~(BIT0);// 清除中断标志位
    }
    if(P1IFG & BIT1)
    {
         P1IFG &= ~(BIT1);// 清除中断标志位
    }
    if(P1IFG & BIT2)
    {
         P1IFG &= ~(BIT2);// 清除中断标志位
    }
     if(P1IFG & BIT3)
    {
         P1IFG &= ~(BIT3);// 清除中断标志位
    }       
}

void main()
{
  WDTCTL=WDTPW+WDTHOLD;  //禁止看门狗
  //Init_Port(); //键盘初始化
  //_EINT();     //打开中断
  //***液晶初始化******
  Init();
  LcdInit();
  ClearSree(0);//清屏
  WriteBmp(0,0,0,64,128); 
  d0_3_1();
}
 

⌨️ 快捷键说明

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