Home > other >  STM8 uart communication
STM8 uart communication

Time:09-28

# include "pbdata. H"
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: UART1_Congfiguration
Note: * function UART1 configuration function
* parameters: no
No
* to return back to value:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void UART1_Congfiguration (void)
{
//configure a serial port parameters as follows: 115200 baud rate, 8 data bits, 1 stop bit, no check, banning synchronous transmission, receive send
UART1_Init ((u32) 115200, UART1_WORDLENGTH_8D UART1_STOPBITS_1, UART1_PARITY_NO, UART1_SYNCMODE_CLOCK_DISABLE, UART1_MODE_TXRX_ENABLE);
UART1_ITConfig (UART1_IT_RXNE_OR, ENABLE);//that can receive interrupt
UART1_Cmd (ENABLE);//can make UART1
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* letter of several: UART1_Send_Byte
Note: * function UART1 to send data function
* parameters: u8 byte at a time one byte
No
* to return back to value:* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void UART1_Send_Byte (u8 byte)
{
UART1_SendData8 (byte);//UART1 send 8 bits of data
While (UART1_GetFlagStatus (UART1_FLAG_TXE)==RESET);//waiting to send complete
}

Void UART1_Printf_Demo (void)
{
//under-16 d2=123;
//u32 d1=12345678;
//u8 d3='a';
//u8 d5 [5].
Double d4 (double)=145.23412;


Printf (" % d % d \ r \ n ", (under-16) d4, Get_decimal (d4, 4));

Printf (" % d % d \ r \ n ", (under-16) d4, Get_decimal (d4, 2));

//printf (" % ld \ r \ n, d1);


//printf (" % d \ r \ n "6.4, d2);
//printf (" % 8 x \ r \ n ", d2);
//printf (" % X \ r \ n ", d2);

//printf (" % c \ r \ n ", d3);

/* d5 [0]='a';
D5 [1]='b';
D5 [2]='c';
D5 [3]='d';
D5 [4]='\ 0';

Printf (" % s \ r \ n ", d5); */

While (1);
}


//the printf function
# ifdef __GNUC__
# define PUTCHAR_PROTOTYPE int __io_putchar int (ch)
# the else
# define PUTCHAR_PROTOTYPE int fputc (int ch, FILE * f)
# endif __GNUC__/* */

PUTCHAR_PROTOTYPE//send a character agreement
{
/* will Printf content delivered to a serial port */
UART1_SendData8 (unsigned char) (ch);
while (! (UART1 - & gt; The SR & amp; UART1_FLAG_TXE));//if send unfinished,//sign bit not setting, the circular wait
Return (ch);
}
  • Related