Advertisement
Guest User

Untitled

a guest
Mar 12th, 2014
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. // Method 1: Polling
  2. main()
  3. {
  4.     uint8_t count = 0;
  5.     ..
  6.     ..
  7.     while(posedge_input) {
  8.         count++;
  9.         if(count == 0) {
  10.             // Start timer
  11.         }
  12.         else if(count == 7) {
  13.             // Stop, Read and Reset timer value
  14.             count = 0;
  15.         }
  16.     }
  17.     ..
  18.     ..
  19. }
  20.  
  21. // Method 2: Hardware Interrupt
  22. // You'll have to read the datasheet for this, I don't have any tutorial for this yet.
  23.  
  24. uint8_t count = 0;      // Global counter
  25.  
  26. Hardware_Interrupt_ISR()
  27. {
  28.     if(posedge_input) {
  29.         count++;
  30.         if(count == 0) {
  31.             // Start timer
  32.         }
  33.         else if(count == 7) {
  34.             // Stop, Read and Reset timer value
  35.             count = 0;
  36.         }
  37.     }
  38. }
  39.  
  40. main()
  41. {
  42.     ..
  43.     ..
  44.     // Do general initialization
  45.     ..
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement