一个简单的问题:关于STM8串口使用疑惑。。。
这几天在使用3合1板子,在用到串口时,不能收发数据不知道是什么原因;使用光盘例程也是这样,望大侠、高手们指点一下,
相关的代码如下:(STVD编译器)
时钟初始化
void CLK_Init(void)
{
/* Configure HSI prescaler*/
CLK_CKDIVR &= ~0x10; /* 01: fHSI= fHSI RC output/2. */
/* Configure CPU clock prescaler */
CLK_CKDIVR |= 0x01; /* 001: fCPU=fMASTER/2. */
}
串口初始化
void UART1_INT(void)
{
/* LINUART configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Receive and transmit enabled
- LINUART Clock disabled
*/
CLK_PCKENR1 |= 0X08; //开启时钟
LINUART_CR1 = 0x00;
LINUART_CR3 = 0x00;
LINUART_BRR2 = 0x03;
LINUART_BRR1 = 0x02;
LINUART_CR2 = 0x2C;
}
I/O初始化
PD_DDR |= 0x3D; /* Output. */
PD_CR1 |= 0xFD; /* PushPull. */
PD_CR2 = 0x00;
主程序
void main(void)
{
_asm("sim");
CLK_Init();
GPIO_Init();
UART1_INT();
PD_ODR=0x04;
_asm("rim");
while (1)
{}
}
中断相关
@far @interrupt void UART1_RX_IRQHandler(void)
{
unsigned char ch;
ch=LINUART_DR;
if(ch==0x0A)PD_ODR ^= 0x01;
return;
}
{0x82, USART_TX}, /* irq20 */
{0x82, UART1_RX_IRQHandler}, /* irq21 */ |