新闻  |   论坛  |   博客  |   在线研讨会
Freescale MCF52211 UART演示程序
mayer | 2009-06-15 18:33:05    阅读:1367   发布文章

Freescale MCF52211 UART演示程序

 

P&E的BDM仿真器买回来了,在我的MCF52211板子上很正常,看来华恒的那个开源BDM有问题,那个BDM我不知道是什么原因,就是没办法调试MCF52211,也不知道是TBLCF本身不支持MCF52211,还是华恒没有把这个东西做好。

下面贴个调试通过的MCF52211 UART的demo程序,供参考

 


 

#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 <stdio.h>
#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++;
 }
}

*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。

参与讨论
登录后参与讨论
推荐文章
最近访客