uart.c

来自「msp430+无线芯片cc1020程序」· C语言 代码 · 共 56 行

C
56
字号

#include "main.h"

void uart_init(void)
{

        /* UART1 is used to configure the transceiver ... */


	U0CTL|=SWRST;

        // 8 bit char...
	U0CTL=SWRST|0x10;
	// U1TCTL=0011 0001
	U0TCTL=0x31;            /* no wakeup, use SMCLK for baud clock */
	U0RCTL=0;               /* no wakeup, no error interrupt */
	// baud rate


        /* http://mspgcc.sourceforge.net/baudrate.html  ;-) */

	U0BR0=0x56;
	U0BR1=0x00;
	U0MCTL=0x94;

        /* Port configuration ...*/

	P3SEL |= 0x30;    // P3.4,5 = USART0 TXD/RXD

	// enable module
	ME1|=UTXE0|URXE0;
	

	//clear flags ....
	IFG1&=~(UTXIFG0|URXIFG0);
        U0CTL&=~SWRST;

        /* At the moment I don't want any kind of interrupt here ....*/

	//IE2|=UTXIE1|URXIE1;

}


int putchar(int ch)
{

  //char dummy;

  while(!(IFG1 & UTXIFG0));


  TXBUF0 = ch;

  return ch;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?