- 打卡等级:初来乍到
- 打卡总天数:5
- 最近打卡:2024-08-14 23:38:41
注册会员
- 积分
- 83
|
用官方USB转单串口例程做修改,使用串口助手
给STC的UART串口发送0x59时点亮STC的LED灯。
使用例程原波特率115200时可以正常点亮,
当把波特率改为9600时无法点亮LED。
查看虚拟串口收到的数据是0x59,
红色是修改部分。
void uart_init()
{
P_SW2 &= ~0x01; //UART2 switch to: 0: P1.0 P1.1
P1M0 &= ~0x03; //P1.0,P1.1设置为准双向模式
P1M1 &= ~0x03;
S2CON = 0x50;
T2L = BR(9600);
T2H = BR(9600) >> 8;
AUXR |= 0x14; //定时器2时钟1T模式,开始计时
IE2 |= 1; //允许中断
LineCoding.dwDTERate = REV4(9600);
LineCoding.bCharFormat = 0;
LineCoding.bParityType = 0;
LineCoding.bDataBits = 8;
}
void uart_polling()
{
BYTE dat;
BYTE cnt;
if (DeviceState != DEVSTATE_CONFIGURED)
return;
if (!UsbInBusy && (TxRptr != TxWptr))
{
if(TxBuffer[0]==0x59)
{ LED = 0; }
IE2 &= ~0x80; //EUSB = 0;
UsbInBusy = 1;
usb_write_reg(INDEX, 1);
cnt = 0;
while (TxRptr != TxWptr)
{
usb_write_reg(FIFO1, TxBuffer[TxRptr++]);
cnt++;
if (cnt == EP1IN_SIZE) break;
}
usb_write_reg(INCSR1, INIPRDY);
IE2 |= 0x80; //EUSB = 1;
}
|
|