从60秒到30秒再到90秒并循环倒计时显示。
----
有点不好理解。
从60秒到30秒,看来,是倒计时。
到了30之后,怎么办?是立即改为90吗?
到了90之后,再怎么办?是立即改为60吗?
#include <AT89X51H>
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsigned char second;
unsigned char tcount;
void main(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
tcount=0;
second=0;
P0=dispcode[second/10];
P2=dispcode[second%10];
while(1)
{
if(TF0==1)
{
tcount--;
if(tcount==0)
{
tcount=15;
second--;
if(second==0)
{
second=15;
}
P0=dispcode[second/10];
P2=dispcode[second%10];
}
TF0=0;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
}
}
假设P0 P2接数码管,静态驱动,程序如下:
include<reg52h>
#define uchar unsigned char
#define uint unsigned int
uchar num=100;
uchar time=0;
//共阴数码管七段码
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d, 0x07,0x7f,0x6f,0x77};
void Delay1ms(uint i) //1ms延时程序
{
uint j;
for(;i>0;i--)
{
for(j=0;j<164;j++)
{;}
}
}
void main(void )//主程序
{
TMOD=0X01;
ET0=1;
EA=1;
TH0=(65536-50000)/256;//定时50ms
TL0=(65536-50000)%256;
TR0=1;
while(1)
{
P0=table[num/10];
Delay1ms(2);
P2=table[num%10];
Delay1ms(2);
}
}
void TIMER0()interrupt 1//中断程序
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
if(time==20)
{
time=0;
num--;
}
if(num==0)
{
num=100;
}
}
你把减一的程序弄到主程序main的while里边,在运行while之前加一个while按键判断子程序,将按键与p1口连接,当p10=0时结束while。
while(1)
{
if(p1_0==0)
delay(10); 消抖
if(p1_0==0)
while(p1_0!=0)
break;
}
# include<reg52h>
typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long uint32;
uint8 code number[]={0xc0,0xf9,0xa4,0xb0,
0x99,0x92,0x82,0xf8,
0x80,0x90,0x88,0x83,
0xa7,0xa1,0x86,0x8e,
};
int a[4];
uint16 counter = 0;
sbit ADDR0 = P3^2;
sbit ADDR1 = P3^1;
sbit ADDR2 = P3^0;
sbit ADDR3 = P2^6;
void delay();
void timer1_init()
{
TMOD|= 0x10;
TMOD&=0x10;
TH1 = 0xFC;
TL1 = 0x67;
TR1 = 1;
}
void int_init()
{
ET1 = 1;
EA = 1;
}
void refresh_led( )
{
static uint8 j = 0;
switch(j)
{
case 0:ADDR0 = 1;ADDR1 = 1;ADDR2 = 1;ADDR3 = 0;j++;P1=number[a[0]];break;
case 1:ADDR0 = 1;ADDR1 = 1;ADDR2 = 0;ADDR3 = 1;j++;P1=number[a[1]];break;
case 2:ADDR0 = 1;ADDR1 = 0;ADDR2 = 1;ADDR3 = 1;j++;P1=number[a[2]];break;
case 3:ADDR0 = 0;ADDR1 = 1;ADDR2 = 1;ADDR3 = 1;j=0;P1=number[a[3]];break;
default:break;
}
}
void main()
{
ADDR3 = 1;
timer1_init();
int_init();
while(1);
}
void interrupt_timer1() interrupt 3
{
static uint32 sec = 0;
TH1 = 0xFC;
TL1 = 0x67;
counter++;
if(counter==1000)
{
sec++;
counter=0;
a[0]=sec%10;
a[1]=sec/10%10;
a[2]=sec/100%10;
a[3]=sec/1000%10;
}
refresh_led( );
}
以上就是关于求C51单片机汇编语言控制两位数码管倒计时程序,从60秒到30秒再到90秒并循环倒计时显示。全部的内容,包括:求C51单片机汇编语言控制两位数码管倒计时程序,从60秒到30秒再到90秒并循环倒计时显示。、倒计时器 c语言程序 单片机c51、如何用C51单片机做出以下程序 “秒表是倒计时,从100秒开始倒计时 用数码管实时显示当前计时值”等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)