欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: 為什么外部中斷錯(cuò)誤 [打印本頁(yè)]

作者: 1262    時(shí)間: 2017-12-27 17:32
標(biāo)題: 為什么外部中斷錯(cuò)誤


#include "reg52.h"
#include<intrins.h>                         //此文件中定義了單片機(jī)的一些特殊功能寄存器
#define led P2
#define uchar unsigned char
typedef unsigned int u16;          //對(duì)數(shù)據(jù)類(lèi)型進(jìn)行聲明定義
typedef unsigned char u8;
#define uint unsigned int
uchar table[]={0x7e,0xbd,0xdb,0xe7};
#define GPIO_KEY P1
u8 KeyValue;
void delay_ms(uint z)
{
     uint i,j;
     for(i=0;i<z;i++)
     for(j=0;j<110;j++);
}
void delay(u16 i)

{
        while(i--);       
}        //用來(lái)存放讀取到的鍵值
void KEY_Scan(void)
{
        char a=0;
        GPIO_KEY=0x0f;
        if(GPIO_KEY!=0x0f)//讀取按鍵是否按下
        {
                delay(1000);//延時(shí)10ms進(jìn)行消抖
                if(GPIO_KEY!=0x0f)//再次檢測(cè)鍵盤(pán)是否按下
                {       
                        //測(cè)試列
                        GPIO_KEY=0X0F;
                switch(GPIO_KEY)
                        {
                                case(0X07):        KeyValue=1;break;
                                case(0X0b):        KeyValue=2;break;
                                case(0X0d): KeyValue=3;break;
                                case(0X0e):        KeyValue=4;break;
                        }
                        //測(cè)試行
                        GPIO_KEY=0XF0;
                        switch(GPIO_KEY)
                        {
                                case(0X70):        KeyValue=KeyValue;break;
                                case(0Xb0):        KeyValue=KeyValue+4;break;
                                case(0Xd0): KeyValue=KeyValue+8;break;
                                case(0Xe0):        KeyValue=KeyValue+12;break;
                        }
                        while((a<50)&&(GPIO_KEY!=0xf0))         //檢測(cè)按鍵松手檢測(cè)
                        {
                                delay(1000);
                                a++;
                        }
                }
        }
}
void liu()
{           u16 i;
          if(KeyValue==1)
        {

        led =0xfe;
         for(i=0;i<7;i++)            //從左至右亮,每次一盞            
                   {                delay(50000); //大約延時(shí)450ms
                           led=_crol_(led,1);       
                                                   Int0Init();          
                   }
             }
                         
                if(KeyValue==2)
        {
                KeyValue=0;
                led=0x7f;
      for(i=0;i<7;i++)        //將led右移一位
                {                 delay(50000); //大約延時(shí)450ms       
                        led=_cror_(led,1);
                }
                delay(50000);
                led=0xff;               
        }
        }
void time0init()
{
        TMOD=0X01;         //定時(shí)器0工作方式
        TH0=0XFc;
        TL0=0X18;
        TR0=1;
        ET0=1;
        EA=1;
}         
void Int0Init()
{
        //設(shè)置INT0
        IT0=1;//跳變沿出發(fā)方式(下降沿)
        EX0=1;//打開(kāi)INT0的中斷允許。       
        EA=1;//打開(kāi)總中斷       
}

void Int0()        interrupt 0                //外部中斷1的中斷函數(shù)
{
         KEY_Scan();
         if(KeyValue==3)
         {
         led=0x00;
         KeyValue=0;
         }
}
void main()
{  
    time0init();
        while(1);               
}
void tim0() interrupt 1
{
        TH0=0XFc;
        TL0=0X18;
        KEY_Scan();
    liu();               
}



作者: 999333    時(shí)間: 2017-12-27 22:47
復(fù)制void Int0Init();到前面的#include下面就行了,其余的兩個(gè)警告是因?yàn)槟銢](méi)有在void main()也就是主函數(shù)中引用




歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1