【Proteus仿真】51单片机定时器计数+共阴数码管驱动显示
- 📌相关篇《【Proteus仿真】51单片机定时器使用》
- 🔖Proteus仿真基础实验-
定时器计数+共阴数码管驱动显示60秒倒计时。 - 🌿Proteus8.12平台
- 🌿本实验代码基于VSM Studio,采用SDCC编译器。
- 🎬仿真演示:


📝示例代码
#include
#define FOSC 11059200L#define T1MS (65536-FOSC/12/1000) #define wei1 (P2_0)
#define wei2 (P2_1)
#define LED (P2_2)
static unsigned int count = 0;
static unsigned int cnt = 0;unsigned char __code table[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f
};void delayms(unsigned int ms)
{unsigned int x;unsigned int y;for (y=ms; y>0; y--){for (x=227; x>0; x--);}
}
void led_off()
{wei1= 1;wei2= 1;
}void Display()
{wei1=0,wei2=1;P0= table[cnt/10];delayms(10);led_off();delayms(2); wei1=1,wei2=0;P0= table[cnt%10];delayms(10);led_off();delayms(2);
}
void Init_Timer0(void)
{TMOD |= 0x01; TL0 = T1MS; TH0 = T1MS >> 8; TR0 = 1; ET0 = 1; EA = 1;
}
void Timer0_isr(void) __interrupt 1 __using 1
{TL0 = T1MS; TH0 = T1MS >> 8; if (count-- == 0) {count = 1000; LED = ! LED; if(cnt-- == 0)cnt = 60;}}void main(void)
{Init_Timer0();led_off();while (1){Display();}
}
📚仿真资源
链接: https:
提取码: svcs
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!