把下述代码添加注释#include "reg51.h" unsigned char led_mod[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71}; unsigned char count = 0; sbit P04 = P0^4; int0_key() interrupt 0{ P04 = !P04; } int1_key() interrupt 2{ P2 = led_mod[count]; if (++count>=0x10) count=0; } void main(){ IT0=IT1=EX0=EX1=EA=1; P2 = 0; while(1); }
时间: 2024-04-06 17:28:46 浏览: 164
duojikongzhi.rar_Unsigned_c++include <reg51>
// 引入reg51头文件
#include "reg51.h"
// 定义LED显示模式数组
unsigned char led_mod[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x58,0x5e,0x79,0x71};
// 定义计数器
unsigned char count = 0;
// 定义P0.4引脚的别名
sbit P04 = P0^4;
// 定义外部中断0的中断函数
int0_key() interrupt 0{
P04 = !P04;
}
// 定义外部中断1的中断函数
int1_key() interrupt 2{
// 在LED数码管上显示计数器对应的值
P2 = led_mod[count];
// 计数器加1,当达到0x10时,重新计数
if (++count>=0x10) count=0;
}
void main(){
// 开启外部中断0和1,以及总中断
IT0=IT1=EX0=EX1=EA=1;
// 初始化LED数码管
P2 = 0;
// 进入死循环
while(1);
}
阅读全文