?? uart.lst
字號(hào):
C51 COMPILER V7.06 UART 11/16/2008 16:00:19 PAGE 1
C51 COMPILER V7.06, COMPILATION OF MODULE UART
OBJECT MODULE PLACED IN UART.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE UART.c BROWSE DEBUG OBJECTEXTEND TABS(1)
stmt level source
1 /******************************************************************
2 本程序只供學(xué)習(xí)使用,未經(jīng)作者許可,不得用于其它任何用途
3
4 歡迎訪問我的USB專區(qū):http://group.ednchina.com/93/
5 歡迎訪問我的blog: http://www.ednchina.com/blog/computer00
6 http://computer00.21ic.org
7
8 感謝PCB贊助商——電子園: http://bbs.cepark.com/
9
10 UART.C file
11
12 作者:電腦圈圈
13 建立日期: 2008.06.27
14 修改日期: 2008.07.10
15 版本:V1.1
16 版權(quán)所有,盜版必究。
17 Copyright(C) 電腦圈圈 2008-2018
18 All rights reserved
19 *******************************************************************/
20
21 #include <at89x52.H>
22
23 #include "UART.h"
24 #include "MyType.h"
25 #include "config.h"
26
27
28 volatile uint8 Sending;
29
30
31 /********************************************************************
32 函數(shù)功能:串口初始化。
33 入口參數(shù):無。
34 返 回:無。
35 備 注:無。
36 ********************************************************************/
37 void InitUART(void)
38 {
39 1 EA=0; //暫時(shí)關(guān)閉中斷
40 1 TMOD&=0x0F; //定時(shí)器1模式控制在高4位
41 1 TMOD|=0x20; //定時(shí)器1工作在模式2,自動(dòng)重裝模式
42 1 SCON=0x50; //串口工作在模式1
43 1 TH1=256-Fclk/(BitRate*12*16); //計(jì)算定時(shí)器重裝值
44 1 TL1=256-Fclk/(BitRate*12*16);
45 1 PCON|=0x80; //串口波特率加倍
46 1 ES=1; //串行中斷允許
47 1 TR1=1; //啟動(dòng)定時(shí)器1
48 1 REN=1; //允許接收
49 1 EA=1; //允許中斷
50 1 }
51 ////////////////////////End of function//////////////////////////////
52
53 /********************************************************************
54 函數(shù)功能:串口中斷處理。
55 入口參數(shù):無。
C51 COMPILER V7.06 UART 11/16/2008 16:00:19 PAGE 2
56 返 回:無。
57 備 注:無。
59 void UartISR(void) interrupt 4
60 {
61 1 if(RI) //收到數(shù)據(jù)
62 1 {
63 2 RI=0; //清中斷請(qǐng)求
64 2 }
65 1 else //發(fā)送完一字節(jié)數(shù)據(jù)
66 1 {
67 2 TI=0;
68 2 Sending=0; //清正在發(fā)送標(biāo)志
69 2 }
70 1 }
71 ////////////////////////End of function//////////////////////////////
72
73 #ifdef DEBUG1
/********************************************************************
函數(shù)功能:將整數(shù)轉(zhuǎn)按十進(jìn)制字符串發(fā)送。
入口參數(shù):x:待顯示的整數(shù)。
返 回:無。
備 注:無。
********************************************************************/
void PrintLongInt(uint32 x)
{
int8 i;
uint8 display_buffer[10];
for(i=9;i>=0;i--)
{
display_buffer[i]='0'+x%10;
x/=10;
}
for(i=0;i<9;i++)
{
if(display_buffer[i]!='0')break;
}
for(;i<10;i++)UartPutChar(display_buffer[i]);
}
////////////////////////End of function//////////////////////////////
#endif
100
101 #if (defined DEBUG0)||(defined DEBUG1)
code uint8 HexTable[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
/********************************************************************
函數(shù)功能:發(fā)送一個(gè)byte的數(shù)據(jù)。
入口參數(shù):待發(fā)送的數(shù)據(jù)。
返 回:無。
備 注:無。
********************************************************************/
void Printc(uint8 x)
{
Sending=1;
SBUF=x;
while(Sending);
}
////////////////////////End of function//////////////////////////////
C51 COMPILER V7.06 UART 11/16/2008 16:00:19 PAGE 3
/********************************************************************
函數(shù)功能:以HEX格式發(fā)送一個(gè)byte的數(shù)據(jù)。
入口參數(shù):待發(fā)送的數(shù)據(jù)
返 回:無。
備 注:無。
********************************************************************/
void PrintHex(uint8 x)
{
Printc('0');
Printc('x');
Printc(HexTable[x>>4]);
Printc(HexTable[x&0xf]);
Printc(' ');
}
////////////////////////End of function//////////////////////////////
/********************************************************************
函數(shù)功能:發(fā)送一個(gè)字符串。
入口參數(shù):pd:要發(fā)送的字符串指針。
返 回:無。
備 注:無。
********************************************************************/
void Prints(uint8 * pd)
{
while((*pd)!='\0') //發(fā)送字符串,直到遇到0才結(jié)束
{
UartPutChar(*pd); //發(fā)送一個(gè)字符
pd++; //移動(dòng)到下一個(gè)字符
}
}
////////////////////////End of function//////////////////////////////
/********************************************************************
函數(shù)功能:往串口發(fā)送一字節(jié)數(shù)據(jù)。
入口參數(shù):d: 要發(fā)送的字節(jié)數(shù)據(jù)。
返 回:無。
備 注:無。
********************************************************************/
void UartPutChar(uint8 d)
{
SBUF=d; //將數(shù)據(jù)寫入到串口緩沖
Sending=1; //設(shè)置發(fā)送標(biāo)志
while(Sending); //等待發(fā)送完畢
}
////////////////////////End of function//////////////////////////////
#endif
166
167 #ifdef DEBUG0
/********************************************************************
函數(shù)功能:將短整數(shù)按十六進(jìn)制發(fā)送。
入口參數(shù):待發(fā)送的整數(shù)。
返 回:無。
備 注:無。
********************************************************************/
void PrintShortIntHex(uint16 x)
{
uint8 i;
uint8 display_buffer[7];
display_buffer[6]=0;
display_buffer[0]='0';
C51 COMPILER V7.06 UART 11/16/2008 16:00:19 PAGE 4
display_buffer[1]='x';
for(i=5;i>=2;i--) //將整數(shù)轉(zhuǎn)換為4個(gè)字節(jié)的HEX值
{
display_buffer[i]=HexTable[(x&0xf)];
x>>=4;
}
Prints(display_buffer);
}
////////////////////////End of function//////////////////////////////
#endif
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 41 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 1 ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -