单片机交流
直播中

殷谷光

7年用户 1003经验值
擅长:控制/MCU
私信 关注
[问答]

怎样去编写基于单片机的c语言30秒倒计时程序?

怎样去编写基于单片机的c语言30秒倒计时程序?

回帖(1)

孟佳

2021-7-15 14:51:39
30秒倒计时c语言51单片机实现
  原理图:
  程序:
  #include
  #define uchar unsigned char
  #define uint unsigned int
  ***it dula=P2^6;
  ***it wela=P2^7;
  ***it D=P2^3;
  uint tt,temp,shi,ge,a;
  uchar code shuma[]= {0x3f,0x06,0x5b,0x4f,
  0x66,0x6d,0x7d,0x07,
  0x7f,0x6f,0x77,0x7c,
  0x39,0x5e,0x79,0x71};
  void delay(uint z);
  void chushi();
  void xianshi(uint temp);
  void main()
  {
  chushi();
  while(1)
  {
  if(tt==20)
  {
  tt=0;
  if(temp<=0)
  {
  temp=30;
  D=0;
  while(1)
  {
  xianshi(0);
  }
  }
  temp--;
  }
  xianshi(temp);
  }
  }
  void delay(uint z) //延时子程序
  {
  uint x,y;
  for(x=z;x>0;x--)
  for(y=110;y>0;y--);
  }
  void chushi() //设置定时器1为工作方式1
  { temp=30;
  TMOD=0X01;
  TH0=(65536-50000)/256;
  TL0=(65536-50000)%256;
  EA=1;
  ET0=1;
  TR0=1;
  }
  void zhongduan() interrupt 1 //中断函数子程序不需要声明
  {
  TH0=(65536-50000)/256;
  TL0=(65536-50000)%256;
  tt++;
  }
  void xianshi(uint temp) //显示子程序
  {
  uint shi,ge;
  shi=temp/10;
  ge=temp%10;
  P0=shuma[shi];
  dula=1;
  dula=0;
  P0=0xfe;
  wela=1;
  wela=0;
  delay(2);
  P0=shuma[ge];
  dula=1;
  dula=0;
  P0=0xfd;
  wela=1;
  wela=0;
  delay(2);
  }
举报

更多回帖

发帖
×
20
完善资料,
赚取积分