九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

第六章 ARM9_串口UART及編程

上傳人:fgh****35 文檔編號:247446509 上傳時間:2024-10-18 格式:PPT 頁數(shù):63 大?。?40KB
收藏 版權申訴 舉報 下載
第六章 ARM9_串口UART及編程_第1頁
第1頁 / 共63頁
第六章 ARM9_串口UART及編程_第2頁
第2頁 / 共63頁
第六章 ARM9_串口UART及編程_第3頁
第3頁 / 共63頁

下載文檔到電腦,查找使用更方便

15 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《第六章 ARM9_串口UART及編程》由會員分享,可在線閱讀,更多相關《第六章 ARM9_串口UART及編程(63頁珍藏版)》請在裝配圖網上搜索。

1、,*,單擊此處編輯母版標題樣式,單擊此處編輯母版文本樣式,第二級,第三級,第四級,第五級,第六章,S3C2410,的串口,UART,及編程,6.1 S3C2410,的串口,UART,概述,6.1.1 S3C2410,異步串行通信(,UART,)單元,S3C2410 UART,單元提供,3,個獨立的異步串行通信接口,皆可工作于查詢、中斷和,DMA,模式。使用系統(tǒng)時鐘最高波特率達,230. 4 kb/s,,如果使用外部設備提供的時鐘,可以達到更高的速率。每一個,UART,單元包含一個,16,字節(jié)的,FIFO,(,First Input First Output,,先進先出移位寄存器),用于數(shù)據(jù)的接

2、收和發(fā)送。,S3C2410 UART,支持可編程波特率、紅外發(fā)送,/,接收,( UART2 ),、,1,個或,2,個停止位、,5,位,/6,位,/7,位,/8,位數(shù)據(jù)寬度和奇偶校驗。,6.1.2,波特率的產生,波特率由一個專用的,UART,波特率分頻寄存器,(,UBRDIVn,),控制,,UBRDIVn,值計算公,如下:,UBRDIVn=,(,int,)ULK/(,波特率, 16),1,或者,UBRDIVn=,(,int,) PLK/(,波特率, 16),1,式中:時鐘選用,ULK,還是,PLK,由,UART,控制寄存器,UCONn10,的狀態(tài)決定。如果,UCONn10=0,,則用,PLK,作

3、為波特率發(fā)生器的時鐘源頻率;否則選用,ULK,作為波特率發(fā)生器的時鐘源頻率。,UBRDIVn,的值必須在,1(216,1),之間。,例如,:,若,ULK,或者,PLK,等于,40 MHz,,當波特率為,115200 b/s,時,則,UBRDIVn=,(int)40 000 000/(115 200 16),一,1=int(21. 7),1= 21,1=20,6.1.3 UART,通信操作,下面簡略介紹,UART,操作,關于數(shù)據(jù)發(fā)送、數(shù)據(jù)接收、中斷產生、波特率產生、查詢檢測模式、紅外模式的詳細介紹,參見下面,6.3,節(jié)。,發(fā)送數(shù)據(jù)幀是可編程的。一個數(shù)據(jù)幀包含,1,個起始位、,58,個數(shù)據(jù)位、,1

4、,個可選的奇偶校驗位和,12,位停止位,停止位通過行控制寄存器,ULCONn,配置。,與發(fā)送數(shù)據(jù)幀類似,接收數(shù)據(jù)幀也是可編程的。接收幀由,1,個起始位、,58,個數(shù)據(jù)位、,l,個可選的奇偶校驗位以及,12,位行控制寄存器,ULCONn,中設定的停止位組成。接收器還可以檢測溢出錯、奇偶校驗錯、幀錯誤和傳輸中斷,每一個錯誤均可以設置一個錯誤標志。,溢出錯誤,(overrun error),:指已接收到的數(shù)據(jù)在讀取之前被新接收的數(shù)據(jù)覆蓋;,奇偶校驗錯:指接收器檢測到的校驗和與設置的不符;,幀錯誤:指沒有接收到有效的停止位;,傳輸中斷:表示接收數(shù)據(jù),RxDn,保持邏輯,0,超過一幀的傳輸時間。,在,F

5、IFO,模式下,如果,RxFIFO,非空,而在,3,個字的傳輸時間內沒有接受到數(shù)據(jù),則產生超時。,6.2 UART,的控制寄存器,6.2.1 UART,行控制寄存器,ULCONn,該寄存器的位,6,決定是否使用紅外模式,位,5,、位,4,和位,3,決定校驗方式,位,2,決定停止位長度,位,1,和位,0,決定每幀的數(shù)據(jù)位數(shù)。具體如下:,ULCONn7,保留;,ULCONn6,紅外線模式,,0,:正常模式;,1,:紅外線模式;,ULCONn5,:,3,校驗模式,,0xx,:無校驗;,100,:奇校驗;,101,:偶校驗;,ULCONn2,停止位,,0,:一個停止位;,1,:二個停止位;,ULCON

6、n1,:,0,數(shù)據(jù)位,,00,:,5,位;,01,:,6,位;,10,:,7,位;,11,:,8,位。,6.2.2 UART,控制寄存器,UCONn,該寄存器決定,UART,的各種模式。,UCONn10 1,:,ULK,做波特率發(fā)生器;,0,:,PLK,做波特率發(fā)生器。,UCONn9 1,:,Tx,中斷電平觸發(fā);,0,:,Tx,中斷脈沖觸發(fā)。,UCONn8 1,:,Rx,中斷電平觸發(fā);,0,:,Rx,中斷脈沖觸發(fā)。,UCONn7 1,:接收超時中斷允許;,0,:接收超時中斷禁止。,UCONn6 1,:產生接收錯誤中斷;,0,:不產生接收錯誤中斷。,UCONn5 l,:發(fā)送直接傳給接收方式,(l

7、oopback),;,0,:正常模式。,UCONn4 1,:發(fā)送間斷信號;,0,:正常模式發(fā)送。,UCONn,3:2,發(fā)送模式選擇:,00,:禁止發(fā)送;,01,:中斷或查詢模式;,10,:,DMA0,請求,(UART0 ),,,DMA3,請求,(UART2),;,11,:,DMAl,請求,(UART1),。,UCONn,1,:,0,接收模式選擇。,00,:禁止接收;,01,:中斷或查詢模式;,10,:,DMA0,請求,UART0,,,DMA2,請求,UART2,;,11,:,DMAl,請求,UART1,。,6.2.3 UART FIFO,控制寄存器,UFCONn,UFCONn7:6,00,:,

8、Tx,FIFO,寄存器中有,0,字節(jié)就觸發(fā)中斷;,01,:,Tx,FIFO,寄存器中有,4,字節(jié)就觸發(fā)中斷;,10,:,Tx,FIFO,寄存器中有,8,字節(jié)就觸發(fā)中斷;,11,:,Tx,FIFO,寄存器中有,12,字節(jié)就觸發(fā)中斷。,UFCONn5:4,00,:,Rx FIFO,寄存器中有,4,字節(jié)就觸發(fā)中斷;,01,:,Rx FIFO,寄存器中有,8,字節(jié)就觸發(fā)中斷;,10,:,Rx FIFO,寄存器中有,12,字節(jié)就觸發(fā)中斷;,11,:,Rx FIFO,寄存器中有,16,字節(jié)就觸發(fā)中斷。,UFCONn,3,保留。,UFCONn,2 1,:,FIFO,復位清零,Tx,FIFO,;,0,:,FI

9、FO,復位不清零,TxFIFO,。,UFCONn,1 1: FIFO,復位清零,Rx FIFO,;,0,:,F1FO,復位不清零,RxFIFO,。,UFCONn,0 1,:允許,FIFO,功能;,0,:禁止,FIFO,功能。,6.2.4 UART MODEM,控制寄存器,UMCONn,UMCONn,7,:,5,保留,必須全為,0,。,UMCONn,4 1,:允許使用,AFC,模式;,0,:禁止使用,AFC,模式。,UMCONn,3,保留,必須全為,0,。,UMCONn0 1,:激活,rRTS,;,0,:不激活,rRTS,。,6.2.5,發(fā)送寄存器,UTXH,和接收寄存器,URXH,這兩個寄存器

