?? uratsend.c
字號:
/*********************************************************************
Author :
Date : jul. 2008
File : UARTSend.c
Hardware : LPC2132
Description : Send data through the Uart0
*********************************************************************/
#include<LPC2103.H>
#define Fosc 11059200
#define Fcclk Fosc*4
#define Fpclk (Fosc*5/4)
#define UART_br 9600
/*****************Inital Uart***********************/
void UART0_Init() //UART0初始化;
{ unst16 Fdiv;
U0LCR=0x83; //使能除數(shù)鎖存寄存器U0DLL,U0DLM;
// 1000 0011 /bit8 enable access to the divisor latch
// bit0,bit1 word width select 11 8bit
Fdiv=(Fpclk/16)/UART_br; //0<DIVADDVAL=0<15,1<MULVAL=1<15 -->U0FDR Resister;
U0DLM=Fdiv/256; //0x00 ;
U0DLL=Fdiv%256; //0x82 ;
U0FDR=0x10; //3:0 DIVADDVAL;7:4 MULVAL 31:8 RESERVED
U0LCR=0x03; //
}
/*****************receive data***************************/
unsigned int UART0_GetByte() //接收數(shù)據(jù);
{ unsigned char rec;
while((U0LSR&0x01)==0); //bit0=1,U0RBR包含有效數(shù)據(jù);
rec=U0RBR; //U0RBR接收緩沖寄存器;
return(rec);
}
void UART0_GetStr(unsigned char *s,unsigned int n)//接收一字符串;
{ for(;n>0;n--)
{ *s++=UART0_GetByte() ;
}
}
/*******************send data************************/
void UART0_SendByte(unsigned char dat) //發(fā)送數(shù)據(jù);
{ U0THR=dat;
while((U0LSR&0x20)==0); //bit5=0,U0THR包含有效數(shù)據(jù); bit6=0,both contain valid data;
}
void UART0_SendStr(unsigned char *str) //發(fā)送一字符串;
{ while(1)
{ if(*str=='\0') break;
UART0_SendByte(*str++);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -