单片机C语言程序设计:INT0 中断计数
来源: \t "/jichuzhishi/mcu/program/-06-27/_blank" 21ic?作者:
关键字: \t "/jichuzhishi/mcu/program/-06-27/_blank" INT0??? \t "/jichuzhishi/mcu/program/-06-27/_blank" 单片机??? \t "/jichuzhishi/mcu/program/-06-27/_blank" C语言??? \t "/jichuzhishi/mcu/program/-06-27/_blank" 程序设计??? \t "/jichuzhishi/mcu/program/-06-27/_blank" ???
/*??名称:INT0?中断计数
说明:每次按下计数键时触发
INT0?中断,中断程序累加计数,
计数值显示在?3?只数码管上,按下
清零键时数码管清零
*/
#include
#define?uchar?unsigned?char
#define?uint?unsigned?int
//0~9?的段码
uchar?code?DSY_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};
//计数值分解后各个待显示的数位
uchar?DSY_Buffer[]={0,0,0};?
uchar?Count=0;
sbit?Clear_Key=P3^6;
//数码管上显示计数值
void?Show_Count_ON_DSY()
{
DSY_Buffer[2]=Count/100;?//获取?3?个数
DSY_Buffer[1]=Count%100/10;
DSY_Buffer[0]=Count%10;
if(DSY_Buffer[2]==0)???//高位为?0?时不显示
{
DSY_Buffer[2]=0x0a;
????????????????????????? if(DSY_Buffer[1]==0)?//高位为?0,若第二位为?0?同样不显示
???????????????????????? DSY_Buffer[1]=0x0a;
}
P0=DSY_CODE[DSY_Buffer[0]];
P1=DSY_CODE[DSY_Buffer[1]];
P2=DSY_CODE[DSY_Buffer[2]];
}
//主程序
void?main()
{
P0=0x00;
P1=0x00;
P2=0x00;
IE=0x81;?//允许?INT0?中断
IT0=1;?????????//下降沿触发
while(1)
{
if(Clear_Key==0)?Count=0;?//清?0
Show_Count_ON_DSY();
????? }
}
//INT0?中断函数
void?EX_INT0()?interrupt?0?
{
Count++;?计数值递增
}
单片机C语言程序设计:INT0 及 INT1 中断计数
来源: \t "/jichuzhishi/mcu/program/-06-27/_blank" 21ic?作者:
关键字: \t "/jichuzhishi/mcu/program/-06-27/_blank" INT0??? \t "/jichuzhishi/mcu/program/-06-27/_blank" INT1??? \t "/jichuzhishi/mcu/program/-06-27/_blank" 单片机??? \t "/jichuzhishi/mcu/program/-06-27/_blank" C语言??? \t "/jichuzhishi/mcu/program/-06-27/_blank" ???
/*??名称:INT0?及?INT1?中断计数
说明:每次按下第?1?个计数键时,
第?1?组计数值累加并显示在右边?3?只数
码管上,?每次按下第?2?个计数键时,第
2?组计数值累加并显示在左边?3?只数码管上,后两个按键分别清零。
*/
#include
#define?uchar?unsigned?char
#define?uint?unsigned?int
sbit?K3=P3^4;?//2?个清零键
sbit?K4=P3^5;?
//数码管段码与位码
uchar?code?DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
如果觉得《51单片机c语言计数程序 51单片机INTOINT1中断计数c语言源程序.doc》对你有帮助,请点赞、收藏,并留下你的观点哦!