Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1.  
  2. #include "address_mapping.h"
  3. unsigned int state;
  4.  
  5. int countOnes (int n)
  6. {
  7.     int count=0;
  8.     if (n == 0){
  9.         return 0;
  10.     }
  11.     while (n>0)
  12.     {
  13.         n = n & (n-1);
  14.         count++;
  15.     }
  16.     return count;
  17. }
  18.  
  19.  
  20. int main() {
  21.  
  22.     *SWITCHES_CONTROL = 0xFFFF;
  23.     *LED_CONTROL = 0x0;
  24.     int ledCounter = 1;
  25.     int temp;
  26.  
  27.     while (1 == 1) {
  28.  
  29.         countOnes(*SWITCHES_DATA);
  30.         temp = countOnes(*SWITCHES_DATA);
  31.  
  32.         while(temp > 0){
  33.  
  34.             ledCounter = ledCounter*2;
  35.  
  36.             temp--;
  37.  
  38.         }
  39.  
  40.         ledCounter--;
  41.         *LED_DATA = ledCounter;
  42.  
  43.  
  44.  
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement