共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 跳转至页
回复
我要赚赏金打赏帖 |
|
|---|---|
| 基于MCP23S17的输入输出功能模块控制被打赏¥20元 | |
| 【S32K3XX】SPD 软件包使用Link文件修改被打赏¥22元 | |
| Switch-Case局部变量定义问题被打赏¥23元 | |
| 基于米尔TIAM62L开发板的串口通信及应用被打赏¥20元 | |
| PCF8574功能模块及其使用被打赏¥20元 | |
| 传感器LSM6DSO及LIS3MDL的功能检测被打赏¥18元 | |
| LPS25HB气压传感器及其检测被打赏¥18元 | |
| HTS221温湿度传感器及其检测被打赏¥18元 | |
| 【S32K3XX】HSE FW 版本更新被打赏¥21元 | |
| 基于ArduinoUNO开发板的AT24C02读写测试被打赏¥16元 | |
我要赚赏金
