Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "io68hc11.h"
- #define OPTION MB(0x1039)
- #define ADCTL MB(0x1030)
- #define PORTB MB(0x1004)
- #define ADR1 MB(0x1031)
- void read_ad(void) {
- ADCTL=_00010000; //SCAN=0,MULT=1,AN[0:3]
- while (!(ADCTL&0x80)); //wait for CCF=1
- }
- int main(void) {
- OPTION=OPTION|0x80; //ADPU=1
- PORTB=0; //turn off LED
- while (1) {
- read_ad();
- if (ADR1>=128) { //checks if conversion result=1
- PORTB=PORTB|1; //turn on LED
- } else {
- PORTB=PORTB&~1; //turn off LED
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement