📄 led.lst
字号:
C51 COMPILER V8.08 LED 09/07/2008 10:28:28 PAGE 1
C51 COMPILER V8.08, COMPILATION OF MODULE LED
OBJECT MODULE PLACED IN led.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE led.c BROWSE DEBUG OBJECTEXTEND TABS(2)
line level source
1 /***********************************
2 *MCU:AT89S51
3 *Freq:12M
4 .edit Tab:4
5 driver:ht1621
6 **********************************/
7 //=============================================================
8 //OCMJ8X15D触摸屏中断程序
9 //当触摸事件发生时模块产生中断经INT脚输出信号触发MCU的外部中断0
10 //=============================================================
11 //=============================================
12 //=============================================
13 #include <reg52.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <math.h>
18 #include <intrins.h>
19 #include <absacc.h>
20 //#include "malloc.h"
21
22
23
24 #define uchar unsigned char
25 #define uint unsigned int
26 //=============================================
27
28 /**************************************************************************************************\
29 * 短信控制处理: *
30 * 1、初始化串口(不会写) *
31 * 2、初始化GSM模块,主要是为了设定消息接受模式,一般英文TEXT足够,PDU用于中文编码 *
32 * 3、读取消息,通过指令“AT+CMGR=1”读取SIM卡位置为1的消息 *
33 * 4、串口收发不是很懂,随便写了一下,好像要用到定时器和中断的start_timer0();close_timer0();都没有写*
34 \**************************************************************************************************/
35
36
37 unsigned char code Command_At[4] = "AT\r\0";
38 unsigned char code Command_Cmgf[11] = "AT+CMGF=1\r\0";
39 unsigned char code Command_Cmgd[11] = "AT+CMGD=1\r\0";
40 unsigned char code Command_Cmgr[11] = "AT+CMGR=1\r\0";
41
42 void delay1 (int ms)
43 {
44 1 int i,j;
45 1 for(i=0;i<ms;i++)
46 1 for(j=0;j<123;j++);
47 1 }
48 //=================================
49
50 //=============================================
51
52
53
54
55
C51 COMPILER V8.08 LED 09/07/2008 10:28:28 PAGE 2
56 uchar *pTBuf;
57 uchar *SaveRBuf;
58 uchar RBuf[15];
59 uchar *pRBuf=RBuf;
60 uchar R_index=0;
61 uchar command;
62 bit com_data=0;
63 uchar remote_status=0;
64
65 void UartInit(unsigned int BandRate)
66 {
67 1 TMOD&=0X0F;
68 1 TMOD|=0x20; /*定时器1作为波特率发生器,工作于方式2,自动8位装载*/
69 1 SCON=0x50; /*工作方式 1*/
70 1 PCON|=0x80; /*波特率加倍*/
71 1 TH1=255-57600/BandRate+1;; /*按波特率计算初值 TH1=256-F*(SMOD+1)/(384*Band)=256-57600/Band*/
72 1 TL1=TH1;
73 1 TR1=1;
74 1 EA=1;
75 1 ES=1;
76 1 }
77
78
79
80 uchar func(uchar i)
81 {
82 1 if((SaveRBuf-RBuf-i)<0) SaveRBuf=SaveRBuf+15;
83 1 if((SaveRBuf-RBuf-i)>=15) SaveRBuf=SaveRBuf-15;
84 1 return *(SaveRBuf-i);
85 1
86 1 }
87 //uchar *tab
88 void send_command(uchar code *com)
89 {
90 1 int i=0;
91 1 com_data=0;
92 1 while(1)
93 1 {
94 2 pTBuf=com;
95 2 SBUF='1';
96 2 delay1(500);
97 2 // for(i=0;i++;i<9)
98 2 // show_num(RBuf[i],i);
99 2 // if(command==2)
100 2
101 2
102 2
103 2 if((func(3)=='O')&&(func(2)=='K'))break;
104 2
105 2
106 2 }
107 1 SaveRBuf=RBuf;
108 1 pRBuf=RBuf;
109 1 command=0;
110 1 }
111
112
113 void read_SMS ()
114 {
115 1 com_data=1;
116 1 while(1)
117 1 {
C51 COMPILER V8.08 LED 09/07/2008 10:28:28 PAGE 3
118 2 pTBuf=Command_Cmgr;
119 2 SBUF='1';
120 2 delay1(500);
121 2
122 2 // if((SaveRBuf-RBuf)<2)
123 2 if((func(3)=='O')&&(func(2)=='N')) {remote_status=1;break;}
124 2 if((func(4)=='O')&&(func(3)=='F')&&(func(2)=='F')) {remote_status=2;break;}
125 2 if((func(3)=='T')&&(func(2)=='+')) {remote_status=3;break;}
126 2 if((func(3)=='T')&&(func(2)=='-')) {remote_status=4;break;}
127 2 if((func(3)=='H')&&(func(2)=='+')) {remote_status=5;break;}
128 2 if((func(3)=='H')&&(func(2)=='-')) {remote_status=6;break;}
129 2 if((func(5)=='A')&&(func(4)=='U')&&(func(3)=='T')&&(func(2)=='O')) {remote_status=7;break;}
130 2
131 2 SaveRBuf=RBuf;
132 2 pRBuf=RBuf;
133 2 command=0;
134 2 // else return 0;
135 2 }
136 1 }
137 void main(void)
138 {
139 1 int i;
140 1 // SP=0x60;
141 1 UartInit(6000);
142 1
143 1 send_command(Command_At);
144 1
145 1 send_command(Command_Cmgf);
146 1 for(i=0;i<10;i++)
147 1 send_command(Command_Cmgd);
148 1 read_SMS();
149 1 while (1);
150 1 }
151
152 void receive(void)
153 {
154 1 RI=0;
155 1 *pRBuf=SBUF;
156 1 if (*pRBuf==0x0a){command++;}
157 1 if((com_data)&&(command==3))SaveRBuf=pRBuf;
158 1 if((!com_data)&&(command==2))SaveRBuf=pRBuf;
159 1 if(R_index==15){R_index=0;pRBuf=RBuf;}
160 1 else
161 1
162 1 {pRBuf++;R_index++;}
163 1
164 1
165 1 }
166
167 void send(void)
168 {
169 1 TI=0;
170 1 if(*pTBuf!=0)
171 1 {
172 2 SBUF=*pTBuf;
173 2
174 2 pTBuf++;
175 2
176 2
177 2 }
178 1 }
179 void UART(void)interrupt 4
C51 COMPILER V8.08 LED 09/07/2008 10:28:28 PAGE 4
180 {
181 1 if(RI==1){receive();return;}
182 1 if(TI==1){send(); return;}
183 1 }
184
185
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 666 ----
CONSTANT SIZE = 37 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 27 7
IDATA SIZE = ---- ----
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -