<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> MCU設計實例 >> 瀏覽文章

        MSP430f2272單片機中斷控制4X4鍵盤程序

        作者:未知   來源:山澗一溪流   點擊數:  更新時間:2014年06月22日   【字體:
        #include "msp430f2272.h"
        int yu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
                  0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
        int i,j,k,temp,dat,ms;
        void delay(int ms)
        {
          while(ms--)
           for(i=0;i<2;i++);
        }
        int main( void )
        {
          // Stop watchdog timer to prevent time out reset
          WDTCTL = WDTPW + WDTHOLD;
          P1DIR |=0x0f;    
          P2DIR  =0xff;  
           P1IE  |=0xf0;   
          P1IES |=0xf0;   
          P2OUT=yu[0];     
          P1IFG =0x00;
          _EINT(); 
          temp=0xfe;
          while(1)
          {
            temp=0xfe;
            P1OUT=temp;
            delay(5);
            temp=0xfd;
            P1OUT=temp;
            delay(5);
            temp=0xfb;
            P1OUT=temp;
            delay(5);
            temp=0xf7;
            P1OUT=temp;
            delay(5);
          }
        }
         #pragma   vector=PORT1_VECTOR
         __interrupt void Port_ISR(void)
         {   
           switch(temp)
               {
                   case 0xfe:
                     {
                       if(P1IFG==BIT4)dat=0;
                       if(P1IFG==BIT5)dat=1;
                       if(P1IFG==BIT6)dat=2;
                       if(P1IFG==BIT7)dat=3;
                       P2OUT =~yu[dat];
                       P1IFG=0x00;
                       break;
                     }
                   case 0xfd:
                     {
                       if(P1IFG==BIT4)dat=4;
                       if(P1IFG==BIT5)dat=5;
                       if(P1IFG==BIT6)dat=6;
                       if(P1IFG==BIT7)dat=7;
                       P2OUT =~yu[dat];
                       P1IFG=0x00;
                       break;
                     }
                   case 0xfb:
                     {
                       if(P1IFG==BIT4)dat=8;
                       if(P1IFG==BIT5)dat=9;
                       if(P1IFG==BIT6)dat=10;
                       if(P1IFG==BIT7)dat=11;
                        P2OUT =~yu[dat];
                        P1IFG=0x00;
                        break;
                      }
                   case 0xf7:
                     {
                       if(P1IFG==BIT4)dat=12;
                       if(P1IFG==BIT5)dat=13;
                       if(P1IFG==BIT6)dat=14;
                       if(P1IFG==BIT7)dat=15;
                        P2OUT =~yu[dat];
                        P1IFG=0x00;
                        break;
                     }
                   default:break;
               } 
         }
        /*********************************************************/
        #include "msp430f2272.h"
        int yu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
                  0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
        int i,j,k,temp,dat,ms;
        void delay(int ms)
        {
          while(ms--)
           for(i=0;i<2;i++);
        }
        int main( void )
        {
          // Stop watchdog timer to prevent time out reset
          WDTCTL = WDTPW + WDTHOLD;
          P1DIR |=0x0f;    
          P2DIR  =0xff;   
          P1REN |=0xf0;
          P1IE  |=0xf0;   
          P1IES |=0xf0;  
          P2OUT=~yu[6];     
          P1IFG =0x00;
          _EINT();
          temp=0xfe;
          while(1)
          {
            temp=0xfe;
            P1OUT=temp;
            delay(5);
            temp=0xfd;
            P1OUT=temp;
            delay(5);
            temp=0xfb;
            P1OUT=temp;
            delay(5);
            temp=0xf7;
            P1OUT=temp;
            delay(5);
          }
        }
         #pragma   vector=PORT1_VECTOR
         __interrupt void Port_ISR(void)
         {   
           switch(temp)
               {
                   case 0xfe:
                     {
                       if((P1IFG|0xef)==0xff)dat=0;
                       if((P1IFG|0xdf)==0xff)dat=1;
                       if((P1IFG|0xbf)==0xff)dat=2;
                       if((P1IFG|0x7f)==0xff)dat=3;
                       P2OUT =~yu[dat];
                       P1IFG=0x00;
                       break;
                     }
                   case 0xfd:
                     {
                       if((P1IFG|0xef)==0xff)dat=4;
                       if((P1IFG|0xdf)==0xff)dat=5;
                       if((P1IFG|0xbf)==0xff)dat=6;
                       if((P1IFG|0x7f)==0xff)dat=7;
                       P2OUT =~yu[dat];
                       P1IFG=0x00;
                       break;
                     }
                   case 0xfb:
                     {
                        if((P1IFG|0xef)==0xff)dat=8;
                        if((P1IFG|0xdf)==0xff)dat=9;
                        if((P1IFG|0xbf)==0xff)dat=10;
                        if((P1IFG|0x7f)==0xff)dat=11;
                        P2OUT =~yu[dat];
                        P1IFG=0x00;
                        break;
                      }
                   case 0xf7:
                     {
                        if((P1IFG|0xef)==0xff)dat=12;
                        if((P1IFG|0xdf)==0xff)dat=13;
                        if((P1IFG|0xbf)==0xff)dat=14;
                        if((P1IFG|0x7f)==0xff)dat=15;
                        P2OUT =~yu[dat];
                        P1IFG=0x00;
                        break;
                     }
                   default:break;
               } 
         }

         #include "msp430f2272.h"
        int yu[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
                  0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
        int i,j,k,temp,dat,ms;
        void delay(int ms)
        {
          while(ms--)
           for(i=0;i<2;i++);
        }
        int main( void )
        {
          // Stop watchdog timer to prevent time out reset
          WDTCTL = WDTPW + WDTHOLD;
          P1DIR |=0x0f;    
          P2DIR  =0xff;    
          P1REN |=0xf0;
          P1IE  |=0xf0;    
          P1IES |=0xf0;  
          P2OUT=~yu[6];     
          P1IFG =0x00;
          _EINT();
          temp=0xfe;
          while(1)
          {
            temp=0xfe;
            P1OUT=temp;
            delay(5);
            temp=0xfd;
            P1OUT=temp;
            delay(5);
            temp=0xfb;
            P1OUT=temp;
            delay(5);
            temp=0xf7;
            P1OUT=temp;
            delay(5);
          }
        }
         #pragma   vector=PORT1_VECTOR
         __interrupt void Port_ISR(void)
         {   
           if(temp==0xfe)
           {
                    if((P1IFG|0xef)==0xff)dat=0;
                    if((P1IFG|0xdf)==0xff)dat=1;
                    if((P1IFG|0xbf)==0xff)dat=2;
                    if((P1IFG|0x7f)==0xff)dat=3;
                    P2OUT =~yu[dat];
                    P1IFG=0x00;
           }
              if(temp==0xfd)
           {
                    if((P1IFG|0xef)==0xff)dat=4;
                    if((P1IFG|0xdf)==0xff)dat=5;
                    if((P1IFG|0xbf)==0xff)dat=6;
                    if((P1IFG|0x7f)==0xff)dat=7;
                    P2OUT =~yu[dat];
                    P1IFG=0x00;
           }
                 if(temp==0xfb)
           {
                    if((P1IFG|0xef)==0xff)dat=8;
                    if((P1IFG|0xdf)==0xff)dat=9;
                    if((P1IFG|0xbf)==0xff)dat=10;
                    if((P1IFG|0x7f)==0xff)dat=11;
                    P2OUT =~yu[dat];
                    P1IFG=0x00;
           }
                 if(temp==0xf7)
           {
                    if((P1IFG|0xef)==0xff)dat=12;
                    if((P1IFG|0xdf)==0xff)dat=13;
                    if((P1IFG|0xbf)==0xff)dat=14;
                    if((P1IFG|0x7f)==0xff)dat=15;
                    P2OUT =~yu[dat];
                    P1IFG=0x00;
           } 
         }
        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