51单片机外部中断int0应用电路原理图如下:
单片机源程序如下:
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code DSY_CODE[]=
- {
- 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x7f,0x6f,0x00
- };
- uchar Display_Buffer[3]={0,0,0};//依次存放个位,十位,百位
- uint Count = 0;
- sbit Clear_Key = P3^6;
- void Show_Count_ON_DSY()
- {
- Display_Buffer[2] = Count / 100; //取百位值
- Display_Buffer[1] = Count % 100 /10; //取十位值
- Display_Buffer[0] = Count % 10; //取个位置
- if(Display_Buffer[2]==0)
- {
- Display_Buffer[2] = 0x0a;
- if(Display_Buffer[1]==0)
- {
- Display_Buffer[1]=0x0a;
- }
- }
- P0 = DSY_CODE[Display_Buffer[0]];
- P1 = DSY_CODE[Display_Buffer[1]];
- P2 = DSY_CODE[Display_Buffer[2]];
- }
- void main()
- {
- P0 = 0xff; //关闭所有的数码管显示
- P1 = 0xff;
- P2 = 0xff;
- IE = 0x81; //0x81=10000001B,定义:EA/-/ET2/ES/ET1/EX1/ET0/EX0。打开EA总中断开和EX0外部中断开关。
- IT0 = 1; //跳变沿出发方式(下降沿)
- while(1)
- {
- if(Clear_Key == 0)
- Count = 0;
- Show_Count_NO_DSY();
- }
- }
- void EX_INT0() interrupt 0 //外部中断0服务函数
- {
- Count ++;
- }
复制代码 知识点:1 数码管段码表
共阴数码管段码表
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
共阳段码表
unsigned char code stab[]={0xff,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
所有资料51hei提供下载:
001INT0中断计数.docx
(120.56 KB, 下载次数: 8)
|