Zigbee Tour (vi): Several important CC2430 basic experiments--ADC Single sampling __zigbee

Source: Internet
Author: User
ZigBee Tour (vi): Several important CC2430 basic experiments--ADC Single sampling first, the connecting link

In wireless sensor networks, it is important to convert the analog value of the sensor to digital to facilitate transmission and processing. ADC (Analog-to-digital Converter) is used to accomplish this conversion.

In the previous section, we introduced the serial communication between CC2430 and PC. A temperature sensor has been embedded inside the CC2430, and this section is based on the previous section realize a simple experiment on the temperature monitoring in the film: Using ADC to convert the voltage value of the temperature sensor into digital, calculate the temperature value by using the formula, then transfer the temperature value to the PC and display it through the serial port. second, the ADC single time sampling (1) Introduction to the experiment

Using ADC to convert temperature values of CC2430 in-chip temperature sensor, the temperature value is sent to PC by serial port and displayed. (2) Program flow chart

(3) experimental source and analysis/*
Experiment instruction: In-chip temperature collection experiment, sends the data to the PC through the serial port 0
*/

#include <ioCC2430.h>

#define LED1 P1_0
#define LED2 P1_1
#define LED3 P1_2
#define LED4 P1_3

/*32M Crystal Oscillator Initialization
-------------------------------------------------------*/
voidXtal_init (void)
{
Sleep &= ~ 0x04; All on the electricity.
while( !      (Sleep & 0x40)); Crystal oscillator Open and stable
Clkcon &= ~ 0x47; Select 32MHz Crystal Oscillator
Sleep |= 0x04;
}

/*led Light Initialization
-------------------------------------------------------*/
voidLed_init (void)
{
P1sel = 0x00; P1 is a normal I/O port
P1dir |= 0x0f; P1.0 P1.1 P1.2 P1.3 output

led1 = 1;
Led2 = 1;
LED3 = 1;
LED4 = 1;
}

/*uart0 initialization
-------------------------------------------------------*/
voidUart0init (unsignedCharStopBits,unsignedCharParity)
{
P0sel |= 0x0C; Initialize UART0 port
Percfg &= ~ 0x01; Select UART0 as an optional location
U0CSR = 0xc0; Set to UART mode, and enable the receiver
U0GCR = 11;
U0baud = 216; Set UART0 baud rate to 115200bps
U0UCR |= stopbits|         Parity; Set stop bit and parity
}

/*uart0 Send characters
-------------------------------------------------------*/
voidUart0send (unsigned CharData
{
while(U0CSR & 0x01); Wait for UART to send data when idle
U0DBUF = data;
}

/*uart0 Send string
-------------------------------------------------------*/
voidUart0sendstring (unsignedChar*s)
{
while(*s!= 0)
Uart0send (*s + +);
}

/*uart0 Receive data
-------------------------------------------------------*/
unsignedCharUart0receive (void)
{
unsignedCharData
while( !  (U0CSR & 0x04)); Query whether or not to receive data, or continue to wait
data = U0dbuf;
returnData
}

/* Delay function
-------------------------------------------------------*/
voidDelay (unsignedintN
{
unsignedintI
for(i = 0; I <n; i + +);
for(i = 0; I <n; i + +);
for(i = 0; I <n; i + +);
for(i = 0; I <n; i + +);
for(i = 0; I <n; i + +);
}

/* Get the actual temperature value
-------------------------------------------------------*/
floatGettemperature (void)
{
unsignedintValue

ADCCON3 = (0x3e); Select 1.25V as reference voltage, 14-bit resolution, and sample on-chip temperature sensor

ADCCON1 |= 0x30; Select the boot mode for the ADC to be manual
ADCCON1 |= 0x40; Start AD transformation

while( !            (ADCCON1 & 0x80)); Waiting for the ADC to be turned over

Value = ADCL >> 2;
Value |= (ADCH << 6); Get the final transformation result, deposit in value

returnValue * 0.06229-311.43; Calculate the temperature value according to the formula
}

/* Main function
-------------------------------------------------------*/
voidMainvoid)
{

Related Keywords:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• Sales Support

1 on 1 presale consultation

• After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.