那位高手高手我stm8串口怎么调试以前学51的时候可以用串口调试助手现在不知道能不能用这个下面是配套的程序。
#include "STM8S105C_S.h" /* Registers and memory mapping file. */
#include "stdio.h"
void main(void)
{
unsigned int i;
unsigned char counter;
/*High speed internal clock prescaler: 1*/
CLK_CKDIVR = 0x00;
UART2_CR2 = 0x00; //disable Tx & Rx
/* UART2 configured as follow:
- BaudRate = 115200 baud
- Word Length = 8 Bits
- One Stop Bit
- No parity
- Receive and transmit enabled
- UART2 Clock disabled
*/
/* Configure UART1 */
UART2_CR1 = 0x00;
UART2_CR3 = 0x00;
UART2_BRR2 = 0x0B;
UART2_BRR1 = 0x08;
UART2_CR2 = 0x0C;
counter = 0;
while(1)
{
/* Output a message on Hyperterminal using printf function */
printf("\nUART2 Example :Please press 1 key from keyboard. \n");
for (i=0;i<10000;i++);
/* Loop until the UART2 Receive Data Register is not empty */
while (!(UART2_SR & 0x20));
/* Store the received byte in RxBuffer */
RxBuffer = UART2_DR;
printf("Key Pressed = %c.\n",RxBuffer);
}
}
char putchar (char c)
{
if (c == '\n')
{
/* put '\r' to hardware here */
/* Wait transmission is completed : otherwise the first data is not sent */
while (!(UART2_SR & 0x40));
UART2_DR = ('\r');
/* Wait transmission is completed */
while (!(UART2_SR & 0x40));
}
/* put c to hardware here */
/* Wait transmission is completed : otherwise the first data is not sent */
while (!(UART2_SR & 0x80));
UART2_DR = (c);
/* Wait transmission is completed */
while (!(UART2_SR & 0x80));
return (c);
} |