Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <msp430.h>
- #include <stdint.h>
- void setOnboardLEDs(const uint8_t greenOn, const uint8_t redOn) {
- uint8_t outVal = 0;
- if (greenOn) outVal |= 0b01000000;
- if (redOn) outVal |= 0b00000001;
- P1OUT = outVal;
- }
- int main(void) {
- uint16_t aVal;
- volatile uint16_t x;
- WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
- P1DIR = 0b01000001; // Pin P1.6 (green LED) and P1.0 (red LED) are Outputs
- ADC10CTL1 = INCH_4; // Direct ADC to channel 4 (pin 1.4)
- ADC10AE0 = 0b00010000; // Enable analog input for pin 1.4
- ADC10CTL0 = ADC10ON + ENC; // Turn the ADC10 module on and enable it
- for ( ; ; ) {
- ADC10CTL0 |= ADC10SC; // Start conversion
- while (0 == ADC10CTL0 & ADC10IFG) {}; // Wait for it to end
- aVal = ADC10MEM; // Read conversion result
- setOnboardLEDs(aVal > 768, aVal < 256);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement