共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 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| 片外存储Flash使用方法(Arduino IDE环境)被打赏¥22元 | |
| 三分钟快速上手ESP-NOW(ArduinoIDE环境)被打赏¥23元 | |
| 【S32K3XX】LPSPI参数配置说明被打赏¥21元 | |
| 在WT9932C61-TINY上实现超声波测距被打赏¥22元 | |
| 基于WT9932C61-TINY的环境构建及OLED屏驱动测试被打赏¥20元 | |
| 【S32K3XX】Core-to-Core 中断使用被打赏¥21元 | |
| 「AI编程记录--含源码」用一晚上的时间写一个esp32的示波器被打赏¥19元 | |
| STM32C0116DK开发探索记(3)被打赏¥30元 | |
| STM32C0116DK开发探索记(2)被打赏¥24元 | |
| STM32C0116DK开发探索记(1)被打赏¥29元 | |
我要赚赏金
