本帖最后由 JAWN 于 2015-10-11 19:54 编辑
void init_clock(void)
{
P7SEL |= BIT0 + BIT1; // IO口设置为外部晶振
UCSCTL1 = DCORSEL_5; // 选择DCO的范围
UCSCTL2 = 374; // 设置DCO频率为16M
// 设置MCLK = DCOC,MCLK =DCO,ACLK=XT1
UCSCTL4 = SELM_3 + SELA_0 + SELS_3
void main(void)
{
WDTCTL=WDTPW+WDTHOLD;
init_clock(); //初始化系统时钟
light=3;
PCDIR=0xffff;
PCSEL=0x0000;
P10SEL = 0x30; //选择P10.4 P10.5串口功能
UCA3CTL1 |= UCSWRST; // USCI Software Reset */
UCA3CTL1 |= UCSSEL_2; // USCI 0 Clock Source: 2 --> SMCLK
UCA3BR0 = 0x6d; //设置波特率9600
UCA3BR1 = 0; //设置波特率
UCA3MCTL |= UCBRS_1 + UCBRF_0; // USCI A0 Modulation Control = USCI Second Stage Modulation: 1 + USCI First Stage Modulation: 0
UCA3CTL1 &= ~UCSWRST; //复位状态机
UCA3IE |= UCRXIE; //USCI Receive Interrupt Enable
_EINT();
//计数时钟选择STMLK=8MHz,1/8分频后为1MHz
TA0CTL |= TASSEL_2 + ID_3;
LcdReset();
s[0]=light/10+0x30;
s[1]=light%10+0x30;
Disp1Char(8,0,s[0]);
Disp1Char(9,0,s[1]);
DispStr(2,0,"light");
DispStr(3,1,"I Love You");
while(1)
{
PCOUT=light;
s[0]=light/10+0x30;
s[1]=light%10+0x30;
Disp1Char(8,0,s[0]);
Disp1Char(9,0,s[1]);
__delay_cycles(100000);
}
}
/*******************中断服务函数***********************/
#pragma vector=USCI_A3_VECTOR
__interrupt void USCI_A3_ISR(void) //串口0中断
{
switch(__even_in_range(UCA3IV,4)) //判断 USCI A0 Interrupt Vector Register Value
{
case 0:break; // Vector 0 - no interrupt
case 2: // Vector 2 - RXIFG
while (!(UCA3IFG&UCTXIFG));
UCA3TXBUF = UCA3RXBUF;
light=UCA3RXBUF;
break;
case 4:break; // Vector 4 - TXIFG
default: break;
}
}
为什么在初始化系统时钟后串口中断接收发送功能就无法运用?当注释掉初始化系统时钟那句后串口中断就可以接收发送。
|