?? uart0.c
字號:
#include <msp430.h>
#include "eeprom.h"
#include <ctype.h>
typedef unsigned char uchar;
/*******************************************
函數名稱:InitUART
功 能:初始化UART端口
參 數:無
返回值 :無
********************************************/
void InitUART(void)
{
P3SEL |= 0x30; // P3.4,5 = USART0 TXD/RXD
ME1 |= URXE0 + UTXE0; // Enable USART0 T/RXD
UCTL0 |= CHAR; // 8-bit character
UTCTL0 |= SSEL0; // UCLK = ACLK
UBR00 = 0x03; // 32k/9600 - 3.41
UBR10 = 0x00; //
UMCTL0 = 0x4A; // Modulation
UCTL0 &= ~SWRST; // Initialize USART state machine
}
/*******************************************
函數名稱:Send1Char
功 能:向PC機發送一個字符
參 數:sendchar--要發送的字符
返回值 :無
********************************************/
void Send1Char(uchar sendchar)
{
while (!(IFG1 & UTXIFG0)); //等待發送寄存器為空
TXBUF0 = sendchar;
}
/*******************************************
函數名稱:PutSting
功 能:向PC機發送字符串
參 數:ptr--指向發送字符串的指針
返回值 :無
********************************************/
void PutString(uchar *ptr)
{
while(*ptr != '\0')
{
Send1Char(*ptr++); // 發送數據
}
while (!(IFG1 & UTXIFG0));
TXBUF0 = '\n'; //發送換行指令
}
/*******************************************
函數名稱:Get1Char
功 能:接收一個來自PC機的字符
參 數:無
返回值 :接收到的字符
********************************************/
uchar Get1Char(void)
{
while (!(IFG1 & URXIFG0)); //等待接收到字符
return RXBUF0;
}
/*******************************************
函數名稱:Get1Char
功 能:接收一個來自PC機的字符
參 數:無
返回值 :接收到的字符
********************************************/
void DisplayConfigMenu(void)
{
PutString("Choose Read or Write operation:");
PutString("R-- Read a char from EEPROM");
PutString("W-- Write a char from EEPROM");
PutString("*-- any other key to redispaly the menu");
}
/*******************************************
函數名稱:HandleConfigMenu
功 能:處理PC的配置函數
參 數:inputvalue--接收到的來自PC機的字符
返回值 :無
********************************************/
void HandleConfigMenu(uchar inputvalue)
{
uchar addr,wdata,result;
uchar hi,lo;
switch(toupper(inputvalue))
{
case 'R':
PutString("Please send the memory address to read:");
addr = Get1Char();
Send1Char('>'); Send1Char('\n');
result = Read_1Byte_Randomaddress(addr);
Send1Char(0x30); //屏幕顯示0
Send1Char(0x78); //屏幕顯示x
hi = (result & 0xf0) >> 4;
if(hi > 0x09)
{
Send1Char(0x37 + hi); //屏幕顯示字母(A~F)
}
else
{
Send1Char(0x30 + hi); //屏幕顯示數字
}
lo = result & 0x0f;
if(lo > 0x09)
{
Send1Char(0x37 + lo); //屏幕顯示字母(A~F)
}
else
{
Send1Char(0x30 + lo); //屏幕顯示數字
}
Send1Char('\n');
break;
case 'W':
PutString("Please send the memory address to write:");
addr = Get1Char();
Send1Char('>'); Send1Char('\n');
PutString("Please send the data to write:");
wdata = Get1Char();
Send1Char('>'); Send1Char('\n');
if( Write_1Byte(wdata,addr) )
{
PutString("Write successfully!");
}
else
{
PutString("Fail to write!");
}
break;
default:
DisplayConfigMenu();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -