标题:
这个程序,如果想定时时间为小时,怎样时间到,LED灯灭,调整时间按一次加键,加5...
[打印本页]
作者:
江西奉新
时间:
2019-6-22 15:11
标题:
这个程序,如果想定时时间为小时,怎样时间到,LED灯灭,调整时间按一次加键,加5...
#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int
sbit led=P2^0;
sbit wea=P2^2;
sbit web=P2^3;
sbit wec=P2^4;
sbit fm=P1^5;
sbit sw1=P3^1;
sbit sw2=P3^0;
sbit sw3=P3^2;
sbit sw4=P3^3;
uchar code duma[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
uchar time ,counter,time_counter;
uchar i ;
void delay(uint z);
void delay(uint z)
{
while (z--);
}
void display(uchar i)
{ uchar shi,ge,qie;
shi=i%100/10;
ge=i%10;
qie=i/100;
P0=0XFF;
wea=0;
web=0;
wec=0;
P0=duma[ge];
delay(41);
P0=0XFF;
wea=1;
web=0;
wec=0;
P0=duma[shi];
delay(41);
P0=0XFF;
wea=0;
web=1;
wec=0;
P0=duma[qie];
delay(41);
}
void keypros()
{
if(sw1==0)
{
delay(10);
if(sw1==0)
{
time_counter++;
while(!sw1);
}
}
if(sw2==0)
{
delay(10);
if(sw2==0&&time_counter!=0)
{
time_counter--;
while(!sw2);
}
}
if(sw3==0)
{
delay(10);
if(sw3==0)
{
TR1=0;
led=1;
time_counter=0;
while(!sw3);
}
}
if(sw4==0)
{
delay(10);
if(sw4==0)
{
TR1=~TR1;
led=~led;
while(!sw4);
}
}
}
void init()
{
TMOD=0x10;
TH1=0x4b;
TL1=0x00;
TR1=0;
}
void main()
{
init();
while(1)
{
keypros();
if(TF1==1)
{ TF1=0;
TH1=0x4b;
TL1=0x00;
counter++;
}
if(counter==10)
{
counter=0;
time_counter++;
}
if(time_counter==240)
time_counter=0;
display(time_counter);
}
}
作者:
江西奉新
时间:
2019-6-22 15:14
补充,时间到灯灭,加键,按一次加5分钟,减键一次,减5分钟,定时间为小时,显示为分钟数
作者:
xianfajushi
时间:
2019-6-22 20:14
加5修改: if(sw1==0)time_counter+=5;判断时间的时参数到指定值那么执行LED即可
作者:
xianfajushi
时间:
2019-6-22 20:18
假设这个为定时值判断 if(time_counter==240){ time_counter=0; led=~led;}那么修改判断式中的参数就是你要的小时值
作者:
xianfajushi
时间:
2019-6-23 10:33
把仿真与程序所有打包发出来以便修改
欢迎光临 (http://www.51hei.com/bbs/)
Powered by Discuz! X3.1