标题: C51秒表仿真电路实验 [打印本页]

作者: heicc    时间: 2016-5-29 15:46
标题: C51秒表仿真电路实验





仿真文件下载:http://www.51hei.com/bbs/dpj-50777-1.html

  1. #include <reg51.h>
  2. char disNumber[10] = {0x40, 0x79, 0x24, 0x30, 0x19, 0x12, 0x2, 0x78, 0x0, 0x10};
  3.    char ONE = 0;
  4.   char TWO = 0;
  5.   char THERE = 0;
  6.   char FOUR = 0;
  7.   int count = 0;
  8. void delay5ms(void)   //误差 0us
  9. {
  10.     unsigned char a,b;
  11.     for(b=19;b>0;b--)
  12.         for(a=130;a>0;a--);
  13. }

  14. void delay950ms(void)   //误差 0us
  15. {
  16.     unsigned char a,b,c;
  17.     for(c=227;c>0;c--)
  18.         for(b=246;b>0;b--)
  19.             for(a=7;a>0;a--);
  20. }
  21. void time1() interrupt 1
  22. {
  23. TH0=(65536-50000)/256;
  24. TL0=(65536-50000)%256;
  25. count++;
  26. if (count % 2 == 0)
  27. FOUR++;
  28. if (FOUR >= 10)
  29. {
  30.   FOUR = 0;
  31.   THERE++;
  32. }
  33. if (THERE >= 10)
  34. {
  35.   THERE = 0;
  36.   TWO++;
  37. }
  38. if (TWO >= 10)
  39. {
  40.   TWO = 0;
  41.   ONE++;
  42. }
  43. }

  44. int main(void)
  45. {
  46.   int i = 0;
  47.   
  48.   
  49. TMOD=0x01;//设置定时器0为工作方式1
  50. TH0=(65536-50000)/256;
  51. TL0=(65536-50000)%256;
  52. EA=1;//打开中断总开关
  53. ET0=1;//开定时器0中断
  54. TR0=1;//启动定时器0
  55.   
  56.   while (1)
  57.   {
  58.     P3 = 0;
  59.         P2 = 0X1;
  60.     P0 = disNumber[ONE];
  61.     delay5ms();
  62.        
  63.         P2 = 0X2;
  64.         P0 = disNumber[TWO];
  65.         delay5ms();
  66.         i++;

  67.         P2 = 0X4;
  68.         P0 = disNumber[THERE];
  69.         delay5ms();
  70.         i++;

  71.         P2 = 0X8;
  72.         P0 = disNumber[FOUR];
  73.         delay5ms();
  74.         i++;
  75.         }         
  76.                  
  77.   return 0;
  78. }
复制代码








欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1