单片机使用循环实现秒计时器
1.仿真电路(软件为Proteus)
使用三极管作为流控开关
2.程序(软件为keil)
#include <reg52.h> //52头文件
#define uchar unsigned char //定义方便后面使用
#define uint unsigned int
uchar code SegCode[] = //seg code;定义显示字形码
{
0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar code BitCode[] = //bit code;
{
0xfe,0xfd,0xfb,0xf7};
uchar DispBuf[4];
uint Count=0; //定义计时器变量
void DelayMs(uint n) //延时
{
uchar j;
while (n--) //11.0592MHz--113
{
for (j = 0; j < 113; j++);
}