標(biāo)題: 基于Proteus和Keil C的程序開發(fā) 計數(shù)顯示器和發(fā)光二極管的簡單應(yīng)用 [打印本頁]
作者: zhuhaiya 時間: 2019-12-14 20:42
標(biāo)題: 基于Proteus和Keil C的程序開發(fā) 計數(shù)顯示器和發(fā)光二極管的簡單應(yīng)用
基于Proteus和KeilC的程序開發(fā)
驗證計數(shù)顯示器的如下功能:可統(tǒng)計按鈕BUT的按壓次數(shù),并將按壓結(jié)果以十進(jìn)制數(shù)形式顯示出來;當(dāng)顯示值達(dá)到99后可自動從1開始,無限循環(huán)。
驗證發(fā)光二極管的如下功能:仿真運行開始時,當(dāng)開關(guān)p3_2閉合時,按一下按鈕p3_4,流水燈全亮,再按一下按鈕,流水燈全滅,然后正式開始流水,從第一個二極管開始每當(dāng)按鈕BUT按壓一次,二極管就亮一次,且再次按壓按鈕時,下一個二極管亮一次,以此類推,循環(huán)往復(fù)。
簡單東西,入門學(xué)習(xí),不喜勿噴
單片機源程序如下:
- #include<reg51.h>
- #define uchar unsigned char
- sbit P3_4=P3^4;
- sbit P3_2=P3^2;
- bit ldelay=0;
- uchar t=0;
- unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66, 0x6d,0x7d,0x07,0x7f,0x6f};
- unsigned char count;
- void delay(unsigned int time){
- unsigned int j=0;
- for(;time>0;time--)
- for(j=0;j<125;j++);
- }
- void main(){
- uchar code ledp[10]={0x00,0xff,0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- uchar ledi;
- TMOD=0x01;
- TH0=0x3c;
- TL0=0xb0;
- TR0=1;
- ET0=1;
- EA=1;
- count=0;
- P0=table[count/10];
- P2=table[count%10];
- while(1){
-
- if(P3_4==0){
- delay(10);
- if(P3_4==0){
- count++;
- if(count==100)
- count=0;
- P0=table[count/10];
- P2=table[count%10];
- while(P3_4==0);}
-
- if(P3_2==0){
-
- if(ldelay) {
- ldelay=0;
- P1=ledp[ledi];
- delay(1000);
- ledi++;
- if(ledi==10) ledi=2;
- }
- }
- }
- }
- }
- timer0() interrupt 1{
- t++;
- if(t==20) {t=0;ldelay=1;}
- TH0=0X3C;TL0=0xb0;
- }
復(fù)制代碼
-
2.png
(71.59 KB, 下載次數(shù): 40)
下載附件
2019-12-14 20:33 上傳
-
1.png
(69.77 KB, 下載次數(shù): 36)
下載附件
2019-12-14 20:33 上傳
-
51hei.png
(6.86 KB, 下載次數(shù): 35)
下載附件
2019-12-15 01:16 上傳
-
-
計數(shù)顯示器與二極管.zip
2019-12-14 20:39 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
132.1 KB, 下載次數(shù): 20, 下載積分: 黑幣 -5
簡單東西,不喜勿噴
作者: 可樂dior 時間: 2020-6-30 16:50
請問有proteus仿真文件嗎?我的顯示不全
歡迎光臨 (http://www.raoushi.com/bbs/) |
Powered by Discuz! X3.1 |