论文是用AT89C51单片机为基础的转速测量系统设计
1. #include<reg51.h> 2. #define unsigned char 3. #define unsigned int 4. unsigned int mm=1234; 5. unsigned char code table[]={0xc0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,}; 6. delay(unsigned int m) 7. { unsigned int i,j; 8. for(i=m;i>0;i--) 9. for(j=60;j>0;j--); 10. } 11. xian_shi() 12. { unsigned char qian,bai,shi,ge; 13. unsigned int jj; 14. jj=mm; 15. jj*=20; 16. //jj+=1; 17. qian=jj/1000; 18. bai=jj%1000/100; 19. shi=jj%100/10; 20. ge=jj%10; 21. 22. P2=0x10; 23. P0=table[qian]; 24. delay(1); 25. //P2=0; 26. 27. P2=0x20; 28. P0=table[bai]; 29. delay(1); 30. //P2=0; 31. 32. P2=0x40; 33. P0=table[shi]; 34. delay(1); 35. //P2=0; 36. 37. P2=0x80; 38. P0=table[ge]; 39. delay(1); 40. //P2=0; 41. 42. } 43. timer_init() //定时器计数器初始化函数 44. { EA=1; 45. ET0=1; 46. ET1=1; 47. TMOD=0X51; 48. TH0=(65535-50000)/256; 49. TL0=(65535-50000)%256; 50. TH1=0; 51. TL1=0; 52. TR0=1; 53. TR1=1; 54. } 55. main() 56. { 57. timer_init(); 58. P0=0; //开始数码管不显示 59. while(1) 60. { 61. xian_shi(); 62. delay(2); //数码管刷新时间单位毫秒 63. } 64. } 65. void timer0() interrupt 1 66. { TR0=0; 67. TR1=0; 68. TH0=(65535-50000)/256; 69. TL0=(65535-50000)%256; 70. mm=0; 71. mm|=TH1; 72. mm=(mm<<8)|TL1; 73. // mm-=55536; 74. TH1=0; 75. TL1=0; 76. TR0=1; 77. TR1=1; 78. } 79. void timer1() interrupt 3 //显示0000说明出错 80. { TR1=0; 81. TR0=0; 82. mm=0; 83. // TH1=0; 84. // TL1=0; 85. // TR1=1; }
萌新求帮忙啊
|