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

📄 com.lst

📁 8051 SPI_93c46 c语言程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
 170   2         }
 171   1        LCK = 0;
 172   1        P0 = 0xfe;
 173   1        LCK = 1;//CS=0;
C51 COMPILER V7.06   COM                                                                   02/28/2007 16:12:35 PAGE 4   

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

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

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


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    700    ----
   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 + -