共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 跳转至页
回复
打赏帖 | |
---|---|
C语言函数宏的三种封装方式被打赏50分 | |
【STM32F769】记一次由于开启D-Cache之后DMA数据传输出错的问题查找与解决被打赏35分 | |
嵌入式LinuxC语言程序调试和宏使用技巧被打赏50分 | |
让代码中包含最新的编译时间信息被打赏50分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769LVGL优化显示被打赏26分 | |
rtthread硬件加密--2crc加密分析被打赏10分 | |
【分享开发笔记,赚取电动螺丝刀】STM32F769驱动ST7789以及显示优化被打赏36分 | |
【分享开发笔记,赚取电动螺丝刀】S32K146 PAL模拟I2C驱动适配被打赏23分 | |
我想要一部加热台+电源硬件设计规范被打赏16分 | |
我想要一部加热台+LED背光驱动芯片RT9293知识被打赏18分 |