10、存放發(fā)送和接收的數(shù)據(jù),當然只有,1,字節(jié),(8,位數(shù)據(jù),),。需要注意的是,在發(fā)生溢出錯誤時,接收的數(shù)據(jù)必須被讀出來,否則會引發(fā)下次溢出錯誤。,6.2.6,發(fā)送和接收狀態(tài)寄存器,UTRSTATn,UTRSTATn,發(fā)送和接收狀態(tài)寄存器包括,UTRSTAT0, UTRSTAT1 and UTRSTAT2,UTRSTATn,寄存器各位定義:,UTRSTATn,1,發(fā)送緩沖器空標志,0 =,不空;,1 =,空。,UTRSTATn,0,接收緩沖器有接收數(shù)據(jù)標志,0 =,空;,1 =,接收緩沖器有數(shù)據(jù)。,6.2.7,波特率分頻寄存器,UBRDIV,波特率分頻寄存器,UBRDIV,的定義和使用在,6.1.

11、2,中已敘述,不再重復。,6.2.8 UART,單元各寄存器的定義,在隨書提供的軟件包,2410test,中,在,2410addr.h,文件中有關于,UART,單元各寄存器的定義。,/UART,#define rULCON0 ( * (volatile unsigned * )0x50000000)/UART 0 Line control,#define rUCON0 ( * (volatile unsigned * )0x50000004)/UART 0 control,#define rUFCON0 ( * (volatile unsigned * )0x50000008)/UART 0

12、FIFO control,#define rUMCON0 ( * (volatile unsigned * )0x5000000c)/UART 0 Modem control,#define rUTRSTAT0 ( * (volatile unsigned * )0x50000010)/UART 0,Tx,/Rx status,#define rUERSTAT0 ( * (volatile unsigned * )0x50000014)/UART 0 Rx error status,#define rUFSTAT0 ( * (volatile unsigned * )0x50000018)/U

13、ART 0 FIFO status,#define,rUMSTAT0 ( * (volatile unsigned * )0x5000001c)/UART 0 Modem status,#define,rUBRDIV0 ( * (volatile unsigned * )0x50000028)/UART 0 Baud rate,diviaor,#define,rULCON1 ( * (volatile unsigned * )0x50004000)/UART 1 Line control,#define,rUCON1 ( * (volatile unsigned * )0x50004004)/

14、UART 1 Control,#define,rUFCON1 ( * (volatile unsigned * )0x50004008)/UART 1 FIFO control,#define,rUMCON1 ( * (volatile unsigned * )0x5000400c)/UART 1 Modem control,#define,rUTRSTAT1 ( * (volatile unsigned * )0x50004010)/UART 1,Tx,/Rx status,#define,rUERSTAT1 ( * (volatile unsigned * )0x50004014)/UAR

15、T 1 Rx error status,#define rUFSTAT1 ( * (volatile unsigned * )0x50004018)/UART 1 FIFO status,#define rUMSTAT1 ( * (volatile unsigned * )0x5000401c)/UART 1 Modem status,#define rUBRDIV1 ( * (volatile unsigned * )0x50004028)/UART 1 Baud rate divisor,#define rULCON2 ( * (volatile unsigned * )0x5000800

16、0)/UART 2 Line control,#define rUCON2 ( * (volatile unsigned * )0x50008004)/UART 2 Control,#define rUFCON2( * (volatile unsigned * )0x50008008)/UART 2 FIFO control,#define rUMCON2 ( * (volatile unsigned * )0x5000800c)/UART 2 Modem control,#define rUTRSTAT2 ( * (volatile unsigned * )0x50008010)/UART

17、2,Tx,/Rx status,#define rUERSTAT2 ( * (volatile unsigned * )0x50008014)/UART 2 Rx error status,#define rUFSTAT2 ( * (volatile unsigned * )0x50008018)/UART 2 FIFO status,#define rUMSTAT2 ( * (volatile unsigned * )0x5000801c)/UART 2 Modem status,#define rUBRDIV2 ( * (volatile unsigned * )0x50008028)/U

18、ART 2 Baud rate divisor,#ifdef_BIG_ENDIAN,#define,rUTXH0 ( * (volatile unsigned char * )0x50000023)/UART 0 Transmission Hold,#define,rURXH0 ( * (volatile unsigned char * )0x50000027)/UART 0 Receive buffer,#define,rUTXH1 ( * (volatile unsigned char * )0x50004023)/UART 1 Transmission Hold,#define,rURX

19、H1 ( * (volatile unsigned char * )0x50004027)/UART 1 Receive buffer,#define,rUTXH2 ( * (volatile unsigned char * )0x50008023)/UART 2 Transmission Hold,#define rURXH2 ( * (volatile unsigned char * )0x50008027)/UART 2 Receive buffer,#define WrUTXH0(ch) ( * (volatile unsigned char * )0x50000023)=(unsig

20、ned char)(,ch,),#define RdURXH0() ( * (volatile unsigned char * )0x50000027),#define WrUTXH1(ch) ( * (volatile unsigned char * )0x50004023)=(unsigned char)(,ch,),#define RdURXH1() ( * (volatile unsigned char * )0x50004027),#define WrUTXH20(ch) ( * (volatile unsigned char * )0x50008023)=(unsigned cha

21、r)(,ch,),#define RdURXH2() ( * (volatile unsigned char * )0x50008027),#difine,UTXH0 (0x50000020+3) /,Byte_access,address by DMA,#define URXH0 (0x50000024+3),#difine,UTXH1 (0x50004020+3),#define URXH1 (0x50004024+3),#difine,UTXH2 (0x50008020+3 ),#define URXH2 (0x50008024+3),#else/Little,Endian,#defin

22、e rUTXH0 ( * (volatile unsigned char * )0x50000020)/UART 0 Transmission Hold,#define rURXH0 ( * (volatile unsigned char * )0x50000024)/UART 0 Receive buffer,#define rUTXH1 ( * (volatile unsigned char * )0x50004020)/UART 1 Transmission Hold,#define rURXH1 ( * (volatile unsigned char * )0x50004024)/UA

23、RT 1 Receive buffer,#define rUTXH2 ( * (volatile unsigned char * )0x50000820)/UART 2 Transmission Hold,#define,rURXH2 ( * (volatile unsigned char * )0x50008024)/UART 2 Receive buffer,#define,WrUTXH0(,ch,) ( * (volatile unsigned char * )0x50000020)=(unsigned char)(,ch,),#define,RdURXH0() ( * (volatil

24、e unsigned char * )0x50000024),#define,WrUTXH1(ch) ( * (volatile unsigned char * )0x50004020)=(unsigned char)(,ch,),#define RdURXH1() ( * (volatile unsigned char * )0x50004024),#define WrUTXH2(ch) ( * (volatile unsigned char * )0x50008020)=(unsigned char)(,ch,),#define RdURXH2() ( * (volatile unsign

25、ed char * )0x50008024),#difine,UTXH0 (0x50000020+3) /,Byte_access,address by DMA,#define,URXH0 (0x50000024+3),#difine,UTXH1 (0x50004020+3),#define,URXH1 (0x50004024+3),#difine,UTXH2 (0x50008020+3 ),#define,URXH2 (0x50008024+3),#endif,6.3 UART,通信程序編寫,6.3.1,通信程序編寫步驟,UART,通信程序可以采用查詢、中斷和,DMA,模式。我們通過使用較多

26、的中斷方式來介,UART,通信程序的編寫。簡單做法是,,UART,通信程序的編寫參照例子程序。,選通道,通過函數(shù),Uart_Select,(),;選,UART0UART2,;,選波特率和波特率發(fā)生器時鐘,選波特率通過函數(shù),Uart_Pclk_En,(,int,ch,int,baud),或,Uart_Pclk_En,(,int,ch,int,baud),來進行。時鐘選,UCLK,,,rUCON0|=0x400,;時鐘選,PCLK,,,rUCON0&=0x3ff,。,通信協(xié)議(,rULCON0,)設定,如果正常通信,一位停止位,,8,位數(shù)據(jù)位,無奇偶效驗:,rULCON0=(06)|(03)|(0

27、2)|(3);,通信控制字(,rUCON0,)設定,如時鐘選,ULK,做波特率發(fā)生器;,Tx,中斷脈沖觸發(fā),,Rx,中斷脈沖觸發(fā);接收超時中斷允許;產生接收錯誤中斷;正常模式發(fā)送:,rUCON0|= (TX_INTTYPE9)|(RX_INTTYPE8)|(07)|(06)|(05)|(04)|(12)|(1),;, I/O,口初始化,因為,UART,通信使用,H,口的第二功能,所以,H,口要上拉禁止:,rGPHUP|=0x1ff,。,H,口控制寄存器,nRTS1,nCTS1,功能使能,,rGPHCON&=0x3c0000,,,rGPHCON|=0x2faaa,;,設中斷服務函數(shù)入口地址,把中

