求嵌入式大神指点
本人学生一枚,最近在做期末课设设计,题目是无线数据采集,但是因为没有设备,老师让我用串行通信做,以下是我现在的代码,也不知道思路和方向对不对,而且总觉得代码太简单太少,求大神指点#include <stdio.h>
// 引入相关芯片的头文件
#include <LPC2103.H>
#include "TFT018.h"
/*----------------------------------------------------------*\
| TYPE DEFINE |
\*----------------------------------------------------------*/
typedef char S8;
typedef unsigned char U8;
typedef short S16;
typedef unsigned short U16;
typedef int S32;
typedef unsigned int U32;
typedef long long S64;
typedef unsigned long long U64;
typedef unsigned char BIT;
typedef unsigned int BOOL;
// 发光管接在P0.3引脚
#define LED (1<<3)
/*----------------------------------------------------------*\
| Delay ns |
\*----------------------------------------------------------*/
void DelayNS (U32 dly) {
U32 i;
for ( ; dly>0; dly--)
for (i=0; i<5000; i++);
}
/*----------------------------------------------------------*\
| UART0 Initial |
\*----------------------------------------------------------*/
void UART0_init(void) {
unsigned short int fdiv;
PINSEL0 |= 0x00000005; // 设置I/O连接到UART0
U0LCR = 0x83; // DLAB = 1,可设置波特率
fdiv = (60000000/16)/9600;
U0DLM= fdiv/256;
U0DLL = fdiv%256;
U0LCR = 0x03;
}
/*----------------------------------------------------------*\
| UART0 Send Char |
\*----------------------------------------------------------*/
void UART0_PutCh(unsigned char Ch) {
U0THR = Ch; // 发送数据
while( (U0LSR&0x40)==0 ); // 等待数据发送完毕
}
/*----------------------------------------------------------*\
| UART0 Send String |
\*----------------------------------------------------------*/
void UART0_PutStr(unsigned char const *str) {
while(*str)
UART0_PutCh(*str++); // 发送数据
}
/*----------------------------------------------------------*\
| UART0 Get Char |
\*----------------------------------------------------------*/
unsigned char UART0_GetCh(void) {
while( (U0LSR&0x01)==0 );
return U0RBR;
}
int main(void) {
unsigned char s[]="";
IODIR=LED; //设置LED控制口为输出
IOCLR=LED;
UART0_init();
for(;;) {
UART0_PutStr(s);
s[0]=UART0_GetCh();
if(s[0] == '0'){
IOCLR = LED;
}
if(s[0] == '1'){
IOSET = LED;
}
UART0_PutCh(s[0]);
DelayNS(10);
}
}
[此贴子已经被作者于2017-7-10 21:33编辑过]