LED指示灯能正常工作,采用TTL转USB连接到PC机上,串口助手显示发送的数据一直为“00”;不管怎么更改都是这样的?
新手上路,请大家支招,谢谢!
#include "stm8l15x.h"
#include "stdio.h"
unsigned char i;
int temp;
char t;
void Uart2_Int(void);
void Uart3_Int(void);
void delay(unsigned int time);
void putch2(unsigned char c);
void putch3(unsigned char c);
int main( void )
{
GPIOD->ODR=0xff;
GPIOD->DDR=0XFF;
GPIOD->CR1=0XFF;
GPIOD->CR2=0X00;
CLK->ECKCR = 0X21;
while(0x02 != (CLK->ECKCR & 0x02))
{
}
CLK->SWCR = CLK_SWCR_SWEN;
CLK->SWR = 0x04;
CLK->CKDIVR = 0x04;
while(0x04 != (CLK->SCSR));
CLK->SWCR=0;
CLK->PCKENR3 = 0X18;
Uart2_Int();
Uart3_Int();
while(1)
{
GPIOD->ODR=0x0f;
putch2(1);
putch3(2);
delay(50000);
GPIOD->ODR=0xff;
delay(50000);
}
}
void Uart2_Int(void)
{
USART2->CR1=0x00;
USART2->CR2=0x08;
USART2->CR3=0X00;
USART2->BRR2=0X00;
USART2->BRR1=0X0D;
}
void Uart3_Int(void)
{
USART3->CR1=0x00;
USART3->CR2=0x08;
USART3->CR3=0X00;
USART3->BRR2=0X00;
USART3->BRR1=0X48;
}
void putch2(unsigned char ch)
{
while((USART2->SR&0x40)==0);
USART2->DR=ch;
//return c;
}
void putch3(unsigned char ch)
{
while((USART3->SR&0x80)==0);
USART3->DR=ch;
//return c;
}
void delay(unsigned int t)
{
while(t--);
} |