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

單片機計數器的設計

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

閱讀全文

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

熱點內容
網游腳本為什麼要連接伺服器 瀏覽:4
程序員發展路線圖 瀏覽:318
手機語音加密會議 瀏覽:587
冰與火pdf 瀏覽:416
為什麼叫我買阿里雲伺服器 瀏覽:470
加密貨幣征稅一覽表 瀏覽:959
llc編譯器 瀏覽:922
數控可編程電阻器 瀏覽:757
培訓app源碼 瀏覽:431
phpcurl啟用 瀏覽:533
ubuntu圖形編程 瀏覽:441
jar包啟動命令 瀏覽:679
java數組一維轉二維 瀏覽:500
office批量轉pdf 瀏覽:185
boss直聘程序員多少薪 瀏覽:633
編程字母代表什麼 瀏覽:954
rainmc伺服器地址 瀏覽:458
電信校園網客戶端認證伺服器地址 瀏覽:450
掌閱怎麼看文件夾 瀏覽:343
在伴伴app裡面怎麼拜師傅 瀏覽:945