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_11; // Direct ADC to internal (Vcc-Vss)/2
- ADC10CTL0 = SREF0 + REFON + REF2_5V; // Use Vref, set internal reference on, set it to 2.5V
- 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 > 675, aVal < 675);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement