Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //#include <studio.h>
- #include <msp430.h>
- #include "project.h"
- #include "ports.h"
- #include "timer.h"
- #include "adc.h"
- #include "uart.h"
- int gADCLastVal = 0;
- char buf[25];
- void ADC_Init() {
- ADC10CTL0 &= ~ENC;
- ADC10CTL0 = ADC10ON /* + MSC */ + ADC10SHT_3;
- ADC10CTL1 = INCH_10 + ADC10SSEL_3 + ADC10DIV_4; //Channel 10, ADC10CLK/3
- //ADC10CTL0 = SREF_0 + REFON + ADC10SHT_3 + ADC10ON ;
- // Vcc & Vss as reference, Sample and hold for 64 Clock Cyccles, ADC on
- //ADC10CTL1 = INCH_10 + ADC10DIV_3;
- //ADC10AE0 //ADC input enable P1.3
- }
- void ADC_Read() {
- int count = 32000;
- ADC10CTL0 |= ENC + ADC10SC; //Start new conversion
- while ((ADC10CTL1 & ADC10BUSY) && --count);
- if (!count) UART_Write("ADC Timeout error");
- gADCLastVal = ADC10MEM; // Left shift
- ADC10CTL0 &= ~ENC;
- }
- inline int ADC_GetValue() {
- return gADCLastVal;
- }
- void ADC_Write() {
- int i;
- int val = ADC_GetValue();
- int q, c = 0;
- //snprintf(buf, 25, "Val: %\n", val);
- for(i=10000; i>0; i/=10){
- q = val/i;
- buf[c++] = q + '0';
- val -= q*i;
- }
- buf[c++] = '\n';
- buf[c++] = '\r';
- buf[c] = '\0';
- UART_Write(buf);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement