单片机定时

来源:百度知道 编辑:UC知道 时间:2024/06/20 07:22:07
用89c51控制一个定时器,定时时间1-99分钟,用共阳数码管显示,P0口控制数据输入,P2口控制位选,P3^7作为启动键,一按开始倒数计时,另外设置两个键可调节定时时间,急求一高手写程序!!(c语言)

楼上的很搞笑,.....
真不知江湖大侠看了会不会笑喷....
唉,也不知是你看了江湖大侠的会不会笑喷....
总之,我就笑弯了腰....

这个毕竟会花费一定的功夫和时间

别人不会为了你的分花费1到2小时帮你编的,

自己一步步来,先做好显示,调试好后加按键设定,然后加定时加倒计OK,

等你自己做出来后就会发现<<单片机并不是想象中那么复杂>>

#include"reg52.h"
#define uchar unsigned char
sbit aj=P3^7;
uchar m=100;
uchar disbuf[3];
uchar code bit_code[3]={0xfe,0xfd,0xfb};
uchar code dis_code[17]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,
0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xff};//0-f与不显示代码

//用于数码管位延时用
void delay100ms()
{uchar x,y;
for(x=200;x>0;x--)
for(y=124;y>0;y--);
}
//按键延时用
void delay20ms()
{
uchar x,y;
for(x=40;x>0;x--)
for(y=124;y>0;y--);
}
//定时器T0中断
void t0()interrupt 1
{
static m_count;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
m_count++;
if(m_count==2)
{
m_count=0;m--;}
if(m==0)