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

📄 sccb.lst

📁 SCCB协议的KEIL UVISION3的编程源码。原创
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 1   


C51 COMPILER V8.02, COMPILATION OF MODULE SCCB
OBJECT MODULE PLACED IN sccb.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE sccb.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1           // OmniVision Serial Camera Control Bus (SCCB) Functional File.
   2          //低电平持续时间         最少1,3ns      ------CLK
   3          //高电平持续时间最少为  O。6ns      -----CLK                                                                                                                                    
   4          #include <Reg52.h>
   5          #include <Intrins.h>
   6          #include<stdio.h>
   7          sbit p32=P3^2;
   8          sbit SIO_C=P1^1;
   9          sbit SIO_D=P1^0;
  10          sbit  IO=       P1^2;
  11          //sbit SIO_D=P1^2;
  12          //chip slave ID is 0X42(for write) and 0X43(for read)
  13          #define OV7620_ID  0x42
  14          void serial_init(void)        //改变你需要的位即可!
  15          {
  16   1                       //串口初始化,晶振11.0592Hz,波特率9600
  17   1              SCON = 0x50; // Setup serial port control register 
  18   1                                              // Mode 1: 8-bit uart var. baud rate 
  19   1                                              // REN: enable receiver
  20   1              PCON &= 0x7F; // Clear SMOD bit in power ctrl reg 
  21   1                                              // This bit doubles the baud rate 
  22   1              TMOD &= 0xCF; // Setup timer/counter mode register 
  23   1                                              // Clear M1 and M0 for timer 1 
  24   1              TMOD |= 0x20; //Set M1 for 8-bit autoreload timer 
  25   1              TH1 = 0xFD; // Set autoreload value for timer 1 
  26   1                                              // 9600 baud with 11.0592 MHz xtal 
  27   1              TR1 = 1; // Start timer 1 ->TCON
  28   1          TI = 1; // Set TI to indicate ready to xmit.
  29   1              ES=1;
  30   1              EA=1;
  31   1         }
  32             void delay()
  33          {
  34   1       unsigned char i,j,k;
  35   1        for(i=0;i<10;i++)
  36   1        {
  37   2         for(j=0;j<20;j++)
  38   2         {
  39   3          for(k=0;k<248;k++);
  40   3         }
  41   2        } 
  42   1      }
  43          
  44          void nops(void)          //36us
  45          {
  46   1       //_nop_();
  47   1       //_nop_();
  48   1       //_nop_();
  49   1      // _nop_();
  50   1       //_nop_();
  51   1       _nop_();
  52   1       _nop_();
  53   1       _nop_();
  54   1       _nop_();
  55   1       _nop_();
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 2   

  56   1      }
  57          
  58          void hnops(void)
  59          {
  60   1       //_nop_();
  61   1       //_nop_();
  62   1       //_nop_();
  63   1         _nop_();
  64   1         _nop_();
  65   1      }
  66          void OV7620_SCCB_START(void)
  67          {
  68   1         SIO_C=1;
  69   1         nops();
  70   1         SIO_D=1;
  71   1         nops();
  72   1         SIO_D=0;
  73   1         nops();
  74   1         SIO_C=0;  
  75   1         nops();   
  76   1      
  77   1      }
  78          void OV7620_SCCB_END(void)
  79          {
  80   1        //SIO_C=1;
  81   1        //nops();
  82   1         SIO_D=0;
  83   1         nops();
  84   1      // SIO_D=1;
  85   1      // nops();
  86   1         SIO_C=1;
  87   1         nops();
  88   1         SIO_D=1;   
  89   1      
  90   1      }
  91          
  92          bit  OV7620_SCCB_Readbit(void )
  93          {
  94   1         bit temp=0;
  95   1      
  96   1          nops();  
  97   1          SIO_C=1;
  98   1          //input 
  99   1          nops();
 100   1          if(SIO_D)
 101   1          temp =1;
 102   1           nops();
 103   1              SIO_C=0;
 104   1          nops();   
 105   1      //       SBUF=temp;
 106   1      //               delay();
 107   1      
 108   1               return  temp;
 109   1      
 110   1      } 
 111          void  OV7620_SCCB_Writebit(bit a)
 112          {
 113   1          nops();  
 114   1              SIO_D=a;
 115   1          nops();
 116   1               nops();
 117   1          SIO_C=1;
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 3   

 118   1          nops();
 119   1          SIO_C=0;
 120   1          nops();      
 121   1      }
 122          
 123          
 124          void OV7620_SCCB_Writechar(unsigned char   b)
 125          {
 126   1               int i = 0; 
 127   1                SBUF=b;
 128   1                       delay(); 
 129   1          /* data */  
 130   1          for (i = 0; i < 8; i++ ) {  
 131   2              OV7620_SCCB_Writebit(b & 0x80);  
 132   2              b <<= 1;  
 133   2          }  
 134   1        
 135   1          /* 9th bit - Don't care */  
 136   1          OV7620_SCCB_Writebit(1);  
 137   1               nops();
 138   1               nops();
 139   1      }
 140          
 141          unsigned char  V7620_SCCB_Readchar( void)
 142          {  
 143   1          char  i;  
 144   1          unsigned char  tmp = 0;  
 145   1          unsigned char  val;
 146   1          bit    l=0;
 147   1               SIO_D=1;
 148   1                nops();
 149   1                 nops();
 150   1          for (i = 7; i >= 0; i--)     //0-255  溢出     没有报错    
 151   1              {
 152   2                 l=   OV7620_SCCB_Readbit();
 153   2                  tmp<<=1;
 154   2                 if(l)
 155   2                 {//tmp = tmp | (1<<i);  
 156   3                       tmp=tmp | 0x01;
 157   3                 
 158   3                 } 
 159   2              } 
 160   1      
 161   1              nops();
 162   1          /* 9th bit - N.A. */  
 163   1          OV7620_SCCB_Writebit(1);  
 164   1               nops();
 165   1               nops();
 166   1          val = tmp & 0xff; 
 167   1                return  val;
 168   1      }     
 169          
 170          unsigned char OV7620_Read_SCCB_CMOS(unsigned char DeviceAddress,unsigned char RegisterAddress)
 171          {
 172   1          
 173   1       unsigned char  val=0;
 174   1          //   SBUF=DeviceAddress;
 175   1              //       delay();
 176   1              //       SBUF=RegisterAddress;
 177   1              //       delay();
 178   1      
 179   1        /* 2-phase write */  
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 4   

 180   1       OV7620_SCCB_START();        //Start
 181   1       OV7620_SCCB_Writechar(DeviceAddress);
 182   1       OV7620_SCCB_Writechar(RegisterAddress);
 183   1       OV7620_SCCB_END();    //stop
 184   1        nops();
 185   1         nops();
 186   1        /* 2-phase read */  
 187   1       OV7620_SCCB_START();        //Start
 188   1       OV7620_SCCB_Writechar(DeviceAddress | 0X01);
 189   1        val=V7620_SCCB_Readchar();  
 190   1      
 191   1       OV7620_SCCB_END();    //stop
 192   1      
 193   1       return val;
 194   1      }
 195          
 196          void  OV7620_Write_SCCB_COMS(unsigned char DeviceAddress,unsigned char RegisterAddress, unsigned char Writ
             -e_Data)
 197          {
 198   1                /* 3-phase write */  
 199   1       OV7620_SCCB_START();        //Start
 200   1       OV7620_SCCB_Writechar(DeviceAddress);
 201   1       OV7620_SCCB_Writechar(RegisterAddress);
 202   1       OV7620_SCCB_Writechar( Write_Data);
 203   1       OV7620_SCCB_END();    //stop
 204   1      
 205   1      
 206   1      }
 207           //相当于一个二相写和一个二相读操作
 208          unsigned char Read_CMOS(unsigned char DeviceAddress,unsigned char RegisterAddress)
 209          {
 210   1       unsigned char  bdata  Buffer_Data;
 211   1      
 212   1       bit Buffer_Data0=Buffer_Data^0;
 213   1       bit Buffer_Data1=Buffer_Data^1;
 214   1       bit Buffer_Data2=Buffer_Data^2;
 215   1       bit Buffer_Data3=Buffer_Data^3;
 216   1       bit Buffer_Data4=Buffer_Data^4;
 217   1       bit Buffer_Data5=Buffer_Data^5;
 218   1       bit Buffer_Data6=Buffer_Data^6;
 219   1       bit Buffer_Data7=Buffer_Data^7;
 220   1      
 221   1       Buffer_Data= 0x42;
 222   1       //printf("write data to register 0x 1c is %x\n",Buffer_Data);
 223   1       F0=0; 
 224   1       //SIO_E=0;
 225   1       //nops();
 226   1      
 227   1       OV7620_SCCB_START();      //Start
 228   1      
 229   1      
 230   1      
 231   1       SIO_D=Buffer_Data7;
 232   1        nops();
 233   1       SIO_C=1;
 234   1       nops();
 235   1       SIO_C=0;
 236   1       nops();         //bit7
 237   1       
 238   1       SIO_D=Buffer_Data6;
 239   1        nops();
 240   1       SIO_C=1;
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 5   

 241   1       nops();
 242   1       SIO_C=0;
 243   1       nops();         //bit6
 244   1      
 245   1       SIO_D=Buffer_Data5;
 246   1        nops();
 247   1       SIO_C=1;
 248   1       nops();
 249   1       SIO_C=0;
 250   1       nops();         //bit5
 251   1      
 252   1       SIO_D=Buffer_Data4;
 253   1        nops();
 254   1       SIO_C=1;
 255   1       nops();
 256   1       SIO_C=0;
 257   1       nops();         //bit4
 258   1      
 259   1       SIO_D=Buffer_Data3;
 260   1        nops();
 261   1       SIO_C=1;
 262   1       nops();
 263   1       SIO_C=0;
 264   1       nops();         //bit3
 265   1      
 266   1       SIO_D=Buffer_Data2;
 267   1        nops();
 268   1       SIO_C=1;
 269   1       nops();
 270   1       SIO_C=0;
 271   1       nops();         //bit2
 272   1      
 273   1       SIO_D=Buffer_Data1;
 274   1       SIO_C=1;
 275   1       nops();
 276   1       SIO_C=0;
 277   1       nops();        //bit1
 278   1      
 279   1       SIO_D=Buffer_Data0;
 280   1        nops();
 281   1       SIO_C=1;
 282   1       nops();
 283   1       SIO_C=0;
 284   1       nops();        //bit0
 285   1       SIO_D=1;          // don't care  1
 286   1       nops();
 287   1       nops();
 288   1       nops();
 289   1      
 290   1      
 291   1       SIO_C=1;
 292   1        nops();
 293   1       
 294   1       SIO_C=0;     
 295   1       nops();       
 296   1       //     printf("send DeviceAddress success\n");
 297   1       
 298   1       Buffer_Data=RegisterAddress; 
 299   1       //printf("write data to register 0x 1c is %x\n",Buffer_Data);
 300   1       SIO_D=0;
 301   1        nops();
 302   1       SIO_C=1;
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 6   

 303   1       nops();
 304   1       SIO_C=0;
 305   1       nops();         //bit7
 306   1       
 307   1       SIO_D=0;
 308   1        nops();
 309   1       SIO_C=1;
 310   1       nops();
 311   1       SIO_C=0;
 312   1       nops();         //bit6
 313   1      
 314   1       SIO_D=0;
 315   1        nops();
 316   1       SIO_C=1;
 317   1       nops();
 318   1       SIO_C=0;
 319   1       nops();         //bit5
 320   1      
 321   1       SIO_D=1;
 322   1        nops();
 323   1       SIO_C=1;
 324   1       nops();
 325   1       SIO_C=0;
 326   1       nops();         //bit4
 327   1      
 328   1       SIO_D=1;
 329   1        nops();
 330   1       SIO_C=1;
 331   1       nops();
 332   1       SIO_C=0;
 333   1       nops();         //bit3
 334   1      
 335   1       SIO_D=1;
 336   1        nops();
 337   1       SIO_C=1;
 338   1       nops();
 339   1       SIO_C=0;
 340   1       nops();         //bit2
 341   1      
 342   1       SIO_D=0;
 343   1        nops();
 344   1       SIO_C=1;
 345   1       nops();
 346   1       SIO_C=0;
 347   1       nops();        //bit1
 348   1      
 349   1       SIO_D=1;
 350   1        nops();
 351   1       SIO_C=1;
 352   1       nops();
 353   1       SIO_C=0;
 354   1       nops();        //bit0
 355   1       SIO_D=1;        // don't care  0 
 356   1       nops();
 357   1       nops();
 358   1       nops();
 359   1      
 360   1       SIO_C=1;
 361   1        nops();
 362   1       SIO_C=0;     
 363   1       nops();        //check Ack    don't care  1
 364   1      //      printf("send RegisterAddress success\n");
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 7   

 365   1      
 366   1      
 367   1       OV7620_SCCB_END();    //stop
 368   1      
 369   1        nops();
 370   1        nops();
 371   1        nops();
 372   1        nops();
 373   1      
 374   1       OV7620_SCCB_START();        //Start
 375   1      
 376   1      
 377   1      Buffer_Data=0X43; // 0x43
 378   1      // printf("write data to register 0x 1c is %x\n",Buffer_Data);
 379   1       SIO_D=0;
 380   1        nops();
 381   1       SIO_C=1;
 382   1       nops();
 383   1       SIO_C=0;
 384   1       nops();         //bit7
 385   1       
 386   1       SIO_D=1;
 387   1        nops();
 388   1       SIO_C=1;
 389   1       nops();
 390   1       SIO_C=0;
 391   1       nops();         //bit6
 392   1      
 393   1       SIO_D=0;
 394   1        nops();
 395   1       SIO_C=1;
 396   1       nops();
 397   1       SIO_C=0;
 398   1       nops();         //bit5
 399   1      
 400   1       SIO_D=0;
 401   1        nops();
 402   1       SIO_C=1;
 403   1       nops();
 404   1       SIO_C=0;
 405   1       nops();         //bit4
 406   1      
 407   1       SIO_D=0;
 408   1        nops();
 409   1       SIO_C=1;
 410   1       nops();
 411   1       SIO_C=0;
 412   1       nops();         //bit3
 413   1      
 414   1       SIO_D=0;
 415   1        nops();
 416   1       SIO_C=1;
 417   1       nops();
 418   1       SIO_C=0;
 419   1       nops();         //bit2
 420   1      
 421   1       SIO_D=1;
 422   1        nops();
 423   1       SIO_C=1;
 424   1       nops();
 425   1       SIO_C=0;
 426   1       nops();        //bit1
C51 COMPILER V8.02   SCCB                                                                  01/07/2009 13:14:33 PAGE 8   

 427   1      
 428   1       SIO_D=1;

⌨️ 快捷键说明

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