Advertisement
Guest User

Untitled

a guest
May 30th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #include<reg51.h>
  2. #include<stdio.h>
  3.  
  4. sfr DPTR = 0x82;
  5. long int time_total, freq;
  6. unsigned char flag=0;
  7.  
  8. intr() interrupt 0{
  9. if(TR0){
  10. TR0 = 0;
  11. flag = 1;
  12. }
  13. else{
  14. TR0 = 1;
  15. }
  16. }
  17.  
  18. init_timer(){
  19. TMOD |= 0x01;
  20. TCON |= 0x01;
  21. }
  22.  
  23. void prnt(char ch){
  24. TI = 0;
  25. SBUF = ch;
  26. while(!TI);
  27. }
  28.  
  29. main(){
  30. unsigned int divisor=10000, temp;
  31. IE |= 0x81;
  32. SCON |= 0x50;
  33. TMOD |= 0x20;
  34. TH1 = 0xfd;
  35. TL1 = 0xfd;
  36. TR1 = 1;
  37. while(1){
  38. init_timer();
  39. if(flag){
  40. DPH = TH0;
  41. DPL = TL0;
  42. time_total = DPTR;
  43. freq = 1000000/time_total;
  44. while(freq){
  45. temp = freq/divisor;
  46. temp += 0x30;
  47. freq%=divisor;
  48. divisor/=10;
  49. prnt(temp);
  50. }
  51. TH0 = 0x00;
  52. TL0 = 0x00;
  53. flag = 0;
  54. }
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement