主函数
#include"ioCC2530.h"
#include"hal_ADC/hal_adc.h"
#include"hal_ADC/hal_types.h"
#include"hal_ADC/LcdControl.h"
#include "stdio.h"
#define uint unsigned int
#define uchar unsigned char
#define master_node
#ifdef master_node
#define LED1 P1_0
#define LED2 P1_1
#else
#define LED1 P1_1
#define LED2 P1_0
#endif
#define ON 1
#define OFF 0
#ifdef master_node
#define K1 P1_3
#define K2 P0_1
#else
#define K1 P0_1
#define K2 P0_7
#endif
enum SYSCLK_SRC{XOSC_32MHz,RC_16MHz};
void Delay(uint);
void InitLed(void);
void InitKey(void);
uchar KeyScan(void);
char i=0;
uchar Keyvalue=0;
uint temperature = 0;
uint volt=0,voltagevalue=0;
uint16 avgTemp;
uint16 avgVcc3;
double v3;
void Delay(uint n){
uint t;
for(t=0;t<n;t++);
for(t=0;t<n;t++);
for(t=0;t<n;t++);
for(t=0;t<n;t++);
for(t=0;t<n;t++);
}
void SystemClockSourceSelect(enum SYSCLK_SRC source)
{
unsigned char osc32k_bm=CLKCONCMD & 0x80;
unsigned char __clkconcmd,__clkconsta;
if(source==RC_16MHz)
CLKCONCMD=((osc32k_bm)|\
(0x01<<6)|\
(0x01<<3)|\
(0x01<<0));
else if(source==XOSC_32MHz)
{
CLKCONCMD=(osc32k_bm);
}
__clkconcmd=CLKCONCMD;
do
{
__clkconsta=CLKCONSTA;
}while(__clkconsta!=__clkconcmd);
}
void InitKey(void)
{
#ifdef master_node
P0SEL&=~0X02;
P0DIR&=~0X02;
P0INP|=0x02;
P1SEL&=~0X08;
P1DIR&=~0X08;
P1INP|=0x08;
#else
P0SEL&=~0X82;
P0DIR&=~0X82;
P0INP|=0x82;
#endif
}
void InitLed(void)
{
P1SEL&=~0x03;
P1DIR|=0x03;
LED1=ON;
LED2=OFF;
}
uchar KeyScan(void)
{
if(K1==0)
{
Delay(100);
if(K1==0)
{
while(!K1);
return(1);
}
}
else if(K2==0)
{
Delay(100);
if(K2==0)
{
while(!K2);
return(2);
}
}
else
;
return(Keyvalue);
}
void main(void)
{
char i;
double v;
double temperature;
uint8 temperature1,temperature2,temperature3;
uint8 avgV0,avgV1,avgV2,avgV3;
uint8 avgvcc0,avgvcc1,avgvcc2,avgvcc3;
SystemClockSourceSelect(XOSC_32MHz);
InitLed();
HalLcd_HW_Init(pic2);
IEN0=IEN1=IEN2=0X00;
HalAdcInit();
Delay(60000);Delay(60000);Delay(60000);
Display_Picture(pic3);
while(1)
{
avgTemp = 0;
avgVcc3 =0;
TR0=0X01;
ATEST=0X01;
for(i = 0 ; i < 4 ; i++)
{
avgVcc3 += HalAdcRead (HAL_ADC_CHN_VDD3, HAL_ADC_RESOLUTION_12);
avgTemp += HalAdcRead (HAL_ADC_CHN_TEMP, HAL_ADC_RESOLUTION_12);
}
TR0=0X00;
ATEST=0X00;
avgTemp >>= 2;
temperature=(avgTemp-(1480-4.5*25))/4.5;
avgVcc3 >>= 2;
v3=1.15*avgVcc3/2047;
v=v3*3.0;
Delay(20000);
temperature = temperature*10;
temperature1 = (uint16)temperature/100;
temperature2 = (uint16)temperature%100/10;
temperature3 = (uint16)temperature%10;
v3 = v3*1000;
avgV0 = (uint16)v3/1000;
avgV1 = (uint16)v3%1000/100;
avgV2 = (uint16)v3%1000/10%10;
avgV3 = (uint16)v3%1000%100%10;
v = v*1000;
avgvcc0 = (uint16)v/1000;
avgvcc1 = (uint16)v%1000/100;
avgvcc2 = (uint16)v%1000/10%10;
avgvcc3 = (uint16)v%1000%100%10;
LCDDataShow(temperature1,2,3,82,89);
LCDDataShow(temperature2,2,3,90,97);
LCDDataShow(temperature3,2,3,99,106);
LCDDataShow(avgV0,4,5,75,82);
LCDDataShow(avgV1,4,5,83,90);
LCDDataShow(avgV2,4,5,91,98);
LCDDataShow(avgV3,4,5,99,106);
LCDDataShow(avgvcc0,6,7,73,80);
LCDDataShow(avgvcc1,6,7,83,90);
LCDDataShow(avgvcc2,6,7,91,98);
LCDDataShow(avgvcc3,6,7,99,106);
Delay(60000);
}
}
完整代码下载