完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
/*----------------------------------------------------------------------------*/
/* File Name : UART.c Description : Use the UART to communication, include sending and recviving. Author : Jones Lee Copyright_&Date_&Version : Jones_Studio _&<2012.8.27>_& Connector Fuction : Notes : */ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /*---Head Files-----------*/ #include "UART.h" /*--Variable Definition---*/ _UINT_8 Flag_Recv; _UINT_8 Byte_Recv; _UINT_8 Buffer_Recv[20]; /*---Function Definiton---*/ void Uart_Init(); void UART_SendOneChar(_UINT_8 byte); void UART_SendChars(_UINT_8 *pBuffer,_UINT_8 cnt); /*---Macro Definition-----*/ /*----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------*/ /* Fuction Name :Uart_Init() Description : Input parameter : Output parameter :void Creat Date :2012.8.27 Author :Jones Lee Notes : */ /*----------------------------------------------------------------------------*/ void Uart_Init() { //Select the IO's function to uart. P1DIR |= BIT2; //P1.2 UART_TX P1DIR &=~BIT1; //P1.2 UART_RX P1SEL |= BIT1+BIT2; //select P1.1 and P1.2 as UART port P1SEL2 |= BIT1+BIT2; //Set the bus as uart. UCA0CTL1 |=UCSWRST; //reset UART module,as well as enable UART module UCA0CTL1 |=UCSSEL_2; //UART clock is SMCLK UCA0BR0 |=65; //Baud N=BCLK/rate,rate=9600,BCLK=SMCLK=8M UCA0BR1 |=3; UCA0MCTL = UCBRS1; //UCBRSx=2 UCA0CTL1 &=~UCSWRST; //UART reset end //Open the UART recievc interrupt IE2 |= UCA0RXIE ; } /*----------------------------------------------------------------------------*/ /* Fuction Name :UART_SendOneChar() Description :The Sending one char function of UART Input parameter : _UINT_8 byte Output parameter :void Creat Date :2012.8.26-2012.8.27 Author :Jones Lee Notes : */ /*----------------------------------------------------------------------------*/ void UART_SendOneChar(_UINT_8 byte) { UCA0TXBUF = byte; while (!(IFG2&UCA0TXIFG)); //waiting UCA0TXBUF is empty IFG2 &=~UCA0TXIFG; //clear TX interrupt flag } /*----------------------------------------------------------------------------*/ /* Fuction Name :UART_SendChars() Description :The Sending chars function of UART Input parameter : _UINT_8 number _UINT_8* pBuffer Output parameter :void Creat Date :2012.8.26-2012.8.27 Author :Jones Lee Notes : */ /*----------------------------------------------------------------------------*/ void UART_SendChars(_UINT_8 *pBuffer,_UINT_8 cnt) { do { UART_SendOneChar(*pBuffer); cnt--; pBuffer++; } while(cnt != 0); //UART_SendOneChar('n'); } /*----------------------------------------------------------------------------*/ /* Fuction Name :USCI0RX_ISR() Description :The Recving chars function of UART Input parameter : _UINT_8* number (global variable) _UINT_8* pBuffer Output parameter :void Creat Date :2012.8.26 -2012.8.27 Author :Jones Lee Notes :There are only some simple sentences,you can add some flex- -ible sentences accroding to yourself. */ /*----------------------------------------------------------------------------*/ #pragma vector=USCIAB0RX_VECTOR __interrupt void USCI0RX_ISR(void) { Byte_Recv =UCA0RXBUF; //load the recieve byte IFG2 &=~UCA0RXIFG; //clear RX interrupt flag Flag_Recv = 1; } 弄了半天,才弄出来,汗死了,就是感觉比LPC 的还难~~~ 和大家分享下 |
|
相关推荐
3 个讨论
|
|
只有小组成员才能发言,加入小组>>
3036个成员聚集在这个小组
加入小组2935 浏览 1 评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3613 浏览 2 评论
请问怎么把下面51单片机的代码改成msp430 g2 pocket的代码,还有改下时间变成30秒
2346 浏览 1 评论
4810 浏览 1 评论
2576 浏览 1 评论
1334浏览 3评论
MSP430FR5994 使用库函数 定时器触发AD问题请教
3613浏览 2评论
2935浏览 1评论
1521浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 11:36 , Processed in 1.360838 second(s), Total 47, Slave 40 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号