?? sart.lst
字號:
C51 COMPILER V7.09 SART 01/12/2007 09:30:15 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE SART
OBJECT MODULE PLACED IN sart.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE sart.c ROM(COMPACT) OPTIMIZE(9,SPEED) BROWSE MODP2 DEBUG OBJECTEXTEND PREPR
-INT
line level source
1
2 /* //////////////////////////////////////////////////////////////////////////
3 // sart.c - source file for lme2200 API
4 //
5 // Copyright 2005, Leaguer MicroElectronics Co., Ltd
6 // www.leaguerme.com
7 //////////////////////////////////////////////////////////////////////////// */
8 #include <REG922.H>
9
10 #include "sart.h"
11 #include "timer.h"
12 #define uint unsigned int
13 #define uchar unsigned char
14
15 #define MAX_FRAME_SZ 28
16
17 #define STAT_PREAMBLE 1
18 #define STAT_SYNC 2
19 #define STAT_SYNC1 3
20 #define STAT_DATALEN 4
21 #define STAT_DATA 5
22
23 #define FRAME_PREAMBLE 0xFE
24 #define FRAME_SYNC 0x68
25 #define FRAME_END 0x16
26
27 idata uchar amr_frame[MAX_FRAME_SZ]; // amr frame rx buffer
28 //bit amr_recved; // amr frame received flag
29
30 // variables used during amr frame reception
31 idata uchar amr_stat;
32 idata uchar amr_len;
33 idata uchar amr_count;
34
35
36 idata uchar uart_buf[16];
37 idata uchar uart_wptr, uart_rptr;
38
39 /*=============================================================================*/
40
41 void uart_init()
42 {
43 1
44 1 SCON =0xd0; // select BRG as UART Baud Rate Gen
45 1 SSTAT=0xe0;
46 1 BRGR0=0xf0; // setup BRG for 9600 baud @ 7.373MHz external Crystal
47 1 BRGR1=0x02;
48 1
49 1 // BRGR0=0xf0; // setup BRG for 4800 baud @ 7.373MHz external Crystal
50 1 // BRGR1=0x05;
51 1
52 1 // BRGR0=0xf0; // setup BRG for 2400 baud @ 7.373MHz external Crystal
53 1 // BRGR1=0x0b;
54 1
C51 COMPILER V7.09 SART 01/12/2007 09:30:15 PAGE 2
55 1 BRGCON = 0x03; // enable BRG
56 1
57 1 IP0H = 0x12; //中斷優(yōu)先級,串口3級,定時器0為2級,外為1級
58 1 IP0 = 0x14;
59 1
60 1 TI = 0; // do not allow transmit
61 1 EA = 1;
62 1 ES = 1;
63 1
64 1 amr_stat = STAT_PREAMBLE; //<-------------設接收的初始計數(shù)1
65 1 // amr_recved = 0;
66 1
67 1 D_SYNC = 1;//--------------設同步輸入無效
68 1
69 1 uart_wptr = 0;
70 1 uart_rptr = 0;
71 1
72 1 }
73
74 /*=============================================================================*/
75
76 /* Serial port ISR */
77 void serial_int (void) interrupt 4
78 {
79 1 //unsigned char c;
80 1
81 1 /*
82 1 * The interrupt was generated. First, check the RI flag to see if it was
83 1 * because a new character was received.
84 1 */
85 1
86 1 if (RI == 1) { /* it was a receive interrupt */
87 2
88 2 RI = 0; /* clear the received interrupt flag */
89 2
90 2 uart_buf[uart_wptr++] = SBUF;
91 2 uart_wptr &= 0x0f;
92 2
93 2 }
94 1
95 1 #ifdef xxx
else if (TI == 1) /* otherwise, assume it was a transmit interrupt */
{
TI = 0; /* clear the transmit interrupt flag */
if (chr != '\0') /* if there's something in the local buffer... */
{
if (chr == '\r') chr = '\n'; /* convert <CR> to <LF> */
SBUF = chr; /* put the character into the transmit buffer */
chr = '\0';
}
}
#endif
108 1
109 1 }
110
111 /*=============================================================================*/
112
113 int uart_recved()
114 {
115 1 if (uart_wptr == uart_rptr) return 0;
116 1
C51 COMPILER V7.09 SART 01/12/2007 09:30:15 PAGE 3
117 1 return 1;
118 1
119 1 }
120
121
122 /*=============================================================================*/
123
124 // Call this function only when uart_recved() is true
125 unsigned char uart_getchar(void)
126 {
127 1 uchar c;
128 1
129 1 c = uart_buf[uart_rptr++];
130 1 uart_rptr &= 0x0f;
131 1
132 1 return c;
133 1 }
134 /*
135 int uart_processed()
136 {
137 amr_recved = 0;
138 uart_wptr = 0;
139 uart_rptr = 0;
140 return 1;
141 }
142 */
143 /*=============================================================================*/
144
145 int recv_amr_frame(void)
146 {
147 1 uchar c;
148 1
149 1 c = uart_getchar();
150 1 // uart_sendchar(c);
151 1 if (amr_stat == STAT_PREAMBLE) { //1
152 2 // Searching for preamble...
153 2 if (c == FRAME_PREAMBLE) { //fe uart_sendchar(c);
154 3 amr_stat = STAT_SYNC;
155 3 amr_count = 0;
156 3 }
157 2 }
158 1 else if (amr_stat == STAT_SYNC) { //2 檢測到68
159 2 // Searching for frame sync ...
160 2 amr_count++;
161 2 if (c == FRAME_SYNC) { //68
162 3 amr_count = 0;
163 3 amr_stat = STAT_SYNC1; //3 uart_sendchar(c);
164 3 }
165 2 else if (amr_count >= 4) {
166 3 // re-start
167 3 amr_stat = STAT_PREAMBLE; //1
168 3 }
169 2 }
170 1 /*
171 1 else if (amr_stat == STAT_SYNC1) { //3
172 1 // Receive address bytes
173 1 amr_frame[amr_count++] = c;
174 1 if (amr_count == 7) { //4個表地址+C+L
175 1 if (c == FRAME_SYNC) { // 68uart_sendchar(c);
176 1 amr_count = 0;
177 1 amr_stat = STAT_DATALEN; //4
178 1 }
C51 COMPILER V7.09 SART 01/12/2007 09:30:15 PAGE 4
179 1 else amr_stat = STAT_PREAMBLE; //1
180 1 }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -