/****************************外部中断0的负边沿触发*******************************
* 描述 : 外部中断,是单片机最基本也是最重要的功能。
P3.2单片机外部中断0的引脚和外部中断0。
每当按下按键的时候,数码管的值会加1.
***********************************************************************/
#include
#define uchar unsigned char
#define uint unsigned int
***it KEY1 = P3^2;
***it KEY2 = P3^3;
uchar Count = 100;
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/********************************************************************
* 名称 : Delay()
* 功能 : 延时,延时时间为 10ms * del
* 输入 : del
* 输出 : 无
***********************************************************************/
void Delay(uint del)
{
uint i,j;
for(i=0; i
for(j=0; j<1827; j++)
;
}
/********************************************************************
* 名称 : Outside_Init()
* 功能 : 外部中断0,1 的初始化
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Outside_Init(void)
{
EX0 = 1; //开外部中断0
IT0 = 1; //负边沿触发
EA = 1; //开总中断
}
/********************************************************************
* 名称 : Outside_Int1()
* 功能 : 外部中断0 的中断处理
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Outside_Int1(void) interrupt 0 using 1
{
Delay(2);
if(KEY1 == 0)
{
Count++;
}
Delay(30);
}
/********************************************************************
* 名称 : Main()
* 功能 : 外部中断试验主程序
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Main(void)
{
Outside_Init();
P2 = 7;
while(1)
{
P0 = table[Count % 10];
Delay(2);
}
}
参考这个自己实现递减 负数 处理长按
/****************************外部中断0的负边沿触发*******************************
* 描述 : 外部中断,是单片机最基本也是最重要的功能。
P3.2单片机外部中断0的引脚和外部中断0。
每当按下按键的时候,数码管的值会加1.
***********************************************************************/
#include
#define uchar unsigned char
#define uint unsigned int
***it KEY1 = P3^2;
***it KEY2 = P3^3;
uchar Count = 100;
uchar code table[10] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
/********************************************************************
* 名称 : Delay()
* 功能 : 延时,延时时间为 10ms * del
* 输入 : del
* 输出 : 无
***********************************************************************/
void Delay(uint del)
{
uint i,j;
for(i=0; i
for(j=0; j<1827; j++)
;
}
/********************************************************************
* 名称 : Outside_Init()
* 功能 : 外部中断0,1 的初始化
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Outside_Init(void)
{
EX0 = 1; //开外部中断0
IT0 = 1; //负边沿触发
EA = 1; //开总中断
}
/********************************************************************
* 名称 : Outside_Int1()
* 功能 : 外部中断0 的中断处理
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Outside_Int1(void) interrupt 0 using 1
{
Delay(2);
if(KEY1 == 0)
{
Count++;
}
Delay(30);
}
/********************************************************************
* 名称 : Main()
* 功能 : 外部中断试验主程序
* 输入 : 无
* 输出 : 无
***********************************************************************/
void Main(void)
{
Outside_Init();
P2 = 7;
while(1)
{
P0 = table[Count % 10];
Delay(2);
}
}
参考这个自己实现递减 负数 处理长按
举报