導航:首頁 > 操作系統 > 單片機計數器的設計

單片機計數器的設計

發布時間:2023-08-23 03:23:50

1. 51單片機設計兩位計數器C語言

#include "reg52.h"
#define uchar unsigned char

#define uint unsigned int
#define dataport P1
sbit s1=P2^0;
sbit s2=P2^1;
sbit s3=P2^2;
sbit wei1=P2^4;

sbit wei2=P2^5;
signed char a=0;

uchar TABLE[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

//延時子程序
void delay1ms(uint t)
{
uint i;
uint j;
for(i=0;i<t;i++)
for(j=0;j<116;j++);
}
//顯示子程序
void display(uchar n)
{
wei1=1;

dataport=TABLE[n/10];
delay1ms(1);
wei1=0;

wei2=1;
dataport=TABLE[n%10];
delay1ms(1);
wei2=0;
}

void main(void)//主程序
{
while(1)
{
if(s1==0)
{
delay1ms(20);
if(s1==0)
{
a++;
}
}
if(a=100)a=0;
if(s2==0)
{
delay1ms(20);
if(s2==0)
{
a--;
}
}
if(a<0)a=99;
if(s3==0)
{
delay1ms(20);
if(s3==0)
{
a=0;
}
}
display(a);
}
}

2. C51單片機設計一個遊客流量計數器(00-99),實現對遊客人數的統計。

#include<reg51.h>

#defineucharunsignedchar
uchar派握codeledtab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40};//0-9
ucharscanled;
uchar頃猜disdat[6]={0,0,0,0,0,0};
uchardatin,datout,dath;
display()
{
disdat[0]=datin/10;
disdat[1]=datin%10;
disdat[2]=datout/10;
disdat[3]=datout%10;
disdat[4]=dath/10;
disdat[5]=dath%10;
}
voidext0isr()interrupt0
{
datin++;
datin%=100;
dath=(datin-datout);
display();
}
voidext1isr()interrupt塵乎慶2
{
if(dath>0)datout++;
dath=(datin-datout);
display();
}
voidt1isr()interrupt3 //顯示
{
TH1=0xec;
TL1=0x78;
P2=~(1<<scanled);
P0=ledtab[disdat[scanled]];
scanled++;
scanled%=6;
}
main()
{
TMOD=0x10;
TH1=0xec;
TL1=0x78;
TR1=1;
ET1=1;
EX0=1;
IT0=1;
EX1=1;
IT1=1;
EA=1;
while(1);
}

3. 怎麼用單片機設計一個計數器

把T0設為計數器模式,初值為FFFFH,來一個脈沖即中斷,定義一個變數放在中斷函數里加1,這個變數即計數值

閱讀全文

與單片機計數器的設計相關的資料

熱點內容
python接入sip協議 瀏覽:256
壓縮米怎麼打開 瀏覽:968
簡述keil編譯軟體的使用步驟 瀏覽:852
買什麼安卓機不卡 瀏覽:192
python文件式怎麼弄 瀏覽:652
python對象名調用 瀏覽:9
選房app在哪裡下載 瀏覽:768
中國移動和通訊錄app叫什麼 瀏覽:96
西門子hmi編程軟體 瀏覽:678
寬頻的認證伺服器不通是為什麼 瀏覽:232
linuxg版本 瀏覽:250
程序員都那麼可愛在線觀看 瀏覽:331
android資料庫版本號 瀏覽:269
解壓館是機器人嗎 瀏覽:223
隔膜壓縮機結構 瀏覽:444
android離線下載實現的 瀏覽:144
pdf解壓包密碼怎麼破解 瀏覽:421
51單片機控制57步進電機步數 瀏覽:533
小白學python好還是前端好 瀏覽:152
自製壓縮袋吸氣泵 瀏覽:310