×
单片机 > 单片机程序设计 > 详情

89C52单片机制作秒表

发布时间:2020-09-02 发布时间:
|
用STC公司的89C52单片机制作秒表,过程其实很简单,有以下几个注意的东西;
  1. 动态显示
  2. 七段译码的编码表
  3. 定时器的设置
  单片机的时钟信号为11.0592MHz,选取46080对应0.05s。
  程序:
 
#include
#include
 
 
sbit P2_2=P2^2 ;
sbit P2_3=P2^3 ;
void delay(unsigned char dly)
{
  unsigned char i,j;
 
  for(i=255;i>0;i--)
    for(j=dly;j>0;j--)
;
}
unsigned char num,time;
void  timer0()interrupt 1
{
  TH0=(65535-46080)/256;
 
  TL0=(65535-46080)% 256;
  num++;
  if(num==20)
    {
 num=0;
 time++;
}
}
void intial()
{
   TMOD=0x01;
   ET0=1;
   EA=1;
   TR0=1;
   num=0;
}
void main()
{
  unsigned char table[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};
  unsigned char shi,fen;
  intial();
  while(1)
    {
 if(time==60)
   time=0;
 shi=time/10;
 fen=time% 10;
 P2_2=1;
 P2_3=0;
 P0=table[shi];
 delay(2);
 P2_2=0;
 P2_3=1;
 P0=table[fen];
 delay(2);
}
}


『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
单片机的抗干扰措施有哪些