potentiometer.c 328 B

1234567891011121314151617181920212223
  1. #include "derivative.h"
  2. #include "funct.h"
  3. unsigned int pot_value;
  4. void read_pot(void)
  5. {
  6. //turn on A/D
  7. ATDCTL2 = 0x80;
  8. //wait for power-up
  9. Delay(2);
  10. //start conversion channel 0
  11. ATDCTL5 = 0;
  12. //wait for conversion complete
  13. while(!(ATDSTAT0 & 0x80))
  14. ;
  15. //get data
  16. pot_value = ATDDR0H;
  17. }