📄 sony2.c
字号:
#include <reg51.h>
#include <intrins.h>
#include <stdio.h>
#include <math.h>
sbit sw1=0x92;
sbit sw2=0x93;
unsigned char poweron[6]={0x81,0x01,0x04,0x00,0x02,0x0ff};
unsigned char ifclear[5]={0x88,0x01,0x00,0x01,0x0ff};
unsigned char address[4]={0x88,0x30,0x01,0x0ff};
unsigned char zoomstop[6]={0x81,0x01,0x04,0x07,0x00,0x0ff};
unsigned char zoomtele[6]={0x81,0x01,0x04,0x07,0x02,0x0ff};
unsigned char zoomwide[6]={0x81,0x01,0x04,0x07,0x03,0x0ff};
unsigned char zoompos[5]={0x81,0x09,0x04,0x47,0x0ff};
unsigned char autowb[6]={0x81,0x01,0x04,0x35,0x00,0x0ff};
unsigned char autofocus[6]={0x81,0x01,0x04,0x38,0x02,0x0ff};
unsigned char apeup[6]={0x81,0x01,0x04,0x02,0x02,0x0ff};
unsigned char apedown[6]={0x81,0x01,0x04,0x02,0x03,0x0ff};
int code table1[50]={41,42,43,44,46,48,50,52,54,56, /*from 0x0000 to 0x2fff*/
58,60,62,64,66,68,70,72,74,76,
/*20*/ 78,80,82,85,88,91,95,99,103,107,
111,115,119,123,128,134,140,146,152,158,
/*40*/ 164,174,184,194,205,215,225,235,
};
int code table2[260]={236,237,238,240,242,244,246,247,248,249, /*from 0x3000 to 0x4000*/
250,251,252,253,254,255,256,257,258,259,
/*20*/ 260,261,262,263,264,265,266,267,268,269,
270,271,272,273,274,275,276,277,278,279,
/*40*/ 280,281,282,283,285,287,288,289,290,291,
292,293,294,295,296,297,298,299,300,301,
/*60*/ 302,303,304,305,306,307,308,309,310,311,
312,313,314,315,316,317,318,319,320,321,
/*80*/ 322,323,325,327,328,329,330,331,332,333,
334,335,336,337,338,339,340,341,342,343,
/*100*/ 344,345,346,347,349,351,353,355,357,359,
361,363,365,367,369,370,371,372,373,374,
/*120*/ 375,376,378,380,382,384,386,388,390,392,
394,396,398,400,402,404,406,408,410,411,
/*140*/ 412,413,414,415,416,417,418,419,420,421,
423,425,427,429,431,433,435,437,439,441,
/*160*/ 443,445,447,449,451,453,455,457,459,461,
463,465,468,471,474,477,480,483,486,489,
/*180*/ 492,494,496,498,500,502,504,506,508,510,
512,514,516,518,520,522,524,526,528,530,
/*200*/ 533,535,537,539,541,544,547,550,553,556,
559,562,565,568,571,574,577,580,583,586,
/*220*/ 589,592,595,598,601,604,607,611,615,618,
621,624,628,632,636,640,644,648,652,656,
/*240*/ 659,662,665,669,673,677,681,685,689,693,
697,703,710,717,724,731,738,
};
unsigned char a,b,c,d,e,f,RN=0,SN=0,OS,NS,SS,order,jh,jl,zj,detail,rev[8];
unsigned int i,tout,tj,delay;
unsigned char SCON1,SBUF1,T2CON,T2MOD;
void receive()
{
RI=0;
i=0;
do
{ while(RI==0){};
rev[i]=SBUF;
RI=0;
i++;
}
while(rev[i-1]!=0x0ff);
}
void initialize()
{
TI=0;
for(i=0;i<5;i++)
{
SBUF1=ifclear[i];
while(TI==0){};
TI=0;
}
receive();
for(i=0;i<4;i++)
{
SBUF1=address[i];
while(TI==0){};
TI=0;
}
receive();
for(i=0;i<6;i++)
{
SBUF1=autowb[i];
while(TI==0){};
TI=0;
}
receive();
if(rev[1]==0x41)
{receive();}
for(i=0;i<6;i++)
{
SBUF1=autofocus[i];
while(TI==0){};
TI=0;
}
receive();
if(rev[1]==0x41)
{receive();}
}
void campos()
{ for(i=0;i<5;i++)
{
SBUF1=zoompos[i];
while(TI==0){};
TI=0;
}
receive();
a=rev[2];
b=rev[3];
c=rev[4];
d=rev[5];
e=a<<4;
e=e|b;
f=e<<4;
f=f|e;
if(e<0x30)
{tout=table1[e];}
else if(e>=0x30)
{tout=table2[f-0x300];}
}
void send(void)
{ EA=0;
ES=0;
if(order==0x080)
{
for(i=0;i<6;i++)
{
SBUF=zoomtele[i];
while(TI==0){};
TI=0;
}
receive();
if(rev[1]==0x41)
{receive();}
}
else if(order==0x040)
{
for(i=0;i<6;i++)
{
SBUF=zoomwide[i];
while(TI==0){};
TI=0;
}
receive();
if(rev[1]==0x41)
{receive();}
}
else
{
for(i=0;i<6;i++)
{
SBUF=zoomstop[i];
while(TI==0){};
TI=0;
}
receive();
if(rev[1]==0x41)
{receive();}
}
SBUF=0x84;
while(TI==0){}
TI=0;
_nop_();_nop_();_nop_();_nop_();
SBUF=0x84;
SS=0x84;
SS=SS+0x84;
while(TI==0){}
TI=0;
_nop_();_nop_();_nop_();_nop_();
SBUF=0x08;
SS=SS+0x08;
while(TI==0){}
TI=0;
SBUF=jl;
SS=SS+jl;
while(TI==0){}
TI=0;
_nop_();_nop_();_nop_();_nop_();
SBUF=jh;
SS=SS+jh;
while(TI==0){}
TI=0;
_nop_();_nop_();_nop_();_nop_();
SBUF=zj;
SS=SS+zj;
while(TI==0){}
TI=0;
_nop_();_nop_();_nop_();_nop_();
SBUF=detail;
SS=SS+detail;
while(TI==0){}
TI=0;
_nop_();_nop_();_nop_();_nop_();
SBUF=SS;
while(TI==0){}
TI=0;
OS=0;
}
void serail_int (void) interrupt 4
{
unsigned char SR;
if(RI==1)
{
SR=SBUF;
RI=0;
if(RN==0)
{
if(SR==0X80)
{
RN++;
}
}
else if(RN==1)
{
if(SR!=0)
{
RN=0;
}
else {RN++;}
}
else if(RN==2)
{
RN++;
}
else if(RN==3)
{
RN++;
order=SR;
}
else if(RN==4)
{
OS=NS;
NS=1;
RN=0;
delay=0;zj=zj&&0x0fb;detail=detail&&0x0fd;
}
}
}
void main(void)
{
PCON=0x00;
TMOD=0x20;
TH1=0x0fd ; TL1=0x0fd ; /*波特率设为9600*/
TR1=1;
SCON1=0x50; /* 串行1方式1,定时器1*/
initialize();
while(1)
{ EA=0;
ES=0;
TR1=0;
PCON=0x00;
TMOD=0x20;
TH1=0x0fd ; TL1=0x0fd ; /*波特率设为9600*/
TR1=1;
SCON1=0x50; /* 串行1方式1,定时器1*/
campos(); /*读相机的焦距值*/
jh=tout/(0x100);
jl=tout%(0x100);
TR1=0;
TMOD=0x21;
TH1=TL1=0x0fd;
PCON=0x80;
SCON=0x0d0;
TR1=1;
EA=1;
ES=1;
if(OS==1)
{ send();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -