這是我做的電子設計,用了兩個星期。和C語言代碼。
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
D%9QTNT9B~04H34~[(GJ5$J.png (69.07 KB, 下載次數: 57)
下載附件
2021-6-22 21:07 上傳
9IP4Y[Z%A$[ECDK)BY_CUO9.png (258.27 KB, 下載次數: 52)
下載附件
2021-6-22 21:07 上傳
單片機源程序如下:
- #include<regx51.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define LED P0
- sbit CS2 = P2^2;
- sbit CS1 = P2^1;
- uchar count;
- uchar counth,countl;
- const uchar tab[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
- unsigned int temp;
- unsigned int fin;
- void delayms()//延時函數
- {
- uint i;
- for(i=0; i<130; i++);
- }
- void it0(void) interrupt 0 using 1
- {
-
- if(temp==1&&count!=0&&fin==0){
- count--;
- temp=0;
- }else{
- temp=1;
- }
- fin=1;
- }
- void it2(void) interrupt 2 using 2
- {
- if(temp==1&&count<99&&fin==1){
- fin=0;
- count++;
- temp=0;
- }else{
- temp=1;
- }
- fin=0;
- }
- void main(void)
- {
- IT0=1;
- IT1=1;
- EA=1;
- EX0=1;
- EX1=1;
- PX1=1;
- fin=1;
- while(1){
- counth=count/10;
- countl=count%10;
- LED= tab[countl];
- CS2=1;
- delayms();
- CS2=0;
- LED=tab[counth];
- CS1=1;
- delayms();
- CS1=0;
- }
- }
復制代碼 由于我是新手以上資料肯定存在一些錯誤,歡迎大家批評指正,一起學習 提高技術(僅供參考 切勿照搬)
|