共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电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
“我踩过的那些坑”主题活动——第001期 | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【我踩过的那些坑】结构堵孔导致的喇叭无声问题被打赏50分 | |
【我踩过的那些坑】分享一下调试一款AD芯片的遇到的“坑”被打赏50分 | |
电流检测模块MAX4080S被打赏10分 | |
【我踩过的那些坑】calloc和malloc错误使用导致跑飞问题排查被打赏50分 | |
多组DCTODC电源方案被打赏50分 | |
【我踩过的那些坑】STM32cubeMX软件的使用过程中的“坑”被打赏50分 | |
新手必看!C语言精华知识:表驱动法被打赏50分 | |
【我踩过的那些坑】杜绑线问题被打赏50分 | |
【我踩过的那些坑】STM32的硬件通讯调试过程的“坑”被打赏50分 | |
【我踩过的那些坑】晶振使用的问题被打赏100分 |