msp430g2553串口接受数据_MSP430G2553 串口的简单程序

本文档介绍了如何使用UART.c文件在MSP430G2553微控制器上进行串口通信,包括初始化设置、发送和接收数据的函数实现,以及中断处理程序。通过实例展示了串口数据的收发过程。
摘要由CSDN通过智能技术生成

/*----------------------------------------------------------------------------*/

/*

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 的还难~~~

和大家分享下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值