28、斷服務函數(shù)入口地址賦函數(shù)指針,PISR_UARTn,注意,接收中斷服務函數(shù)入口地址和發(fā)送中斷服務函數(shù)入口地址是一個,在中斷服務函數(shù)中根據(jù),UTRSTATn,1,和,UTRSTATn,0,狀態(tài)決定是發(fā)送中斷還是接收中斷。,打開總中斷屏蔽和子中斷屏蔽等待中斷:,rINTMSK=,(BIT_UART0);,rINTSUBMSK=,(BIT_SUB_TXD0);,進入中斷后,先屏蔽發(fā)送和接收中斷,防止新來中斷干擾我們的正常發(fā)送和接收,正常發(fā)送和接收結束后,清中斷掛起和中斷源掛起寄存器:,ClearPending(BIT_UART0),,,rSUBSRCPND=,(BIT_SUB_TXD0,(發(fā)送),,

29、rSUBSRCPND=,(BIT_SUB_RXD0|BIT_SUB_ERR0),(接收),;,取消中斷屏蔽,等下一次中斷。,6.3.2,通信程序編寫示例,下面給出的幾個函數(shù),是查詢方式,URAT,通信常用到的主要函數(shù),包括,URAT,初始化,字符的發(fā)送、接收函數(shù),希望大家仔細閱讀,理解每一行的含義。,1, UART,通信,采用查詢方式:,/,引用頭文件,#include 2410addr.h,#include 2410lib.h,#include ,option.h,#include ,def.h,#include ,#include ,#include ,#include ,#include

30、 ,/,函數(shù)聲明,void,Uart_Init,(,int,pclk,int,baud);,char,Uart_Getch,(void);,char,Uart_GetKey,(void);,void,Uart_GetString,(char *string);,void,Uart_SendByte,(,int,data);,void,Uart_SendString,(char *pt);,void,Uart_Select,(,int,ch,);,/-,/,串口初始化,輸入,PCLK,輸入波特率,/-,static,int,whichUart=0;,void,Uart_Init,(,int,pc

31、lk,int,baud),int,i;,if(,pclk,= 0),pclk,= PCLK;,rUFCON0 = 0x0; /UART channel 0 FIFO control register, FIFO disable,rUFCON1 = 0x0; /UART channel 1 FIFO control register, FIFO disable,rUFCON2 = 0x0; /UART channel 2 FIFO control register, FIFO disable,rUMCON0 = 0x0; /UART,chaneel,0 MODEM control registe

32、r, AFC disable,rUMCON1 = 0x0; /UART,chaneel,1 MODEM control register, AFC disable,/UART0,rULCON0 = 0x3;,/Line control register :,Normal,No,parity,1 stop,8 bits.,/ 0 0 0 0 0 0 1 1,rUCON0 = 0x245; / Control register,/ 10 9 8 7 6 5 4 3:2 1:0,/ Clock,Sel,Tx,Int, Rx,Int, Rx Time Out, Rx err, Loop-back, S

33、end break, Transmit Mode, Receive Mode,0 1 0 0 1 0 0 0 1 0 1,/ PCLK ,Level Pulse Disable Generate Normal,Normal,Interrupt or Polling,/ rUBRDIV0=( (int)(pclk/16./baud) -1 ); /Baud rate,divisior,register 0,rUBRDIV0=( (int)(pclk/16./baud+0.5) -1 ); /Baud rate,divisior,register 0,/UART1,rULCON1 = 0x3;,r

34、UCON1 = 0x245;,rUBRDIV1=( (,int,)(pclk/16./baud) -1 );,/UART2,rULCON2 = 0x3;,rUCON2 = 0x245;,rUBRDIV2=( (,int,)(pclk/16./baud) -1 );,for(i=0;i100;i+);,/-,/,選擇串口通道,/-,void,Uart_Select,(,int,ch,),whichUart,=,ch,;,/-,/,等待發(fā)送移位寄存器空,/-,void,Uart_TxEmpty,(,int,ch,),if(ch=0),while(!(rUTRSTAT0 /Wait until,tx

35、,shifter is empty.,else if(ch=1),while(!(rUTRSTAT1 /Wait until,tx,shifter is empty.,else if(ch=2),while(!(rUTRSTAT2 /Wait until,tx,shifter is empty.,/-,/,接收串口一字節(jié)數(shù)據(jù),注意,RdURXH0(),,,RdURXH1(),,,RdURXH2(),的使用,/-,char,Uart_Getch,(void),if(whichUart=0),while(!(rUTRSTAT0 /Receive data ready,return RdURXH0(

36、);,else if(whichUart=1), while(!(rUTRSTAT1 /Receive data ready,return RdURXH1();,else if(whichUart=2), while(!(rUTRSTAT2 /Receive data ready,return RdURXH2();,else,return 0;,/-/,得到串口的鍵值,/-,char,Uart_GetKey,(void),if(whichUart=0),if(rUTRSTAT0 & 0x1) /Receive data ready,return RdURXH0();,else,return 0

37、;,else if(whichUart=1),if(rUTRSTAT1 & 0x1) /Receive data ready,return RdURXH1();,else,return 0;,else if(whichUart=2),if(rUTRSTAT2 & 0x1) /Receive data ready,return RdURXH2();,else,return 0;,else,return 0;,/-,/,串口得到字符串,/-,void,Uart_GetString,(char *string),char *string2 = string;,char c;,while(c =,Ua

38、rt_Getch,()!=r),if(,c=b,),if( (int)string2 (,int,)string ),Uart_Printf,(b b);,string-;,else,*string+,= c;,Uart_SendByte,(c);,*string=0;,Uart_SendByte,(n);,/-,/,得到串口初始號,/-,int,Uart_GetIntNum,(void),char str30;,char *string =,str,;,int,base = 10;,int,minus = 0;,int,result = 0;,int,lastIndex,;,int,i;,U

39、art_GetString,(string);,if(string0=-),minus = 1;,string+,;,if(string0=0 & (string1=x | string1=X),base = 16;,string += 2;,lastIndex,=,strlen,(string) - 1;,if(,lastIndex,0),return -1;,if(string,lastIndex,=h | string,lastIndex,=H ),base = 16;,string,lastIndex, = 0;,lastIndex,-;,if(base=10),result =,at

40、oi,(string);,result = minus ? (-1*result):result;,else,for(i=0;i,=lastIndex;i+,),if(,isalpha,(stringi),if(,isupper,(stringi),result = (result4) + stringi - A + 10;,else,result = (result4) + stringi - a + 10;,else,result = (resultUART0,Tx,interrupt test is,good!rn,;,Uart_Printf,(,Uart,channel 0,Tx,In

41、terrupt Testn);,pISR_UART0=(unsigned)Uart0_TxInt;,rULCON0=(06)|(03)|(02)|(3);/,Normal,No,parity,One,stop bit, 8bit,rUCON0 / For the PCLK UCLK,fuction,rUCON0|= (TX_INTTYPE9)|(RX_INTTYPE8)|(07)|(06)|(05)|(04)|(12)|(1);,/,Clock,Tx:Def,Rx:Def,Rx,timeout:x,Rxerror,int:x,Loop-back:x,Send,break:x,Tx:int,Rx

42、:int,Uart_TxEmpty(0); /wait until,tx,buffer is empty.,rINTMSK=,(BIT_UART0);,rINTSUBMSK=,(BIT_SUB_TXD0);,while(,isTxInt,);,/* UART0 Rx test with interrupt */,isRxInt=1;,uart0RxStr=(char *)UARTBUFFER;,Uart_Printf,(n,Uart,channel 0 Rx Interrupt Test:n);,Uart_Printf,(After typing ENTER key, you will see

43、 the characters which was typed by you.);,Uart_Printf,(,nTo,quit, press ENTER key.!n);,Uart_TxEmpty(0); /wait until,tx,buffer is empty.,pISR_UART0 =(unsigned)Uart0_RxIntOrErr;,rULCON0=(06)|(03)|(02)|(3);/,Normal,No,parity,One,stop bit, 8bit,rUCON0 / For the PCLK UCLK,fuction,rUCON0|= (TX_INTTYPE9)|(

44、RX_INTTYPE8)|(07)|(16)|(05)|(04)|(12)|(1);,/,Clock,Tx:pulse,Rx:pulse,Rx:timeout:x,Rx,errorint:o,Loop-back:x,Sendbreak:x,Tx:int,Rx:int,/ Clear,Int,Pending and Unmask,ClearPending(BIT_UART0);,rINTMSK=,(BIT_UART0);,rSUBSRCPND=,(BIT_SUB_TXD0|BIT_SUB_RXD0|BIT_SUB_ERR0);,rINTSUBMSK=,(BIT_SUB_RXD0|BIT_SUB_

45、ERR0);,while(,isRxInt,);,rINTSUBMSK|=,(BIT_SUB_RXD0|BIT_SUB_ERR0);,rINTMSK|=,(BIT_UART0);,Uart_Printf,(,%sn,(char *)UARTBUFFER);,Uart_Port_Return,();,/-,/UART,發(fā)送和接收用到的,I/O,口保存和初始化,/-,void,Uart_Port_Set,(void),/Push UART GPIO port configuration,save_rGPHCON=rGPHCON,;,save_rGPHDAT=rGPHDAT,;,save_rGPHU

46、P=rGPHUP,;,/Configure UART port,rGPHCON,rGPHCON|=0x2faaa;/ nRTS1,nCTS1,rGPHUP|=0x1ff;/,Uart,port pull-up disable,/rINTSUBMSK=0x7ff; /SUBINT ALL MASK,/Push,Uart,control registers,save_ULCON0=rULCON0;,save_UCON0=rUCON0;,save_UFCON0=rUFCON0;,save_UMCON0=rUMCON0;,save_ULCON1=rULCON1;,save_UCON1 =rUCON1;

47、,save_UFCON1=rUFCON1;,save_UMCON1=rUMCON1;,save_ULCON2=rULCON2;,save_UCON2 =rUCON2;,save_UFCON2=rUFCON2;,save_UMCON2=rUMCON2;,/Initialize UART1,2 port,/-,/ UART,發(fā)送和接收結束,用到的,I/O,口恢復原來狀態(tài),/-,void Uart_Port_Return(void),/Pop UART GPIO port configuration,rGPHCON=save_rGPHCON;,rGPHDAT=save_rGPHDAT;,rGPHUP

48、=save_rGPHUP;,/Pop,Uart,control registers,rULCON0=save_ULCON0;,rUCON0 =save_UCON0;,rUFCON0=save_UFCON0;,rUMCON0=save_UMCON0;,rULCON1=save_ULCON1;,rUCON1 =save_UCON1;,rUFCON1=save_UFCON1;,rUMCON1=save_UMCON1;,rULCON2=save_ULCON2;,rUCON2 =save_UCON2;,rUFCON2=save_UFCON2;,rUMCON2=save_UMCON2;,/-,/ UART

49、,發(fā)送和接收使用,UCLK,,并計算,rUBRDIV0,和設定波特率,/-,void,Uart_Uclk_En,(,int,ch,int,baud),/*,int,ch, baud;,Uart_Printf,(,nSelect,UART channel0:UART0/1:UART1/2:UART2:n);,ch=Uart_GetIntNum,();,Uart_Printf,(,nSelect,baud rate :n);,baud=Uart_GetIntNum,();,*/,if(,ch,= 0) ,Uart_Select(0);,rUCON0|=0x400;/ Select UCLK,rUB

50、RDIV0=( (int)(UCLK/16./baud) -1 );/Baud rate,divisior,register,Uart_Printf,(UCLK is enabled by UART0.n);,else if(ch=1),Uart_Select(1);,rUCON1|=0x400;/ Select UCLK,rUBRDIV1=( (int)(UCLK/16./baud) -1 );/Baud rate,divisior,register,Uart_Select(0);,Uart_Printf,(UCLK is enabled by UART1.n);,else ,Uart_Select(2);,rUCON2|=0x400;/ Select UCLK,rUBRDIV2=( (int)(UCLK/16./baud) -1 );/Baud rate,divisior,register,Uart_Select(0);,Uart_Printf,(UCLK is enabled by UART2.n);,/for(i=0;i100;i+);/ For the,satble,operation,/-,/ UART,發(fā)送和接收使用,PCLK,

展開閱讀全文
溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
5. 裝配圖網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

相關資源

更多
正為您匹配相似的精品文檔
關于我們 - 網站聲明 - 網站地圖 - 資源地圖 - 友情鏈接 - 網站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網版權所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對上載內容本身不做任何修改或編輯。若文檔所含內容侵犯了您的版權或隱私,請立即通知裝配圖網,我們立即給予刪除!