單片機(jī)外部中斷的電平觸發(fā)和邊沿觸發(fā)程序
code:本文引用地址:http://m.butianyuan.cn/article/201612/324167.htm
//電平觸發(fā)
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit D1=P2^0;
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//段選,選擇要顯示的數(shù)字
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//八位數(shù)碼管
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
EA=1;//打開中斷總開關(guān)
EX0=1;//打開外部中斷0,P3.2選通
IT0=0;//選擇電平觸發(fā)方式
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}
void duan() interrupt 0
{
D1=1;
delay(500);
D1=0;
delay(500);
}
//邊沿觸發(fā)方式
#include
#include
#define uint unsigned int
#define uchar unsigned char
sbit D1=P2^0;
uchar num;
uchar wnum=0x00;
uchar code dbit[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//段選,選擇要顯示的數(shù)字
//uchar code wnum[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdF,0xbF,0x7F};//八位數(shù)碼管
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
{
for(y=0;y<113;y++)
{
}
}
}
void main()
{
P1=wnum;
EA=1;//打開中斷總開關(guān)
EX0=1;//打開外部中斷0,P3.2選通
IT0=1;//選擇邊沿觸發(fā)方式
while(1)
{
for(num=0;num<10;num++)
{
P0=dbit[num];
delay(500);
}
}
}
void duan() interrupt 0
{
D1=1;
delay(500);
D1=0;
delay(500);
}
評論