四位数码管,初始值显示00.00前面两位为秒,自动记时

这个是不带定时器的,需要带定时器的请看上一个文章

四位数码管,应用定时器中断,初始值显示00.00前面两位为秒,S1按下启动记时,S2按下停止,S3按下清零。-CSDN博客

#include<reg52.h>
unsigned char code SEGMENT_CODE[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};

sbit BIT_P10=P1^0;
sbit BIT_P11=P1^1;
sbit BIT_P12=P1^2;
sbit BIT_P13=P1^3;
sbit LED=P2^0;
unsigned char micro_second=0;
unsigned int second=0;
unsigned int ccc=0;

 void delay_ms(unsigned int x)
 {
 	unsigned int i=0;
 	unsigned int j=0;

 	for(i=0;i<x;i++)
	 {
  		 for(j=0;j<100;j++)
   		{
   
   		}
	 }
 
 }
  void display()
{
   unsigned char w1=0;
   unsigned char w2=0;
   unsigned char w3=0;
   unsigned char w4=0;

	w4=(micro_second/10);
	w3=micro_second%10;
	w1=(second%100)/10;
	w2=(second%10);

	P0=SEGMENT_CODE[w1];
	BIT_P10=0;
	BIT_P11=1;
	BIT_P12=1;
	BIT_P13=1;
	delay_ms(5);
	BIT_P10=1;

	P0=SEGMENT_CODE[w2]|0x80;
	BIT_P10=1;
	BIT_P11=0;
	BIT_P12=1;
	BIT_P13=1;
	delay_ms(5);
	BIT_P11=1;
	
	P0=SEGMENT_CODE[w3];
	BIT_P10=1;
	BIT_P11=1;
	BIT_P12=0;
	BIT_P13=1;
	delay_ms(5);
	BIT_P12=1;

	P0=SEGMENT_CODE[w4];
	BIT_P10=1;
	BIT_P11=1;
	BIT_P12=1;
	BIT_P13=0;
	delay_ms(5);
	BIT_P13=1;
}

  void main()
 {
 	TMOD=0X01;
	TH0=(65536-10000)/256;
	TL0=(65536-10000)%256;
	EA=1;
	ET0=1;
	TR0=1;
	TMOD|=0X01;
       	TH1=(65536-50000)/256;
	TL1=(65536-50000)%256;
	EA=1;
	ET0=1;
	TR1=1;
	  while(1)
	  {
	  display();  
	  }
 }


 void TIMER() interrupt 1
 {
       	TH0=(65536-10000)/256;
	TL0=(65536-10000)%256;
       	micro_second++;
	   if(micro_second>99)
	   {
	       micro_second=0;
		   second++; 
	   }
}

void TIMER1()  interrupt 3
{
  	TH1=(65536-10000)/256;
	 TL1=(65536-10000)%256;
	  ccc++;   
	  if(ccc>=2)
	  {
	  ccc=0;
	  LED=~LED;  
	  }
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wenlong Yang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值