历史上的今天
今天是:2025年03月11日(星期二)
2020年03月11日 | MSP430F149单片机实现uart数据接收中断
2020-03-11 来源:eefocus
/*****************************************************
程序功能:MCU不停向PC机发送数据,在屏幕上显示0~127对应
的ASCII字符
------------------------------------------------------
通信格式:N.8.1, 9600
------------------------------------------------------
测试说明:打开串口调试精灵,正确设置通信格式,观察屏幕
******************************************************/
#include typedef unsigned char uchar; typedef unsigned int uint; extern void Delays(void); extern uchar GetChar(void); extern void PutChar(uchar c); extern void PutString(uchar *ptr); extern void InitUART(void); static uchar pstr = 'A'; /********************主函数**********************/ void main(void) { uchar *tishi = " MCU sends 0~127 to PC and the n screen will display their corresponding n ASCII code as follows:"; uchar value = 0; //uchar c; int i = 10; int j = 100; WDTCTL = WDTPW + WDTHOLD; // 关狗 InitUART(); _EINT(); //打开全局中断 while(i--) { while (!(IFG1 & UTXIFG0)); TXBUF0 = value++; value &= 0x7f; // 保证value的数值小于128 while (!(IFG1 & UTXIFG0)); TXBUF0 = 'n'; Delays(); } PutString(tishi); while(j--) { PutChar(pstr); //if(IFG1 & URXIFG0) //如果收到字符 //c = RXBUF0; //PutChar(c); Delays(); } while(1) { Delays(); } } #include typedef unsigned char uchar; typedef unsigned int uint; void Delays(void); uchar GetChar(void); void PutChar(uchar c); void PutString(uchar *ptr); void InitUART(void); /******************************************* 函数名称:GetChar 功 能:向开发板发送字符 参 数:无 返回值 :char ********************************************/ uchar GetChar(void) { uchar c; while(URXIFG0 == 1); c = RXBUF0; return c; //将收到的字符发送出去 } /******************************************* 函数名称:PutChar 功 能:向开发板发送字符 参 数:uchar 返回值 :无 ********************************************/ void PutChar(uchar c) { while (!(IFG1 & UTXIFG0)); TXBUF0 = c; //将收到的字符发送出去 } /******************************************* 函数名称:PutSting 功 能:向PC机发送字符串 参 数:无 返回值 :无 ********************************************/ void PutString(uchar *ptr) { while(*ptr != '




