共2条
1/1 1 跳转至页
iar,compile 如何在iar C-compile 中来仿真串口?
问
请问,如何在iar C-compile 中来仿真串口?多谢先,
答 1:
extern unsigned char UartRxc,RxOk,TxOk,BitCnt;
extern unsigned int UartTxc;
void TAInit(void)
{
CCTL0=OUT; // TXD Idle as Mark
TACTL=TASSEL1+MC1; // SMCLK, 10 Continuous mode: the timer counts up to 0FFFFh
}
void RxReady(void)
{
BitCnt = 8;
CCTL0 = SCS +OUTMOD0 + CM1 + CAP +CCIE;// CCI0A input pin+ CCIS0
RxOk=1;
}
void TxByte(void)
{
CCR0 += Bitime;
UartTxc |= 0x0100; //0000 000* xxxx xxxx add stop bit
UartTxc <<= 1; //0000 00*x xxxx xxx0 add start bit
BitCnt = 10; //1+8+1
CCTL0 = OUTMOD0 + CCIE;
return;
}
#pragma vector=TIMERA0_VECTOR
__interrupt void TA0_ISR (void)
{ CCR0 += Bitime;
if ((CCTL0 & SCS) !=0) //Rx
{ if ((CCTL0 & CAP) !=0) {CCTL0 &= ~CAP;CCR0 += Bitime_5; return;} //Start Bit,delay 1.5 Bittime
else { UartRxc >>=1; //Receive a bit
if ((CCTL0 & SCCI) !=0) UartRxc |= 0x80;
BitCnt--;
if (BitCnt ==0) {RxOk=2;CCTL0 &= ~CCIE;} //Receive over, disable Ta0 interrupt
return;
}
} else { if (BitCnt==0) {TxOk=1;CCTL0 &= ~CCIE;} //Tx over, disable Ta0 interrupt
else { CCTL0 &= ~OUTMOD2;
if ((UartTxc & 0x01) != 0) CCTL0 |= OUTMOD2;
BitCnt--;
}
}
}
extern unsigned int UartTxc;
void TAInit(void)
{
CCTL0=OUT; // TXD Idle as Mark
TACTL=TASSEL1+MC1; // SMCLK, 10 Continuous mode: the timer counts up to 0FFFFh
}
void RxReady(void)
{
BitCnt = 8;
CCTL0 = SCS +OUTMOD0 + CM1 + CAP +CCIE;// CCI0A input pin+ CCIS0
RxOk=1;
}
void TxByte(void)
{
CCR0 += Bitime;
UartTxc |= 0x0100; //0000 000* xxxx xxxx add stop bit
UartTxc <<= 1; //0000 00*x xxxx xxx0 add start bit
BitCnt = 10; //1+8+1
CCTL0 = OUTMOD0 + CCIE;
return;
}
#pragma vector=TIMERA0_VECTOR
__interrupt void TA0_ISR (void)
{ CCR0 += Bitime;
if ((CCTL0 & SCS) !=0) //Rx
{ if ((CCTL0 & CAP) !=0) {CCTL0 &= ~CAP;CCR0 += Bitime_5; return;} //Start Bit,delay 1.5 Bittime
else { UartRxc >>=1; //Receive a bit
if ((CCTL0 & SCCI) !=0) UartRxc |= 0x80;
BitCnt--;
if (BitCnt ==0) {RxOk=2;CCTL0 &= ~CCIE;} //Receive over, disable Ta0 interrupt
return;
}
} else { if (BitCnt==0) {TxOk=1;CCTL0 &= ~CCIE;} //Tx over, disable Ta0 interrupt
else { CCTL0 &= ~OUTMOD2;
if ((UartTxc & 0x01) != 0) CCTL0 |= OUTMOD2;
BitCnt--;
}
}
}
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |