AET

ChinaAET 博客代码插入功能上线

0
阅读(2427)

对于工程师博客来说,经常都需要在博客中插入代码。如何让插入的代码看上去友好又整洁呢?ChinaAET的博客代码插入功能能为您解决这个问题。

发布博客的时候点击编辑框上部的这个按钮,剩下的工作根据指示完成就可以啦。

举例插入bluehacker的《Freescale MCF52211 UART演示程序》一文中的代码,如下所示,看上去是不是非常顺眼呢?

#include "support_common.h" /* include peripheral declarations and more */
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)
/* Standard IO is only possible if Console or UART support is enabled. */
#include 
#endif
void uart0_init(unsigned long baudrate)
{
    register uint16 div;
   
    MCF_GPIO_PUAPAR =0x05;
 /*
  * Reset Transmitter
  */
 MCF_UART0_UCR =MCF_UART_UCR_RESET_TX;
 /*
  * Reset Receiver
  */
 MCF_UART0_UCR = MCF_UART_UCR_RESET_RX;
 /*
  * Reset Mode Register
  */
 MCF_UART0_UCR = MCF_UART_UCR_RESET_MR;
 
 /*
 * No parity, 8bit data
 */
 MCF_UART0_UMR1=(0
  | MCF_UART_UMR_PM_NONE
  | MCF_UART_UMR_BC_8 );
 /*
 * 1bit stop
 */
 MCF_UART0_UMR2=(0
  | MCF_UART_UMR_CM_NORMAL
  | MCF_UART_UMR_SB_STOP_BITS_1);
 /*
  * Set Rx and Tx baud by SYSTEM CLOCK
  */
 MCF_UART0_UCSR = (0
  | MCF_UART_UCSR_RCS_SYS_CLK
  | MCF_UART_UCSR_TCS_SYS_CLK);
 /*
  * Mask all UART interrupts
  */
 MCF_UART0_UIMR = 0;
 /* set baud rate
 */
 div=(uint16)(60000000L/(32*baudrate));
 
 MCF_UART0_UBG1=(unsigned char)(div>>8);
 MCF_UART0_UBG2=(unsigned char)(div&0x00ff);
 
 /* Enable Tx/Rx*/
 MCF_UART0_UCR = (0
  | MCF_UART_UCR_TX_ENABLED
  | MCF_UART_UCR_RX_ENABLED);
}
void uart0_putchar(unsigned char c)
{
  /* Wait until space is available in the FIFO */
    while (!(MCF_UART0_USR & MCF_UART_USR_TXRDY))
    {
    
    };
    /* Send the character */
    MCF_UART0_UTB = c;
}
unsigned char uart0_getchar()
{
  /* Wait until character has been received */
    while (!(MCF_UART0_USR & MCF_UART_USR_RXRDY))
    {
    
    };
    return MCF_UART0_URB;
}

void uart0_putstr(unsigned char *str)
{
 while(*str!=0)
 {
  uart0_putchar(*str++);
 }
}

int main(void)
{
 int counter = 0;
    unsigned char c="0";
 
#if (CONSOLE_IO_SUPPORT || ENABLE_UART_SUPPORT)
 printf("Hello World in C from MCF52211 derivative on MCF52211 board\n\r");
 fflush(stdout);
#endif
 uart0_init(9600);
 uart0_putstr((unsigned char*)("MCF52211 Uart0 test start\n"));
 for(;;) {
  c=uart0_getchar();
  uart0_putchar(c);  
     counter++;
 }
}