www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當前位置:首頁 > 單片機 > 單片機
[導讀]1.TinyOS提供的組件和接口CC2430被廣泛應用于無線傳感器網(wǎng)絡,其片上自帶的ADC可以將傳感器采集到的模擬信號轉換為數(shù)字信號進行相應處理。開源組織TinyOS 8051 working group 提供可以移植到CC2430EM平臺上的TinyOS

1.TinyOS提供的組件和接口

CC2430被廣泛應用于無線傳感器網(wǎng)絡,其片上自帶的ADC可以將傳感器采集到的模擬信號轉換為數(shù)字信號進行相應處理。

開源組織TinyOS 8051 working group 提供可以移植到CC2430EM平臺上的TinyOS,該平臺TinyOS含有可用于控制CC2430單片機ADC的組件AdcC:

components new AdcC(); // 用于控制CC2430 ADC

該組件可將P0口8路輸入任一通道中的模擬信號轉換為數(shù)字信號。

為調用該組件提供有如下接口:

provides interface AdcControl; // 用于控制和打開指定ADC端口

provides interface Read; //用于進行指定端口的ADC轉換

2.AdcC使用實例分析

2.1組成AdcC組件的內部組件連接關系定義如下:

generic configuration AdcC() {

provides interface AdcControl;

provides interface Read;

}

implementation {

components MainC, AdcP;

MainC.SoftwareInit -> AdcP.Init;

/*****該枚舉變量是關鍵,ID =unique("UNIQUE_ADC_PORT"),表明ID值是一個常量函數(shù)的返回值,常量函數(shù)unique()的具體使用方法參考tinyos-programming.pdf文檔中的介紹**********/

enum { ID = unique("UNIQUE_ADC_PORT"), };

AdcControl = AdcP.AdcControl[ID]; // ID值為0當unique只調用1次

Read = AdcP.Read[ID]; // 同上

}

2.2下面進入到組件(模塊)AdcP中查看AdcControl[ID]、Read[ID]接口的具體實現(xiàn):

module AdcP {

provides interface Init;

provides interface AdcControl[uint8_t id];

provides interface Read[uint8_t id];

}

implementation

{

#include "Adc.h"

uint8_t references[uniqueCount("UNIQUE_ADC_PORT")]; //uniqueCount()等于unique()函數(shù)在程序中的調用次數(shù),該數(shù)組用于存放參考電壓值

uint8_t resolutions[uniqueCount("UNIQUE_ADC_PORT")]; //該數(shù)組用于存放對應端口的轉換精度:8bit/10bit/12bit/14bit

uint8_t inputs[uniqueCount("UNIQUE_ADC_PORT")]; //該數(shù)組用于存放對應的端口號(P0(0~7)口的任一端口)

bool inUse[uniqueCount("UNIQUE_ADC_PORT")]; // 端口是否使用FLAG

uint8_t counter;

uint8_t lastId = uniqueCount("UNIQUE_ADC_PORT");

// 一些用到的變量的初始化操作

command error_t Init.init() {

uint8_t i;

for (i = 0; i < uniqueCount("UNIQUE_ADC_PORT"); i++) {

inUse[i] = FALSE;

}

counter = 0;

return SUCCESS;

}

// 三個參數(shù)分別為參考電壓、轉換精度、端口號

command void AdcControl.enable[uint8_t id](uint8_t reference, uint8_t resolution, uint8_t input) {

/* enable interrupt when a channel is enabled (and stop any sampling in progress */

if (counter == 0) {

ADCIE = 1; // 使能ADC中斷

ADC_STOP(); // start select,產(chǎn)生新的ADC轉換序列,停止正在進行的轉換

}

/* enable channel if not already enabled */

if (!inUse[id]) { // 查詢對應ADC端口是否已經(jīng)使用,否,使能

inUse[id] = TRUE;

counter++;

ADC_ENABLE_CHANNEL(inputs[id]); // ADC Input Configuration 對應端口輸入使能,該宏定義在Adc.h中實現(xiàn)

}

/* save parameters */

references[id] = reference; //參考電壓

resolutions[id] = resolution; //轉換位數(shù)

inputs[id] = input; //端口號

}

// 對應端口ADC功能關閉

command void AdcControl.disable[uint8_t id]() {

/* disable channel if it has been enabled */

if (inUse[id]) {

inUse[id] = FALSE;

ADC_DISABLE_CHANNEL(inputs[id]);

counter--;

/* disable interrupts if no more channels are used by ADC */

if (counter == 0) {

ADCIE = 0;

}

}

}

/**

* Initiates a read of the value.

*

* @return SUCCESS if a readDone() event will eventually come back.

*/

command error_t Read.read[uint8_t id]() {

/* check if ADC is in use */

if (lastId < uniqueCount("UNIQUE_ADC_PORT")) {

return FAIL;

} else {

uint8_t temp;

/* remember caller */

lastId = id;

/* read out any old conversion value */

//temp = ADCH; //貌似沒啥用,覆蓋了 我給注釋了結果是一樣的

//temp = ADCL; //貌似沒啥用,覆蓋了 我給注釋了結果是一樣的

/* start conversion 根據(jù)數(shù)組中存儲的對應端口的參數(shù)改變控制寄存器ADCCON3,進行ADC轉換 */

ADC_SINGLE_CONVERSION(references[id] | resolutions[id] | inputs[id]);

return SUCCESS;

}

}

task void signalReadDone();

int16_t value;

/* Interrupt handler 中斷服務函數(shù) */

MCS51_INTERRUPT(SIG_ADC) {

/* read value from register */

value = (( (uint16_t) ADCH) << 8); // 高8位右移8為存儲到16位value中

value |= ADCL; //ADC轉換的低8位存到value的低8位

post signalReadDone(); // 通知上層組件ADC轉化成功任務

}

task void signalReadDone() {

uint8_t tmp;

/* mark ADC as not in use */

tmp = lastId;

lastId = uniqueCount("UNIQUE_ADC_PORT");

/* map out value according to resolution */

value >>= (8 - (resolutions[tmp] >> 3)); // 左移2位,因為轉化結果是14BIT的植

/* sign extend to int16_t */

//8bit

// value >>= 2;

// value |= 0xC000 * ((value & 0x2000) >> 13);

//#define ADC_8_BIT 0x00 // 64 decimation rate

//#define ADC_10_BIT 0x10 // 128 decimation rate

//#define ADC_12_BIT 0x20 // 256 decimation rate

//#define ADC_14_BIT 0x30 // 512 decimation rate

// 通知上層組件轉換成功,value為傳遞的ADC轉換的值

signal Read.readDone[tmp](SUCCESS, value);

}

default event void Read.readDone[uint8_t id](error_t result, int16_t val) {

}

}

