//**************************************************//
//*******************我爱铅笔***********************//
//**************************************************//
// //// //// ///// //
// // // // // // // ******** //
// // // // // *工作室* //
// // // // // // ******** //
// ////// ///// ///// ** ** //
//》》》》》》》》》》》》》》》》》》》》》》》》》》
#ifndef __USART_CPP
#define __USART_CPP
#include "Usart.h"
Usart::Usart()
{
volatile unsigned int i;
USART_SEL |= 0xC0; // P3.6,7 = USART1 TXD/RXD |= 0xC0;
// P3.4,5 = USART0 TXD/RXD
UCA1CTL1 |= UCSSEL0;
UCA1BR0= 0x03; // 32768/9600
UCA1BR1 = 0x00;
UCA1MCTL = 0x4a; // no modulation
UCA1CTL0 &= ~(UCMODE0 +UCMODE1); //选择模式0
UCA1CTL1 &= ~UCSWRST;
}
void Usart::SetPt(long NewP)
{
switch(NewP)
{
case 9600:
USART_SEL |= 0xC0; // P3.6,7 = USART1 TXD/RXD |= 0xC0; // P3.4,5 = USART0 TXD/RXD
UCA1CTL1 |= UCSSEL0;
UCA1BR0= 0x03; // 8Mhz/19200 ~ 417
UCA1BR1 = 0x00;
UCA1MCTL = 0x4a; // no modulation
UCA1CTL0 &= ~(UCMODE0 +UCMODE1); //选择模式0
UCA1CTL1 &= ~UCSWRST;
break;
}
}
//串行口写一字节
void Usart::PutCh( char c)
{
if(c == '\n')
PutCh('\r') ;
while (!(UC1IFG & UCA1TXIFG)); // USCI_A0 TX buffer ready?
UCA1TXBUF = c;
}
//发送字符串的函数
void Usart::PrnStr( char *p)
{
do
{
PutCh(*p);
}
while (*(p++) != '\0');
PutCh('\n');
}
#endif //endif __USART_CPP
//《《《《《《《《《《《《《《《《《《《《《《《《《
评论0