资源描述:
《无线龙04协议栈CC2430单片机串口测试实验(UART)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、无线龙()4协议栈CC243()单片机串口测试实验(UART)程序:1、《main.c》#dcfincENABLE_ALL_INTERRUPT()(IENO1=0x80)#defineDISABLE.ALL_INTERRUPT()(IENO&=-0x80)#include,,ioCC2430.hn#defineucharunsignedchar#defineuintunsignedint#defineBYTEunsignedcharexternvoidLARTxISRopcn(void);〃开串口接收中断服务函数externvoidSET
2、_UARTO_ISR(void);//冷口中断接收设置函数externoidnitUART(void);〃初始化函数main(void){uchartemp=0;SLEEP&二-0x04;//reset2:Bothoscillatorspoweredupwhile(!(SLEEP&0x40));//XOSCispoweredupandstable等待起振CLKCON&=〜0x47;//reset6:Mainclockoscillatorselect:32MHzcrystaloscillatorSLEEP1=0x04;//set2:Osc
3、illatornotselectedbyOSCbitpowereddown〃先让两个振荡器都起振;等待品体振荡器起振并稳定;〃通过CLKCON的OSC位把主时钟选择32M晶体振荡器;〃再让没有被CLKCON的OSC位选择的振荡器停止起振(关RC振荡器)initUARTO;〃初始化UARTxISRopenO;〃开串口屮断ENABLE_ALL_INTERRUPT();//开全局中断whilc(l);振荡器起振稳定——>设置主时钟——>初始化串口——>开串口中断——>开全局中断//2、《uart・c》#includenioCC2430.hHun
4、signeduarttemp;#defineENABLE_ALL_INTERRUPT()(IENO1=0x80)〃开全局中断#defineDISABLE_ALL_INTERRUPT()(1EN0&=〜0x80)//关全局中断#defineIO_PER_LOC_UARTO_AT_PORTO_PIN2345()do{PERCFG(PERCFG&~0x01)10x00;}while(0)//rcstc0:USART0I/Olocation:Alternative1location〃选择USART0为通道1:P0.2345#defineuchar
5、unsignedchar#defineCRYSTAL0x00#dcfincRC0x01#defineHIGH_STOP#defineIOWSTOP0x02〃停止位为高电平0x00〃停止位为低电平#defineCLKSPD(CLKCON&0x07)//32KHZand32MHZcrystaloscilliator;32MHZticks#defineTRANSFER_MSB.FIRST0x80/最高位先发送#defineTRANSFER_MSB_LAST0x0()/最高位后发送//LSB(LeastSignificantBit),意为最低冇效
6、位//MSB(MostSignificantBit),意为最高有效位#defineUART_ENABLE_RECEIVE0x40//UART接收使能#defineUART_SETUP(uart,baidRate,opions)do{if((uart)=0)//ifuart=O,choseUSARTO.UART/SPI{if(PERCFG&0x01)//ifU0CFG=1,choselocation2{P1SEL1=0x30;//thenPl.4/5setasperipheralI/O}//Pl.4/5分别是RX,TX两条线
7、,UART可由这两线组成,也可再加上RT,CT这两条else//讦U0CFG=0,choselocation1POSEL1=OxOC;//thenPO.2/3setasperipheralI/O;同样为RX,TX两线}}else//ifuart=l,choseUSART1_UART/SP1{if(PERCFG&0x02)//ifU1CFG=1,choselocation2{P1SEL1=OxCO;//thenPl.6/7jeta;pa*ipheralIO}else//ifU1CFG=O,choselocation1{
8、POSEL1=0x30;//thenPO.4/5st3peripheralIO}}〃以上进行USATR通道选择设置//##中间的uart根据上而的设置为0或1U##uart##GCR=B