#include <reg51.h>
#include <math.h>
#define uchar unsigned char
#define uint unsigned int
#define ON 0
#define OFF 1
sbit PWM=P3^5;
sbit MP=P3^4;
bit FLAG=0;
uchar code dispbit[6]={0x20,0x10,0x08,0x04,0x02,0x01};
uchar code seg[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
//0,1,2,3,4,5,6,7,8,9
uchar disbuf[6]={0,0,0,0,10,10};
uint temp[6];
uint discount=0;
uint timecount=0;//定时的次数
uint T0count=0;
uint hus=0;
uint k=60;
uint Vc;
uint Vs;
uint tm=3000;
uint x;
void t0_serv() interrupt 1
{ T0count++;
}
void t1_serv() interrupt 3
{
PWM=1;
TH1=(65536-tm)/256;
TL1=(65536-tm)%256;
hus++;
if(hus==tm)
{ PWM=0;
TH1=(25536+tm)/256;
TL1=(25536+tm)%256;
}
timecount++;
if(timecount==250)
{
//FLAG=1;
TR0=0;
hus=0;
timecount=0;
Vc=T0count*65536+TH0*256+TL0;
Vs=144;
if(abs(Vc-Vs)>5)
{ tm=abs(k*(Vc-Vs));
T0count=0;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
}
FLAG=1;
TR0=0;
timecount=0;
}
P0=dispbit[discount];
P1=seg[disbuf[discount]];
discount++;
if(discount==6)
{ discount=0;
}
}
void main()
{ uint i;
TMOD=0x15;
TH0=0;
TL0=0;
TH1=(65536-tm)/256;
TL1=(65536-tm)%256;
TR0=1;
TR1=1;
ET0=1;
ET1=1;
EA=1;
while(1)
{ if(FLAG==1)
{ FLAG=0;
x=T0count*65536+TH0*256+TL0;
for(i=0;i<6;i++)
{temp[i]=0;
}
i=0;
while(x/10)
{
temp[i]=x%10;
x=x/10;
i++;
}
temp[i]=x;
for(i=0;i<6;i++)
{
disbuf[i]=temp[i];
}
timecount=0;
T0count=0;
TH0=0;
TL0=0;
T0count=0;
TR0=1;
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
仿真文件及原代码.rar (18个子文件)
仿真文件及原代码
03
04.lnp 54B
04.M51 10KB
04.Opt 912B
04.Uv2 2KB
STARTUP.LST 14KB
1021.PWI 840B
04.hex 4KB
04_Uv2.Bak 2KB
1011.OBJ 8KB
1021.DSN 135KB
1011.c 2KB
Last Loaded 1021.DBK 136KB
STARTUP.A51 6KB
04 8KB
04_Opt.Bak 1KB
1011.hex 4KB
STARTUP.OBJ 749B
1011.LST 5KB
共 18 条
- 1
资源评论
- 小虾爱吃鱼2018-04-01好东西 值得学习
- m0_376603122019-04-12东西还行吧
hb_ma
- 粉丝: 44
- 资源: 18
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功