通過以上對AdcP.nc文件的分析,可以看出CC2430單片機ADC轉換的實現(xiàn)需要以下操作:

ADCIE // 端口使能,設置為輸入

ADCCFG // 中斷配置寄存器

ADCCON3 //ADC控制寄存器的操作

寄存器的具體定義參考CC2430 datasheet,內有使用詳細說明。

2.3 ADC組件的使用實例分析

2.3.1頂層應用組件定義:

configuration TestAppC {

}

implementation {

components MainC, TestAppP;

MainC.SoftwareInit -> TestAppP.Init;

MainC.Boot <- TestAppP;

components LedsC;

TestAppP.Leds -> LedsC;

components StdOutC;

TestAppP.StdOut -> StdOutC;

#ifdef __cc2430em__

components new AdcC();

TestAppP.Read -> AdcC;

TestAppP.AdcControl -> AdcC;

#elif __micro4__

components new Msp430InternalTemperatureC();

TestAppP.Read -> Msp430InternalTemperatureC;

#endif

}

2.3.2應用組件實現(xiàn):

#define DEBUG

module TestAppP {

provides interface Init;

uses interface Boot;

uses interface Leds;

uses interface StdOut;

#ifdef __cc2430em__

uses interface Read as Read;

uses interface AdcControl;

#elif __mi

本站聲明: 本文章由作者或相關機構授權發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內容真實性等。需要轉載請聯(lián)系該專欄作者,如若文章內容侵犯您的權益,請及時聯(lián)系本站刪除。
換一批
延伸閱讀

8位單片機在嵌入式設計領域已經(jīng)成為半個多世紀以來的主流選擇。盡管嵌入式系統(tǒng)市場日益復雜,8位單片機依然不斷發(fā)展,積極應對新的挑戰(zhàn)和系統(tǒng)需求。如今,Microchip推出的8位PIC?和AVR?單片機系列,配備了先進的獨立...

關鍵字: 單片機 嵌入式 CPU

在嵌入式系統(tǒng)開發(fā)中,程序燒錄是連接軟件設計與硬件實現(xiàn)的關鍵環(huán)節(jié)。當前主流的單片機燒錄技術已形成ICP(在電路編程)、ISP(在系統(tǒng)編程)、IAP(在應用編程)三大技術體系,分別對應開發(fā)調試、量產(chǎn)燒錄、遠程升級等不同場景。...

關鍵字: 單片機 ISP ICP IAP 嵌入式系統(tǒng)開發(fā)

在嵌入式系統(tǒng)開發(fā)中,看門狗(Watchdog Timer, WDT)是保障系統(tǒng)可靠性的核心組件,其初始化時機的選擇直接影響系統(tǒng)抗干擾能力和穩(wěn)定性。本文從硬件架構、軟件流程、安全規(guī)范三個維度,系統(tǒng)分析看門狗初始化的最佳實踐...

關鍵字: 單片機 看門狗 嵌入式系統(tǒng)

本文中,小編將對單片機予以介紹,如果你想對它的詳細情況有所認識,或者想要增進對它的了解程度,不妨請看以下內容哦。

關鍵字: 單片機 開發(fā)板 Keil

隨著單片機系統(tǒng)越來越廣泛地應用于消費類電子、醫(yī)療、工業(yè)自動化、智能化儀器儀表、航空航天等各領域,單片機系統(tǒng)面臨著電磁干擾(EMI)日益嚴重的威脅。電磁兼容性(EMC)包含系統(tǒng)的發(fā)射和敏感度兩方面的問題。

關鍵字: 單片機 電磁兼容

以下內容中,小編將對單片機的相關內容進行著重介紹和闡述,希望本文能幫您增進對單片機的了解,和小編一起來看看吧。

關鍵字: 單片機 復位電路

在這篇文章中,小編將為大家?guī)韱纹瑱C的相關報道。如果你對本文即將要講解的內容存在一定興趣,不妨繼續(xù)往下閱讀哦。

關鍵字: 單片機 異常復位

今天,小編將在這篇文章中為大家?guī)韱纹瑱C的有關報道,通過閱讀這篇文章,大家可以對它具備清晰的認識,主要內容如下。

關鍵字: 單片機 仿真器

單片機將是下述內容的主要介紹對象,通過這篇文章,小編希望大家可以對它的相關情況以及信息有所認識和了解,詳細內容如下。

關鍵字: 單片機 中斷 boot

一直以來,單片機都是大家的關注焦點之一。因此針對大家的興趣點所在,小編將為大家?guī)韱纹瑱C的相關介紹,詳細內容請看下文。

關鍵字: 單片機 數(shù)字信號 模擬信號
關閉