标题:
四位数秒器陈序及电路图,有点简陋
[打印本页]
作者:
醉孤辰
时间:
2017-4-25 20:03
标题:
四位数秒器陈序及电路图,有点简陋
四位.png
(14.08 KB, 下载次数: 54)
下载附件
2017-4-25 20:02 上传
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code SegCode[]=
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
uchar code BitCode[]={0xfe,0xfd,0xfb,0xf7};
uchar DispBuf[4];
uint Count;
void DelayMs(uchar n)
{
uchar j;
while(n--)
{
for(j=0;j<113;j++);
}}
void NumToBuf(void)
{
DispBuf[3]=Count/1000;
DispBuf[2]=Count/100%10;
DispBuf[1]=Count/10%10;
DispBuf[0]=Count%10;
}
void BufToSeg(void)
{
uchar i;
for(i=0;i<4;i++)
{
P0=SegCode[DispBuf[i]];
P2=BitCode[i];
DelayMs(2);
P2|=0x0F;
}}
void main(void)
{
uint k;
while(1)
{
if(++k==220)
{
k=0;
if(++Count==10000)Count=0;
}
NumToBuf();
BufToSeg();
}}
复制代码
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1