⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 miao biao.txt

📁 用c语言编写的单片机秒表程序
💻 TXT
字号:

#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07, 0x7f,0x6f};
uchar sec; //定义计数值,每过1 秒,sec 加1
uint tcnt; //定时中断次数

sbit gewei=P2^0; //个位选通定义
sbit shiwei=P2^1; //十位选通定义
void Delay(uint tc) //延时程序
{
	while( tc != 0 )
	  {
	    uint i;
		for(i=0; i<100; i++);
		tc--;
	  }
}
void LED() //LED 显示函数
{
	shiwei=0; P0=table[sec%10]; Delay(5); shiwei=1;
	gewei=0; P0=table[sec/10]; Delay(8); gewei=1;
}
void t0(void) interrupt 1 using 0 //定时中断服务函数
{
	TH0=(65536-50000)/256; //对TH0 TL0 赋值
	TL0=(65536-50000)%256; //重装计数初值
	tcnt++; //每过250ust tcnt 加一
	if(tcnt==20) //计满20 次(1 秒)时
	  {																					                           
	
		   tcnt=0;
		   sec++;
		   if(sec==60)
		   { 
		     sec=0;
		   }
	  }
}
void main(void)
{
	P2=0;
	TMOD=0x01; //定时器工作在方式1
	ET0=1; EA=1;
	TH0=(65536-50000)/256; //对TH0 TL0 赋值
	TL0=(65536-50000)%256; //使定时器0.05 秒中断一次
	TR0=1; //开始计时
	while(1)
	  {
		LED();
		
	  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -