標(biāo)題:
CC2530源程序分享
[打印本頁]
作者:
白。
時(shí)間:
2016-12-24 15:04
標(biāo)題:
CC2530源程序分享
CC2530的程序
0.png
(65.76 KB, 下載次數(shù): 75)
下載附件
2017-2-12 16:32 上傳
完整代碼下載:
LIGHT.rar
(28.29 KB, 下載次數(shù): 14)
2016-12-24 15:03 上傳
點(diǎn)擊文件名下載附件
下載積分: 黑幣 -5
主程序:
#include "ioCC2530.h"
#define uint8 unsigned char
#define uint16 unsigned int
#define uint32 unsigned long
extern void Sensor_PIN_INT(void);
extern uint16 ReadAdcValue(uint8 ChannelNum,uint8 DecimationRate,uint8 RefVoltage);
char uart_buffer;
void delay(void)
{
unsigned int i;
unsigned char j;
for(i=0;i<1500;i++)
{
for(j=0;j<200;j++)
{
asm("NOP");
asm("NOP");
asm("NOP");
}
}
}
void UartTX_Send_String(unsigned char *Data,int len) //串口發(fā)送函數(shù)
{
int j;
for(j=0;j<len;j++)
{
U0DBUF = *Data++;
while(UTX0IF == 0);
UTX0IF = 0;
}
}
void UartTX_Send_Data(unsigned char Data,int len) //串口發(fā)送函數(shù)
{
int j;
for(j=0;j<len;j++)
{
U0DBUF = Data;
while(UTX0IF == 0);
UTX0IF = 0;
}
}
#pragma vector=URX0_VECTOR //uart0中斷函數(shù)
__interrupt void uart0(void){
URX0IF = 0; //清中斷標(biāo)志
P0_0=~P0_0;
uart_buffer = U0DBUF;
//UartTX_Send_String("welcome",10);
UartTX_Send_Data(uart_buffer,1);
}
void main( void )
{
unsigned char buf[8];
uint16 temp;
P0DIR |= 0x01; //設(shè)置P0.0為輸出方式;P0.4和P0.5為輸入方式
APCFG = (0x1<<1)|(0x1<<4)|(0x1<<6);//P01,P04,P06為ADC口
P2DIR |= 0x01; //設(shè)置P2.0為輸出方式
P0_0 = 1;
P2_0 = 1; //熄滅LED
CLKCONCMD &= ~0x40; //選擇32M晶振
while(!(SLEEPSTA & 0x40)); //等待XSOC穩(wěn)定
CLKCONCMD = 0xb8; //TICHSPD 128分頻,CLKSPD 不分頻
SLEEPCMD |= 0x04; //關(guān)閉不用的RC 振蕩器
PERCFG = 0x00; //位置1 P0 口
P0SEL = 0x3c; //P0 用作串口
U0CSR |= 0x80; //UART 方式
U0GCR |= 10; //baud_e = 10;
U0BAUD |= 216; //波特率設(shè)為57600
UTX0IF = 1;
U0CSR |= 0X40; //允許接收
IEN0 |= 0x84; //開總中斷,接收中斷
Sensor_PIN_INT();
UartTX_Send_String("Testing...\r\n",12);
while(1){
P2_0=~P2_0;
temp = ReadAdcValue(4,3,0x2);//P0.4采集光照度,12bit,AVDD5作為參考
temp = (temp>>4);
buf[0] = (uint8)(temp&0xff);
buf[1] = (buf[0]>>4)&0xf;
buf[2] = buf[0]&0xf;
if(buf[1] > 0x9)
buf[1] = buf[1] - 0XA + 'A';
else
buf[1] = buf[1] + '0';
if(buf[2] > 0x9)
buf[2] = buf[2] - 0XA + 'A';
else
buf[2] = buf[2] + '0';
UartTX_Send_String("LIGHT = ",8);
UartTX_Send_String(&buf[1],1);
UartTX_Send_String(&buf[2],1);
UartTX_Send_String("\r\n",2);
delay();
}
} // end of main()
復(fù)制代碼
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1