📄 serial.lst
字号:
C51 COMPILER V7.02b SERIAL 01/18/2005 19:37:32 PAGE 1
C51 COMPILER V7.02b, COMPILATION OF MODULE SERIAL
OBJECT MODULE PLACED IN SERIAL.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE SERIAL.C LARGE BROWSE DEBUG OBJECTEXTEND
stmt level source
1 /******************************************************************************/
2 /* */
3 /* SERIAL.C: Interrupt Controlled Serial Interface for RTX-51 tiny */
4 /* */
5 /******************************************************************************/
6
7
8 #include <reg52.h> /* special function register 8052 */
9 #include <rtx51tny.h> /* RTX-51 tiny functions & defines */
10 #include "serial.h"
11
12 #define OLEN 8 /* size of serial transmission buffer */
13 unsigned char ostart=0; /* transmission buffer start index */
14 unsigned char oend=0; /* transmission buffer end index */
15 char outbuf[OLEN]; /* storage for transmission buffer */
16 unsigned char otask = 0xff; /* task number of output task */
17
18 #define ILEN 8 /* size of serial receiving buffer */
19 unsigned char istart=0; /* receiving buffer start index */
20 unsigned char iend=0; /* receiving buffer end index */
21 char inbuf[ILEN]; /* storage for receiving buffer */
22 unsigned char itask = 0xff; /* task number of output task */
23
24
25 bit sendfull=0; /* flag: marks transmit buffer full */
26 bit sendactive=0; /* flag: marks transmitter active */
27
28
29 #define MaxLenStr 100 /*buf[MaxLenStr+1] for '\0'*/
30 #define TABNum 4 //TAB键移动长度
31
32 /******************************************************************************/
33 /* putbuf: write a character to SBUF or transmission buffer */
34 /******************************************************************************/
35 void putbuf (char c) {
36 1 if (!sendfull) { /* transmit only if buffer not full */
37 2 if (!sendactive) { /* if transmitter not active: */
38 3 sendactive = 1; /* transfer the first character direct */
39 3 SBUF = c; /* to SBUF to start transmission */
40 3 }
41 2 else { /* otherwize: */
42 3 outbuf[ostart++ % OLEN] = c;
43 3 ostart=ostart% OLEN;
44 3 if (((ostart+1)%OLEN)==oend) sendfull = 1;
45 3 }
46 2 }
47 1 }
48
49
50 /******************************************************************************/
51 /* putchar: interrupt controlled putchar function */
52 /******************************************************************************/
53 char putchar (char c) {
54 1
55 1 while (sendfull) {
C51 COMPILER V7.02b SERIAL 01/18/2005 19:37:32 PAGE 2
56 2 otask = os_running_task_id ();
57 2 os_wait (K_SIG, 0, 0);
58 2 otask = 0xff;
59 2 }
60 1 putbuf (c); /* send character */
61 1 return (c); /* return character: ANSI requirement */
62 1 }
63
64
65 /******************************************************************************/
66 /* _getkey: interrupt controlled _getkey */
67 /******************************************************************************/
68 char _getkey (void) {
69 1 char tmp;
70 1 while (iend == istart) {
71 2 itask = os_running_task_id (); /* set input task number */
72 2 os_wait (K_SIG, 0, 0); /* RTX-51 call: wait for signal */
73 2 itask = 0xff; /* clear input task number */
74 2 }
75 1 tmp=inbuf[iend++% ILEN];
76 1 iend=iend% ILEN;
77 1 return (tmp);
78 1 }
79
80
81 /******************************************************************************/
82 /* serial: serial receiver / transmitter interrupt */
83 /******************************************************************************/
84 serial () interrupt 4 using 2 { /* use registerbank 2 for interrupt */
85 1 unsigned char c;
86 1 bit start_trans = 0;
87 1
88 1 if (RI) { /* if receiver interrupt */
89 2 c = SBUF; /* read character */
90 2 RI = 0; /* clear interrupt request flag */
91 2 if(((istart+1)%ILEN)!=iend){
92 3 inbuf[istart++ % ILEN] = c;
93 3 istart=istart % ILEN;
94 3 }
95 2 if (itask != 0xFF) isr_send_signal (itask);
96 2 }
97 1
98 1 if (TI || start_trans) {
99 2 TI = 0;
100 2 if(ostart!=oend){
101 3 SBUF = outbuf[oend++ %OLEN];
102 3 oend=oend%OLEN;
103 3 sendfull = 0;
104 3 if (otask != 0xFF) isr_send_signal (otask);
105 3 }
106 2 else sendactive = 0;
107 2 }
108 1
109 1 }
110 /******************************************************************************/
111 /* serial_init: initialize serial interface */
112 /******************************************************************************/
113 void serial_init (void) {
114 1 SCON = 0x50; /* mode 1: 8-bit UART, enable receiver */
115 1 TMOD |= 0x20; /* timer 1 mode 2: 8-Bit reload */
116 1 TH1 = 0xf4; /* reload value 2400 baud */
117 1 TR1 = 1; /* timer 1 run */
C51 COMPILER V7.02b SERIAL 01/18/2005 19:37:32 PAGE 3
118 1 ES = 1; /* enable serial port interrupt */
119 1 }
120
121
122 void PrintCh(unsigned char ch) //内部使用,不建议用户看到。
123 {
124 1 if(ch>=0&&ch<=9) ch=ch+'0';
125 1 else ch=ch+'A'-10;
126 1 putchar(ch);
127 1 }
128
129 void insidePrintByte(unsigned char Byte) //内部使用,以十六进制格式显示1个字节数据
130 {
131 1 unsigned char c;
132 1 c=Byte;
133 1 c=c>>4;
134 1 PrintCh(c);
135 1 c=Byte;c=c&0x0F;PrintCh(c);
136 1 }
137
138 void PrintByte(unsigned char Byte) //以十六进制格式显示1个字节数据
139 {
140 1 //EA=0;
141 1 insidePrintByte(Byte);
142 1 //EA=1;
143 1 }
144
145 void insidePrintWord(unsigned int Word) //内部使用,以十六进制格式显示1个字数据
146 {
147 1 insidePrintByte(Word>>8);
148 1 insidePrintByte(Word&0xFF);
149 1 }
150
151 void PrintWord(unsigned int Word) //以十六进制格式显示1个字数据
152 {
153 1 //EA=0;
154 1 insidePrintWord(Word);
155 1 //EA=1;
156 1 }
157
158 void PrintLong(unsigned long LongWord) //以十六进制格式显示1个长字数据
159 {
160 1 //EA=0;
161 1 insidePrintWord(LongWord>>16);
162 1 insidePrintWord(LongWord&0xFFFF);
163 1 //EA=1;
164 1 }
165
166 void PrintStr(unsigned char *str) //显示字符串
167 {
168 1 int i;
169 1 unsigned char j;
170 1 unsigned char ch;
171 1
172 1 //EA=0;
173 1 for(i=0;i<MaxLenStr;i++){
174 2 ch=*(str+i);
175 2 if(ch=='\0') break;
176 2 else if(ch=='\n'){putchar(10);putchar(13);}
177 2 else if(ch=='\t'){
178 3 for(j=0;j<TABNum;j++)
179 3 putchar(' ');
C51 COMPILER V7.02b SERIAL 01/18/2005 19:37:32 PAGE 4
180 3 }
181 2 else putchar(ch);
182 2 }
183 1 //EA=1;
184 1 }
185
186 void clrscr() //清屏
187 {
188 1 PrintStr("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");//25个回车换行清屏幕。
189 1 }
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 595 ----
CONSTANT SIZE = 26 ----
XDATA SIZE = 22 15
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = 2 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -