⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 93c46.lst

📁 8051 SPI_93c46 c语言程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 172   2            InData<<=1;
 173   2         }
C51 COMPILER V7.06   93C46                                                                 06/19/2007 13:22:16 PAGE 4   

 174   1        LCK = 0;
 175   1        P0 = 0x00;
 176   1        LCK = 1;//CS=0;
 177   1      }
 178          
 179          
 180          //****************************** 禁止写入************************
 181          void Ewds(void) {
 182   1          unsigned char temp,InData;
 183   1         LCK = 0;
 184   1         P0 = 0x00;
 185   1         LCK = 1;//CS=0;
 186   1      
 187   1         SK=0;
 188   1      
 189   1         LCK = 0;
 190   1         P0 = 0x40;
 191   1         LCK = 1;//CS=0;
 192   1      
 193   1         InData=0x80; // 10000XXXX
 194   1         for(temp=9;temp!=0;temp--) { // 9
 195   2           DI=InData&0x80;
 196   2         SK=1; SK=0;
 197   2         InData<<=1;
 198   2        }
 199   1        LCK = 0;
 200   1        P0 = 0x00;
 201   1        LCK = 1;//CS=0;
 202   1      }
 203          
 204          //**************************读address中的一字节****************************
 205          unsigned int Read(unsigned char address) {
 206   1        unsigned char temp;
 207   1        unsigned int result;
 208   1        Ewen();
 209   1        SK=0; DI=1; // 110 A5-A0
 210   1         LCK = 0;
 211   1         P0 = 0x00;
 212   1         LCK = 1;//CS=0;
 213   1        
 214   1         LCK = 0;
 215   1         P0 = 0x40;
 216   1         LCK = 1;//CS=1;
 217   1      
 218   1         SK=1; SK=0; // 1
 219   1         address=address&0x3f|0x80;
 220   1         for(temp=8;temp!=0;temp--) { // 8
 221   2         DI=address&0x80;
 222   2         SK=1; SK=0;
 223   2         address<<=1;
 224   2        }
 225   1         DO=1;
 226   1         for(temp=16;temp!=0;temp--) { // 16
 227   2         SK=1;
 228   2         result=(result<<1)|DO;
 229   2         SK=0;
 230   2        }
 231   1         LCK = 0;
 232   1         P0 = 0x00;
 233   1         LCK = 1;//CS=0;
 234   1         Ewds();
 235   1        return(result);
C51 COMPILER V7.06   93C46                                                                 06/19/2007 13:22:16 PAGE 5   

 236   1       }
 237          
 238          //***************************往address中写一字节InData************************
 239          void Write(unsigned char address,unsigned int InData) {
 240   1            unsigned char temp;
 241   1             Ewen();
 242   1             SK=0; DI=1; // 101 A5-A0
 243   1             LCK = 0;
 244   1             P0 = 0x00;
 245   1             LCK = 1;//CS=0;
 246   1      
 247   1             LCK = 0;
 248   1             P0 = 0x40;
 249   1             LCK = 1;//CS=0;
 250   1      
 251   1             SK=1; SK=0; // 1
 252   1       
 253   1             address=address&0x3f|0x40;
 254   1             for(temp=8;temp!=0;temp--) { // 8
 255   2             DI=address&0x80;
 256   2             SK=1; SK=0;
 257   2             address<<=1;
 258   2           }
 259   1          for(temp=16;temp!=0;temp--) { // 16
 260   2          DI=InData&0x8000;
 261   2          SK=1; SK=0;
 262   2          InData<<=1;
 263   2         }
 264   1         LCK = 0;
 265   1         P0 = 0x00;
 266   1         LCK = 1;//CS=0;
 267   1      
 268   1         DO=1;
 269   1      
 270   1         LCK = 0;
 271   1         P0 = 0x40;
 272   1         LCK = 1;//CS=0;
 273   1      
 274   1         SK=1;
 275   1         while(DO==0) { // busy test
 276   2           SK=0; SK=1;
 277   2         }
 278   1        SK=0;    
 279   1        LCK = 0;
 280   1        P0 = 0x00;
 281   1        LCK = 1;//CS=0;
 282   1        Ewds();
 283   1      }
 284          
 285          
 286          //*************************读address开始的一个字节,分高字节和地字节*******************
 287          unsigned char ReadChar(unsigned char address) {
 288   1          unsigned char temp=address>>1;
 289   1          if(address&0x01) return((unsigned char)(Read(temp)>>8));
 290   1          else return((unsigned char)(Read(temp)));
 291   1          }
 292          
 293          //**************************写address开始的一个字节,分高字节和地字节*****************
 294          void WriteChar(unsigned char address,unsigned char InData) {
 295   1             unsigned char temp=address>>1;
 296   1             if(address&0x01) Write(temp,(unsigned int)(Read(temp)&0x00ff|(InData<<8)));
 297   1             else Write(temp,(unsigned int)(Read(temp)&0xff00|InData));
C51 COMPILER V7.06   93C46                                                                 06/19/2007 13:22:16 PAGE 6   

 298   1          }
 299          
 300          //********************************读一个字符串**********************************
 301          void ReadString(unsigned char data *RamAddress,unsigned char RomAddress,unsigned char Number) {
 302   1          while(Number!=0) {
 303   2          *RamAddress=ReadChar(RomAddress);
 304   2          RamAddress++;
 305   2          RomAddress++;
 306   2          Number--;
 307   2         }
 308   1       }
 309          
 310          
 311          //**********************************写一个字符串**************************************//置左又半区标志//置
             -左又半区标志
 312          void WriteString(unsigned char data *RamAddress,unsigned char RomAddress,unsigned char Number) {
 313   1           unsigned int temp;
 314   1           if(Number==0) return;
 315   1           if(RomAddress&0x01) {
 316   2            WriteChar(RomAddress,*RamAddress);
 317   2           RamAddress++;
 318   2           RomAddress++;
 319   2           Number--;
 320   2         }
 321   1      
 322   1         if(Number==0) return;
 323   1         while(Number>>1) {
 324   2         temp=*RamAddress;
 325   2         RamAddress++;
 326   2         temp=temp|(*RamAddress)<<8;
 327   2         RamAddress++;
 328   2         Write(RomAddress>>1,temp);
 329   2         RomAddress++;
 330   2         RomAddress++;
 331   2         Number--;
 332   2         Number--;
 333   2        }
 334   1       if(Number) WriteChar(RomAddress,*RamAddress);
 335   1      
 336   1      } 
 337          
 338          /**********************************结束***********************************/


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    707    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     22       7
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      2    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -