This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
工具/软件:Code Composer Studio
大家好,我在 P4.5引脚上尝试了使用计时器的软件 UART。 我只是将单个字符传输到控制器,但在超级终端中没有重新发送。 它的9600波特率。 请报告任何错误或更改。
.#include"driverlib.h"
在 Launchpad 上#define TX_PIN BIT5 //P4.5、XOUT
#define bit_time 104 //0x680 for 9600;
uint8_t buff Tx [64];
uint8_t * ptr_Tx;
uint8_t bitCount、flag=0;
uint16_t test_buff = 0x00、TXByte;
uint32_t 时钟= 0;
void initio (void);
void initTA1 (void);
void uartTx (uint8_t byte);
void main()
{
WDTCTL = WDTPW + WDTHOLD;//停止 WDT
PM5CTL0 &=~LOCKLPM5;
Clock=CS_getSMCLK();
_bis_SR_register (GIE);
initio();
while (1)
{
uartTx(3);
}
}
void 初始化(void)
{
P4SEL0 |= TX_PIN;
P4OUT |= BIT5;
P4DIR |= TX_PIN;
}
空 uartTx (uint8_t 字节)
{
TXByte =字节;
bitCount = 0xA;//加载位计数器、8位+ ST/SP
TXByte |= 0x100;//将停止位添加到 TXByte (逻辑1)//txbyte=0001 0000 0000
TXByte = TXByte << 1;//添加起始位(逻辑0)//0010 0000 0000
initTA1();
}
空 initTA1 (空)
{
while (TA0CCTL0和 CCIE)
{
;//等待前一个 xmit 完成
}
TA0CCR0 = TA0R;//与当前 TIMERA 计数器重新同步
TA0CCR0 += BIT_TIME;//设置下一个开始位边沿时间
TA0CTL = tassel_2 + MC_2;
TA0CCTL0 = OUT | CCIE|CCIS0;//将 EQU0上的 TX_PIN 设置为高电平并重新启用中断
}
//计时器 A0中断服务例程
#if defined (__TI_Compiler_version__)|| Defined (__IAR_systems_ICC__)
#pragma vector = TIMER0_A0_vector
_interrupt void Timer0_A0_ISR (void)
#Elif defined (_GNU_)
void __attribute__((中断(TIMER0_A0_Vector)) Timer0_A0_ISR (void)
其他
错误编译器不受支持!
#endif
{
TA0CCR0 += bit_time;//将偏移添加到 TA0CCR0
flag=(TXByte & 0x01);
如果(flag==1)
{
(P4OUT |= TX_PIN);
}
其他
{
(P4OUT &=~TX_PIN);
}
TXByte = TXByte >> 1;
bitCount --;
if (bitCount=1)
{
TA0CCR0=0;
TA0CCTL0 &=~CCIE;
}
}