Advertisement
Guest User

Untitled

a guest
Oct 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. #include "io68hc11.h"
  2.  
  3. #define OPTION MB(0x1039)
  4. #define ADCTL MB(0x1030)
  5. #define PORTB MB(0x1004)
  6. #define ADR1 MB(0x1031)
  7.  
  8. void read_ad(void) {
  9. ADCTL=_00010000; //SCAN=0,MULT=1,AN[0:3]
  10.  
  11. while (!(ADCTL&0x80)); //wait for CCF=1
  12. }
  13.  
  14. int main(void) {
  15. OPTION=OPTION|0x80; //ADPU=1
  16. PORTB=0; //turn off LED
  17. while (1) {
  18. read_ad();
  19. if (ADR1>=128) { //checks if conversion result=1
  20. PORTB=PORTB|1; //turn on LED
  21. } else {
  22. PORTB=PORTB&~1; //turn off LED
  23. }
  24. }
  25.  
  26. return 0;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement