#include<iostm8l152c6.h>
void UART1_Init(unsigned int baudrate)
{
unsigned int baud; //
CLK_PCKENR1_bit.PCKEN15 = 1; //使能USART模块时钟
baud = 16000000 / baudrate; //设定串口相应波特率与串口时钟的分频数
//先写BRR2 , 再写BRR1
USART1_BRR2 = ((unsigned char)((baud & 0xf000) >> 8 )) | ((unsigned char)(baud & 0x000f)); //先写波特比率的高4位与低4位
USART1_BRR1 = ((unsigned char)((baud & 0x0ff0) >> 4)); //后写波特比率的中间8位
USART1_CR1_bit.USARTD = 0; //使能UART0
USART1_CR2_bit.RIEN = 0; //使能中断接收
USART1_CR2_bit.TEN = 1; //使能发送
USART1_CR2_bit.REN = 0; //接收使能
}
void Uart_SendData(unsigned char data)
{
while(!(USART1_SR&0X80)); //判断发送数据寄存器是否为空
USART1_DR = data; //向发送寄存器写入数据
}
int main(void)
{
CLK_CKDIVR = 0x00;
UART1_Init(9600);
while(1)
{
Uart_SendData(0xff);
}
}
这是程序,下载后串口助手没有收到数据是什么原因?
也找了两个人看,都没看出问题来,所以来论坛找找大神,请大神给予指点!谢谢了!!!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
你能不能发个完整的程序出来给我看看,我看你用的这个头文件跟我的都不一样呢,我用的是<STM8L052C6.h>,而你用的是<iostm8l152c6.h>
硬件应该是没问题的,这块板是公司前辈以前用的,那时候他们用都没问题,现在轮到我就不行了
我把你这个程序复制进去编译出现好多错误:
#error cpstm8 main.c:1 can't open iostm8l152k4.h
#error cpstm8 main.c:8(18+7) bad struct/union operand
#error cpstm8 main.c:15(17+6) bad struct/union operand
#error cpstm8 main.c:16(17+4) bad struct/union operand
#error cpstm8 main.c:17(17+3) bad struct/union operand
#error cpstm8 main.c:18(17+3) bad struct/union operand
#error cpstm8 main.c:16(2+14) USART1_CR2_bit undefined
#error cpstm8 main.c:15(2+14) USART1_CR1_bit undefined
#error cpstm8 main.c:13(2+11) USART1_BRR1 undefined
#error cpstm8 main.c:12(2+11) USART1_BRR2 undefined
#error cpstm8 main.c:8(2+15) CLK_PCKENR1_bit undefined
#error cpstm8 main.c:24(10+9) USART1_SR undefined
#error cpstm8 main.c:25(2+9) USART1_DR undefined
#error cpstm8 main.c:32(5) missing prototype
#error cpstm8 main.c:35(5) missing prototype
#error cpstm8 main.c:33(2+10) CLK_CKDIVR undefined
#error cpstm8 main.c:44(0+11) missing ;
#error cpstm8 main.c:46(19) missing ;
#error cpstm8 main.c:50(19) incomplete declaration
#error cpstm8 main.c:51(21) redeclared external Uart_SendData
#error cpstm8 main.c:51(22) missing ;
#error cpstm8 main.c:54(0) incomplete declaration
main.c:
The command: "cxstm8 -ic:usersadministratordesktopstm8资料头文件 -i"....program filesstmicroelectronicsst_toolsetinclude" +debug -pxp -no -l +mods0 -pp -i"D:Program FilesSTMicroelectronicsHstm8" -clDebug -coDebug main.c " has failed, the returned value is: 1
exit code=1.
led_flash.elf - 23 error(s), 0 warning(s)
一周热门 更多>