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

單片機計數器的設計

發布時間: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,這個變數即計數值

閱讀全文

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

熱點內容
黑月編譯器優缺點 瀏覽:683
線刷包為啥要解壓 瀏覽:147
伺服器滑道怎麼安裝 瀏覽:698
手游發貨伺服器是什麼 瀏覽:709
文件夾的各個名稱 瀏覽:722
安卓系統哪個文件夾存放密碼文件 瀏覽:361
傳真伺服器什麼意思 瀏覽:249
stm3251單片機 瀏覽:279
怎麼做程序員男友 瀏覽:826
信道編解碼作用 瀏覽:838
程序員零基礎學習 瀏覽:201
網卡加密視頻 瀏覽:628
命令按鈕的代碼 瀏覽:853
androidjson編碼 瀏覽:500
筆記本rpc伺服器不可用怎麼進入桌面 瀏覽:946
哪個app開發好 瀏覽:266
java封裝與調用方法 瀏覽:288
自學編程找不到工作 瀏覽:356
招行app余額在哪裡 瀏覽:832
編譯target 瀏覽:910