📄 romsore.lst
字号:
C51 COMPILER V7.01 ROMSORE 09/23/2008 14:27:39 PAGE 1
C51 COMPILER V7.01, COMPILATION OF MODULE ROMSORE
OBJECT MODULE PLACED IN romsore.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE romsore.c OPTIMIZE(6,SPEED) BROWSE DEBUG OBJECTEXTEND
stmt level source
1 #include<reg52.h>
2 //第一片eeprom的地址为0000~1fff,64kbit,8kbyte,256page,1page=32byte
3 //在外部RAM中设定两个数据存储区,DATA_STORE[]为发到rom中的数 ,DATA_RECE[]为rom中取出的数
4
5 //commend
6 #define EEROM_READ 0x03//Read data from memory array beginning at selected address
7 #define EEROM_WRITE 0x02//Write data to memory array beginning at selected address
8 #define EEROM_WREN 0x06//Set the write enable latch (enable write operations)
9 #define EEROM_WRDI 0x04//Reset the write enable latch (disable write operations)
10 #define EEROM_RDSR 0x05//Read status register
11 #define EEROM_WRSR 0x01//Write status register
12 #define STATUS_REG 0x00
13 ///////////////////////////////////////////////////////////////////////////////
14 #define ALARM_START_ADD 0x0008//指向的是存储alarm首地址
15 #define ALARM_END_ADD 0x2000//终止地址
16 #define ALAME_NUM_ADD 0x0000
17 #define ALAME_ADDPT_ADD 0x0002
18 #define NUM_MAX 1023
19
20 typedef unsigned char uchar;
21 typedef unsigned int uint;
22 //connection
23 sbit CS1=P1^6;
24 sbit SO1=P1^7;
25 sbit SCK1=P3^4;
26 sbit SI1=P3^5;
27
28 //变量定义
29 //uchar xdata DATA_RECE[64];//发到rom中的数
30 //uchar xdata DATA_STORE[64];//rom中取出的数
31 //uchar xdata test1,test2,test3;
32 //uint xdata test4;
33 unsigned int xdata alarm_num;
34 unsigned int xdata alarm_addpt;
35 //------------------------------------------------------------------------------------
36
37 ////////////////////////////////////////////////////////////////////////////////////////////
38 //下面的函数是对第一片eeprom1进行操作的函数
39 ////////////////////////////////////////////////////////////////////////////////////////////
40
41 //单片机发送一个字节的数据/命令到eeprom1
42 void sendbyte_chip1(uchar sbytedat)
43 {
44 1 uchar n;
45 1 for(n=0;n<8;n++)
46 1 {
47 2 if((sbytedat&0x80)==0x80)//判断sbytedat的最高位数据(&1000 0000),'1' SI1 = 1;'0' SI1 = 0,
48 2 SI1=1;
49 2 else
50 2 SI1=0;
51 2 SCK1=0;//开始为低电平,保证SCK1 = 1时,有个上升沿到来。
52 2 sbytedat<<=1;//数据左移一位,连续移动保证8位数据一直在最高位,低电平时间短,高电平时间长
53 2 SCK1=1;
54 2 }//给了8个上升沿,写入8个位,结束后SCK=1,SI=0
55 1 }
C51 COMPILER V7.01 ROMSORE 09/23/2008 14:27:39 PAGE 2
56 //------------------------------------------------------------------------------------
57
58 //单片机发送一个字数据到eeprom1,其中高位在前,低位在后
59 void sendword_chip1(uint sworddat)
60 {
61 1 uchar k;
62 1 for(k=0;k<16;k++)
63 1 {
64 2 if((sworddat&0x8000)==0x8000)
65 2 SI1=1;
66 2 else
67 2 SI1=0;
68 2 SCK1=0;
69 2 sworddat<<=1;//低电平时间短,高电平时间长
70 2 SCK1=1;
71 2 }
72 1 }
73 //------------------------------------------------------------------------------------
74
75 //单片机接收一个字节数据到eeprom1
76 uchar receivebyte_chip1()
77 {
78 1 uchar n,rbytedat=0;
79 1 SCK1=1;
80 1 for(n=0;n<8;n++)
81 1 {
82 2 SCK1=0;
83 2 if(SO1==1)
84 2 rbytedat|=0x01;//低电平时间长,高电平时间短
85 2 if(n<7)
86 2 rbytedat<<=1;
87 2 SCK1=1;
88 2 }//给了8个下降沿,结束后SCK=1;入口SCK=1,以便更新数据,结束后SCK=1
89 1 //rbytedat>>=1; //由于左移8次,应移回1位
90 1 return(rbytedat);
91 1 }
92 //------------------------------------------------------------------------------------
93
94 /*读状态寄存器,读出的数据放入到status中*/
95 uchar rdsr_cmd_chip1 (void)
96 {
97 1 uchar status;
98 1 //SCK1=0;
99 1 CS1=0;
100 1 sendbyte_chip1(EEROM_RDSR);
101 1 status=receivebyte_chip1();
102 1 //SCK1=0;
103 1 CS1=1;
104 1 return(status);
105 1 }
106 //------------------------------------------------------------------------------------
107
108 /*检测写入的过程是否结束*/
109 void checkend_chip1()
110 {
111 1 uchar checkn,pstatus;//检测次数100次
112 1 for(checkn=0;checkn<100;checkn++)
113 1 {
114 2 pstatus=rdsr_cmd_chip1();
115 2 if((pstatus&0x01)==0)//?铁电存储器已经没有就绪位了,不用检查是否就绪/READY位;
116 2 break;
117 2 }
C51 COMPILER V7.01 ROMSORE 09/23/2008 14:27:39 PAGE 3
118 1 }
119 //------------------------------------------------------------------------------------
120
121 /*写状态寄存器子程序*/
122 void wrsr_cmd_chip1(void)
123 {
124 1 CS1=0;
125 1 sendbyte_chip1(EEROM_WREN);
126 1 CS1=1;
127 1
128 1 CS1=0;/* Bring /CS low */
129 1 //SCK1=0;
130 1 sendbyte_chip1(EEROM_WRSR) ;/* Send WRSR instruction */
131 1 sendbyte_chip1(STATUS_REG);/* Send status register */
132 1 CS1=1;/* Bring /CS high */
133 1 //SCK1=0;
134 1 checkend_chip1();
135 1 }
136 //------------------------------------------------------------------------------------
137
138 //向eeprom1中写入一个字节数据
139 void bytewrite_chip1(uint wbyteadd,uchar wbytedata)
140 {
141 1 // SCK1=0;
142 1 CS1=0;
143 1
144 1 sendbyte_chip1(EEROM_WREN);
145 1 // SCK1=0;
146 1 CS1=1;
147 1
148 1 CS1=0;
149 1 sendbyte_chip1(EEROM_WRITE);//发送写命令
150 1 sendword_chip1(wbyteadd);//发送16位地址
151 1 sendbyte_chip1(wbytedata);//发送数据
152 1 // SCK1=0;
153 1 CS1=1;
154 1 checkend_chip1();
155 1 }
156 //------------------------------------------------------------------------------------
157
158 //从eeprom1中读出一个字节的数据
159 uchar byteread_chip1(uint rbyteadd)
160 {
161 1 uchar rdata;
162 1 //SCK1=0;
163 1 CS1=0;
164 1 sendbyte_chip1(EEROM_READ );//发送读命令
165 1 sendword_chip1(rbyteadd);//发送16位地址
166 1 rdata=receivebyte_chip1();
167 1 //SCK1=0;
168 1 CS1=1;
169 1 return(rdata);
170 1 }
171 //------------------------------------------------------------------------------------
172
173 //向eeprom1中写入一个字数据
174 void wordwrite_chip1(uint wwordadd,uint wworddata)
175 {
176 1 // SCK1=0;
177 1 CS1=0;
178 1
179 1 sendbyte_chip1(EEROM_WREN);
C51 COMPILER V7.01 ROMSORE 09/23/2008 14:27:39 PAGE 4
180 1 // SCK1=0;
181 1 CS1=1;
182 1
183 1 CS1=0;
184 1 sendbyte_chip1(EEROM_WRITE);//发送写命令
185 1 sendword_chip1(wwordadd);//发送16位地址
186 1 sendword_chip1(wworddata);//发送数据
187 1 // SCK1=0;
188 1 CS1=1;
189 1 checkend_chip1();
190 1 }
191 //------------------------------------------------------------------------------------
192
193 //从eeprom1中读出一个字的数据
194 uint wordread_chip1(uint rwordadd)
195 {
196 1 uint rwdata;
197 1 //SCK1=0;
198 1 CS1=0;
199 1 sendbyte_chip1(EEROM_READ );//发送读命令
200 1 sendword_chip1(rwordadd);//发送16位地址
201 1 rwdata=receivebyte_chip1();
202 1 rwdata<<=8;
203 1 rwdata=rwdata|(receivebyte_chip1());
204 1 //SCK1=0;
205 1 CS1=1;
206 1 return(rwdata);
207 1 }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -