msp-adc.c

来自「MANTIS是由科罗拉多大学开发的传感器网络嵌入式操作系统。 这是mantis」· C语言 代码 · 共 66 行

C
66
字号
//  This file is part of MANTIS OS, Operating System//  See http://mantis.cs.colorado.edu/////  Copyright (C) 2003,2004,2005 University of Colorado, Boulder////  This program is free software; you can redistribute it and/or//  modify it under the terms of the mos license (see file LICENSE)/*  Project Mantis  File:   msp-adc.c  Author: Charles Gruenwald III  Date:   05-20-05  This file implements the lowest level control of the analog to digital  conversion system on the msp430x16x device.*/#include "mos.h"#ifdef PLATFORM_TELOSB#include "msp-adc.h"#include "dev.h"#include "mutex.h"#include "sem.h"uint8_t adc_channel;void adc_set_channel(uint8_t ch){   uint8_t addr = 0;   //set the addr where conversion result will reside   ADC12CTL1 |= ((addr & 0x0F) << 11);   //set the addr to read from the corresponding channel   ADC12MCTL0 |= (ch & 0x0F);}uint16_t adc_get_conversion16(uint8_t ch){   ADC12CTL0 &= ~ENC;   adc_on();   adc_set_channel(ch);      //set source of sampling signal (SAMPCON) to be the output of   //the sampling timer   ADC12CTL1 |= SHP;   //start the conversion   ADC12CTL0 |= ENC | ADC12SC;   //polling wait for conversion to complete   while(ADC12CTL1 & ADC12BUSY);   uint16_t sample = ADC12MEM0;   return sample;}#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?