⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sport0.c

📁 MSP430和PDID12开发的USB设备程序
💻 C
字号:
#include "chip.h"
#include "string.h"

unsigned char tx0flg,rx0flg;
unsigned char rxbuf0;

void InitSport0()
{
UCTL0=SWRST;          //Ready for configurating serial's parameters
UCTL0 |=CHAR;//+LISTEN;  //Data frame format(8-N-1) with listen 
UTCTL0=SSEL1+URXSE;   //Selection of SMCLK becomes baud ratio clock,edge of starting singal available
URCTL0=URXEIE;        //Wrong message interrupt of reception enable
//UBR10=0x00;           //115200 @ 760KHz DCO(default)
//UBR00=0x06;      
//UMCTL0=0x55;          //Baud ratio adjusting
//UBR10=0;            //115200 @ 4.786 MHz DCO
//UBR00=41;
//UMCTL0=0x55;
UBR10=0;              //Baud ratio adjustiing
UBR00=69;             //115200 @ 8MHz External Oscillator
UMCTL0=0x55;
U0ME=URXE0+UTXE0; //Functions of reception and transmitter enable
UCTL0 &=~SWRST;  //Functions of serial port enable
U0IE=URXIE0;//+UTXIE0;   //Enable interrupt of reception 
P3SEL |=0x30;    //P3.5(URXD0),P3.4(UTXD0)
P3OUT &=0xDF;    //Setting P3.5 input
P3OUT |=0x10;    //Setting p3.4 output
P3DIR |=0x10;    //Setting P3.4 direction to output

tx0flg=1;
rx0flg=0;
}

#pragma vector=UART0TX_VECTOR
__interrupt void usart0_tx (void)
{
_DINT();    //Entry routine of TX0 with clearing URXIFG0 automatically
 tx0flg=1;  //Setting transmission successful flag
_EINT();
}

#pragma vector=UART0RX_VECTOR
__interrupt void usart0_rx (void)
{
_DINT();
// The following routine is used when setting UXRSE under low-power mode
  if(!(U0IFG & URXIFG0))
  {
    UTCTL0 &=~URXSE;     //Clear inner URXS flag without occuring URXIFGO
    UTCTL0 |=URXSE;      //Re-setting URXSE founction  
    _BIS_SR(SCG0+SCG1);  //Activating DCO if it was disabled by low-power mode
  }  
//The following routine is a normal interrupt service  
  else
  {
    rx0flg=1;            //Setting transmission successful flag;
    rxbuf0=RXBUF0;       //Reading data from RXBUF0 for clearing URXIFG0 automatically
  } 
_EINT();
}

void Tx0Char(unsigned char c)
{
 while(!(UTCTL0 & TXEPT));
 tx0flg=0;
 TXBUF0=c;
 while(!(U0IFG & UTXIFG0));
 tx0flg=1;
}
 
void Tx0S(char *p)
{
 unsigned  i,j;
 i=strlen(p);
 if(i>=256) i=255;
 for(j=0;j<i;j++) 
 {
  if(*(p+j)=='\n')
  {
   Tx0Char(0x0d);
   Tx0Char(0x0a);
  }
  else    Tx0Char(*(p+j)); 
 }
}  

void Tx0HexC(unsigned char c)
{
 unsigned char temp;
 temp=(c & 0xf0) >>4;
 if(temp <10) Tx0Char(temp +0x30);
 else Tx0Char(temp +'A'-10);
 temp=c & 0x0f;
 if(temp <10) Tx0Char(temp +0x30);
 else Tx0Char(temp +'A'-10);
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -