單片機C語言程序設計:INT0 及 INT1 中斷計數(shù)
/* 名稱:INT0 及 INT1 中斷計數(shù)
說明:每次按下第 1 個計數(shù)鍵時,
第 1 組計數(shù)值累加并顯示在右邊 3 只數(shù)
碼管上, 每次按下第 2 個計數(shù)鍵時,第
2 組計數(shù)值累加并顯示在左邊 3 只數(shù)碼管上,后兩個按鍵分別清零。
*/
#includereg51.h>
#define uchar unsigned char
#define uint unsigned int
sbit K3=P3^4; //2 個清零鍵
sbit K4=P3^5;
//數(shù)碼管段碼與位碼
uchar code DSY_CODE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
uchar code DSY_Scan_Bits[]={0x20,0x10,0x08,0x04,0x02,0x01};
//2 組計數(shù)的顯示緩沖,前 3 位一組,后 3 位一組
uchar data Buffer_Counts[]={0,0,0,0,0,0};
uint Count_A,Count_B=0;
//延時
void DelayMS(uint x)
{
uchar t;
while(x--) for(t=0;t120;t++);
}
//數(shù)據(jù)顯示
void Show_Counts()
{
uchar i;
Buffer_Counts[2]=Count_A/100;
Buffer_Counts[1]=Count_A%100/10;
Buffer_Counts[0]=Count_A%10;
{
if( Buffer_Counts[2]==0)
Buffer_Counts[2]=0x0a;
if( Buffer_Counts[1]==0)
}
c語言相關文章:c語言教程
評論