|
給51黑電子論壇的朋友們分享一個用51單片機0~9999計數(shù)器程序和proteus仿真,下面是原理圖:
0.png (25.25 KB, 下載次數(shù): 119)
下載附件
2016-10-10 14:34 上傳
源程序:
- /********************************************************************
- 天馬電子
- *********************************************************************/
- #include <reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar duan[10]={0xc0,0Xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90}; //所需的段的位碼
- //uchar wei[4]={0XEf,0XDf,0XBf,0X7f}; //位的控制端 (開發(fā)板)
- uchar wei[4]={0X80,0X40,0X20,0X10}; //位的控制端 (仿真)
- uint z,x,c,v, date; //定義數(shù)據(jù)類型
- uint dispcount=0;
- /******************************************************************
- 延時函數(shù)
- ******************************************************************/
- void delay(uchar t)
- {
- uchar i,j;
- for(i=0;i<t;i++)
- {
- for(j=13;j>0;j--);
- { ;
- }
- }
- }
- /**********************************************************************
- 數(shù)碼管動態(tài)掃描
- *********************************************************************/
- void xianshi()
- {
- /*****************數(shù)據(jù)轉(zhuǎn)換*****************************/
- z=date/1000; //求千位
- x=date%1000/100; //求百位
- c=date%100/10; //求十位
- v=date%10; //求個位
- P2=wei[0];
- P0=duan[z];
- delay(50);
- P2=wei[1];
- P0=duan[x];
- delay(50);
- P2=wei[2];
- P0=duan[c];
- delay(50);
- P2=wei[3];
- P0=duan[v];
- delay(50);
-
- }
- /*************************************************************************
- 主函數(shù)
- **************************************************************************/
- void ExtInt0() interrupt 0 //中斷服務(wù)程序
- {
- dispcount++; //每按一次中斷按鍵,計數(shù)加一
- if (dispcount==9999) //計數(shù)范圍0-9999
- {dispcount=0;}
- }
- /*************************************************************************
- 主函數(shù)
- **************************************************************************/
- void main()
- {
- TCON=0x01; //中斷設(shè)置
- IE=0x81;
- while(1)
- {
- date=dispcount;
- xianshi();
- }
- }
-
復(fù)制代碼
0.png (50.1 KB, 下載次數(shù): 100)
下載附件
2016-10-10 14:34 上傳
仿真工程文件及所有完整程序等資料下載地址(壓縮包一共有45個單片機仿真,全部下載后找到這個項目035即可):
http://www.zg4o1577.cn/bbs/dpj-56298-1.html
|
|