標(biāo)題: 用數(shù)碼管做一個(gè)單片機(jī)秒表 [打印本頁]

作者: beibeixin    時(shí)間: 2017-10-13 00:18
標(biāo)題: 用數(shù)碼管做一個(gè)單片機(jī)秒表
用數(shù)碼管做一個(gè)秒表

單片機(jī)源程序如下:
  1. #include"reg52.h"
  2. #define u8 unsigned char
  3. #define u16 unsigned int
  4. sbit duan1=P2^2;
  5. sbit duan2=P2^3;
  6. sbit duan3=P2^4;
  7. u8 code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
  8. u16 date=5448;
  9. u8 a;

  10. void delay(u16 mas)
  11. {
  12.    u16 i,j;
  13.    for(i=mas;i>0;i--)
  14.      for(j=110;j>0;j--);
  15. }

  16. void display(u16 date)
  17. {
  18.    u8 ge,shi,bai,qian;
  19.    ge=date%10;
  20.    shi=date/10%10;
  21.    bai=date/100%10;
  22.    qian=date/1000;
  23.    duan1=0;duan2=0;duan3=0;
  24.    P0=table[ge];
  25.    delay(5);
  26.    P0=0x00;
  27.    duan1=1;duan2=0;duan3=0;
  28.    P0=table[shi];
  29.    delay(5);
  30.    P0=0x00;
  31.    duan1=0;duan2=1;duan3=0;
  32.    P0=table[bai];
  33.    delay(5);
  34.    P0=0x00;
  35.    duan1=1;duan2=1;duan3=0;
  36.    P0=table[qian];
  37.    delay(5);
  38.    P0=0x00;
  39. }       



  40. void main()
  41. {
  42.   
  43.   TMOD=0x01;
  44.   TH0=(65536-45872)/256;
  45.   TL0=(65536-45872)%256;
  46.   EA=1;
  47.   ET0=1;
  48.   TR0=1;
  49.   while(1)
  50.   {
  51.           display(date);
  52.   
  53.   }
  54. }
  55. void inttime() interrupt 1
  56. {

  57.   TH0=(65536-50000)/256;
  58.   TL0=(65536-50000)%256;
  59.   a++;
  60.   
  61.   if(a==20)
  62.   {
  63.     a=0;
  64.         date=date-1;
  65.         if(date==0)
  66.            date=5448;
  67.   }
  68. }
復(fù)制代碼

所有資料51hei提供下載:
秒表.zip (22.98 KB, 下載次數(shù): 7)







歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1