📄 main.c
字号:
/*******************************
void wait_for_input(unsigned int){
function:wait for input from specified key groups
input: imask: which group of keys monitored
return: key id in ikey
global variables:ikey,nk,flag_keyscan_en;
call: none
********************************/
void wait_for_input(unsigned int imask){
J1:while (flag_keyscan_en) { //wait for input
;
}
if (!(nk&imask)) { //no allowed key
flag_keyscan_en=1;
goto J1;
}
ikey=0;
while (!(nk&keys[ikey])) ikey++;
}
/*********************************
void wait_for_release(void)
function:delay and wait for release of specified key
input: ikey: which key is monitored
return: none
global variables:ikey,nk,flag_keyscan_en;
call: none
**********************************/
void wait_for_release(void){
unsigned char delay=5;
flag_keyscan_en=1;
while (--delay){
while (flag_keyscan_en) {
;
}
flag_keyscan_en=1;
}
do {
flag_keyscan_en=1;
}
while (!((~nk)&keys[ikey])); //wait for button release
}
/***********************************
unsigned int inpint(unsigned char pos,dig)
input dig-digs integer v at pos
************************************/
unsigned int inpint(unsigned char pos,unsigned char dig) {
unsigned int res=0;
unsigned char i;
for(i=0;i<dig;i++){
wait_for_input(KEY_NUM_F_ENABLE);
if(ikey==15) break;
res*=10;
res+=ikey;
disint(res,(pos),dig);
wait_for_release();
}
wait_for_release();
return res;
}
//========================================
//Camera Operation
//操作
//========================================
/***********************************
display prg setting
************************************/
void disprg(void){
disstr(menu_prg,(DISP_LINE2),16);
disint(camexpo,(4|DISP_LINE2),3);
disint(camwait,(8|DISP_LINE2),3);
disint(camrpt,(12|DISP_LINE2),3);
}
/***********************************
setmode
************************************/
void setmode(void) {//设置系统
dismenu(menu_mode1,menu_mode2);
ikey=15;
wait_for_release();
wait_for_input(KEY_13_ENABLE);
if (ikey<4) mode=ikey;
switch(mode){
case 1: //995
disstr(menu_995,(DISP_POS),16);
disprg();
break;
case 2: //20D
disstr(menu_20d,(DISP_POS),16);
disprg();
break;
case 3:
dismenu(menu_com1,menu_com2);
break;
}
wait_for_release();
}
/************************************
void setcamera(void)
设置DC程控曝光参数(曝光时间,间隔时间,拍摄次数)
保存在全局变量中
*************************************/
void setcamera(void){
wait_for_release();
dismenu(menu_setcam,menu_prg);
//input exposure time in seconds (0-999)
camexpo=inpint((4|DISP_LINE2),3);
//input wait time in seconds (0-999)
camwait=inpint((8|DISP_LINE2),3);
//input repeat times
camrpt=inpint((12|DISP_LINE2),3);
switch(mode){
case 1: //995
disstr(menu_995,(DISP_POS),16);
break;
case 2: //20d
disstr(menu_20d,(DISP_POS),16);
break;
default:
;
}
disprg();
}
/*******************************
unsigned char camdelay(unsigned int)
延时指定的秒数并显示,5秒以上按原健退出
输出:0:延时结束 1:退出
需要释放原键,否则延迟(不累积)
********************************/
unsigned char camdelay(unsigned int isec)
{
unsigned int elapssec=0;
bit flag_released=0;
second_cnt=20; //同步
secticker=0;
if(isec<6){
while (secticker<isec){
if(flag_newsec) {
elapssec=secticker;
disint(elapssec,(13|DISP_POS),3);
flag_newsec=0;
}
}
return 0;
}
wait_for_release();
nk=0;
flag_keyscan_en=1;
while (secticker<isec){
if (!flag_keyscan_en) {
if(nk&keys[ikey]) return 1; //按原键
flag_keyscan_en=1;
}
if(flag_newsec) {
elapssec=secticker;
disint(elapssec,(13|DISP_POS),3);
flag_newsec=0;
}
}
return 0;
}
/*******************************
反光镜预升
等效1秒曝光
********************************/
void mirrorlock(void)
{
second_cnt=20;
secticker=0;
if(!flag_focus){
FOCUS=1;
while (secticker<1){
;
}
second_cnt=20;
secticker=0;
}
SHUTTER=1;
while (secticker<1){
;
}
SHUTTER=0;
FOCUS=0;
flag_focus=0;
camdelay((unsigned int)(mirror));
}
/*******************************
void eos20d(void)
20d operation
********************************/
void eos20d(void){
switch(ikey){
case 9: //T
disp_cmd((DISP_POS|8));
disp_write('T');
case 0: //1s
case 1: //1m
case 2: //2m
case 3: //3m
case 4: //4m
if(flag_mirror) mirrorlock();
if(!flag_focus){
FOCUS=1;
camdelay(1);
}
SHUTTER=1;
camdelay(expo[ikey]);
SHUTTER=0;
FOCUS=0;
flag_focus=0;
break;
case 8: //focus
flag_focus=!flag_focus;
FOCUS=flag_focus;
break;
case 6: //shoot
if(flag_mirror) mirrorlock();
if(!flag_focus){
FOCUS=1;
camdelay(1);
}
SHUTTER=1;
wait_for_release();
SHUTTER=0;
FOCUS=0;
flag_focus=0;
break;
case 5://PRG
disp_cmd(DISP_POS|8);
disp_write('P');
while(camrpt--){
if(flag_mirror) mirrorlock();
FOCUS=1;
camdelay(1);
SHUTTER=1;
if(camdelay(camexpo)) break;
SHUTTER=0;
FOCUS=0;
if(camdelay(camwait)) break;
disint(camrpt,(12|DISP_LINE2),3);
}
SHUTTER=0;
FOCUS=0;
flag_focus=0;
break;
case 14: //expo setup
setcamera();
break;
case 12: //mirror lock
dismenu(menu_mirror1,menu_mirror2);
disstr(flag_mirror?str_on:str_off,(DISP_POS|12),3);
disint(mirror,DISP_LINE2|6,2);
wait_for_release();
wait_for_input(KEY_NUM_CF_ENABLE);
if(ikey<10){
mirror=ikey;
disint((unsigned int)(mirror),DISP_LINE2|6,2);
wait_for_release();
wait_for_input(KEY_NUM_CF_ENABLE);
if(ikey<10) {
mirror*=10;
mirror+=ikey;
disint((unsigned int)(mirror),DISP_LINE2|6,2);
}
if(ikey!=12){
wait_for_release();
wait_for_input(KEYC|KEYF);
}
}
if(ikey==12) flag_mirror=~flag_mirror;
disstr(menu_20d,(DISP_HOME),16);
disprg();
break;
case 15: //切换模式
FOCUS=0;
break;
default:
break;
}
disp_cmd(DISP_POS|8);
disp_write(' ');
disp_write(flag_mirror?'M':' ');
disp_write(flag_focus?'F':' ');
}
//相机控制
//控制指令协议
unsigned char code camcmd[24][4]={
{0x1B, 0x53, 0x06,0x00},
{0x00, 0x11, 0x02,0x00},
{0x00, 0x00, 0x13,0x00}, //Standard SetSpeed to 19200 command packet
{0x1B, 0x53, 0x06,0x00},
{0x00, 0x11, 0x02,0x00},
{0x00, 0x10, 0x23,0x00}, //Go to MC-EU1 protocol packet, switch LCD ON
{0x9B, 0x85, 0x1C,0x1C}, //6 Initialisations
{0x9B, 0x13, 0x1C,0x1C}, //response
{0x9B, 0x08, 0x1C,0x1C}, //8 Has camera power down ?
{0x9B, 0x01, 0x1C,0x1C}, //9 Half press the shutter button.
{0x9B, 0x01, 0x7F,0x1C}, //10 Full press the shutter button,
{0x9B, 0x01, 0x7F,0x7F}, //11 Release the shutter button,
{0x9B, 0x01, 0x1C,0x7F}, //12 Half press release (unlock shutter button).
{0x9B, 0x02, 0x1C,0x1C}, //13 "Press" the zoom in button
{0x9B, 0x02, 0x1C,0x7F}, //"Release" the zoom in button
{0x9B, 0x02, 0x7F,0x1C}, //15 "Press" the zoom out button
{0x9B, 0x02, 0x7F,0x7F}, //"Release" the zoom out button
{0x9B, 0x04, 0x1C,0x1C}, //17 "Press" right,next
{0x9B, 0x04, 0x1C,0x7F}, //"Release" right
{0x9B, 0x04, 0x7F,0x1C}, //19 "Press" left ,previous
{0x9B, 0x04, 0x7F,0x7F}, //"Release" left
{0x9B, 0x07, 0x1C,0x1C}, //21 Number of picture left
{0x9B, 0x89, 0x1C,0x1C}, //22 A/M/P mode
{0x9B, 0x8A, 0x1C,0x1C}}; //23Go back to standard protocol LCD OFF},
/***************************
void wait_for_camera(unsigned char)
function: camera operation
****************************/
void wait_for_camera(unsigned char cc){
unsigned char delay=125;
flag_keyscan_en=1;
while (--delay){
while (flag_keyscan_en) {
if(uartread!=uartwrite){//有新数据
if(++uartread>7) uartread=0;
if(cc==uartbuf[uartread]) return;
}
}
flag_keyscan_en=1;
}
return;
}
/***************************
void sendcmd_to_camera(unsigned char)
function: camera operation
****************************/
sendcmd_to_camera(unsigned char cc){ //发送4字节命令
unsigned char i;
for(i=0;i<4;i++) {
while(flag_uart_busy){
;
}
flag_uart_busy=1;
SBUF=camcmd[cc][i];
}
}
/*******************************
void cp995d(void)
995 operation
********************************/
void cp995(void){
switch (ikey){
case 0: //1s
case 1: //1m
case 2: //2m
case 3: //3m
case 4: //4m
case 9: //T
if(!flag_focus){
sendcmd_to_camera(9);
wait_for_camera(0x86);
}
sendcmd_to_camera(10);
wait_for_camera(0x86);
camdelay(expo[ikey]);
sendcmd_to_camera(11);
wait_for_camera(0x8F);
sendcmd_to_camera(12);
wait_for_camera(0x86);
flag_focus=0;
break;
case 8: //focus
flag_focus=!flag_focus;
sendcmd_to_camera(flag_focus?9:12);
break;
case 6: //shoot
if(!flag_focus){
sendcmd_to_camera(9);
wait_for_camera(0x86);
}
sendcmd_to_camera(10);
wait_for_camera(0x86);
wait_for_release();
sendcmd_to_camera(11);
wait_for_camera(0x8F);
sendcmd_to_camera(12);
wait_for_camera(0x86);
flag_focus=0;
break;
case 5://PRG
while(camrpt--){
if(!flag_focus){
sendcmd_to_camera(9);
wait_for_camera(0x86);
}
sendcmd_to_camera(10);
wait_for_camera(0x86);
if(camdelay(camexpo)) break;
sendcmd_to_camera(11);
wait_for_camera(0x8F);
sendcmd_to_camera(12);
wait_for_camera(0x86);
flag_focus=0;
if(camdelay(camwait)) break;
disint(camrpt,(12|DISP_LINE2),3);
}
break;
case 14: //expo setup
setcamera();
break;
case 12://C连接
while(flag_uart_busy){
;
}
SBUF=0x00;
wait_for_camera(0xFF);
while(flag_uart_busy){
;
}
SBUF=0x00;
wait_for_camera(0x15);
sendcmd_to_camera(0);
sendcmd_to_camera(1);
sendcmd_to_camera(2);
wait_for_camera(0x06);
sendcmd_to_camera(3);
sendcmd_to_camera(4);
sendcmd_to_camera(5);
wait_for_camera(0x06);
flag_focus=0;
break;
case 10://A,广角
sendcmd_to_camera(15);
wait_for_camera(0x86);
sendcmd_to_camera(16);
ikey=15;//else just 1 step
break;
case 11: //B,长焦
sendcmd_to_camera(13);
wait_for_camera(0x86);
sendcmd_to_camera(14);
ikey=15;//else only 1 step
break;
case 15: //切换模式
if(flag_focus){
flag_focus=0;;
sendcmd_to_camera(12);
}
break;
}
}
/*******************************
void polar(void)
calculate polar's hour angle for polar alignment
********************************/
void polar(void){
unsigned int hour=13,min=112,sec=3550,year,mon,day;
unsigned char i;
unsigned char code dom[12]={122,31,30,31,30,31,31,30,31,30,31,31};
//intp=daysofmonth+floor(yy/4)+day
//frap=day0
//gmst=9089+frap*(1.0027375)+236.5553679*intp-57.29*yy (s)
// =2h31m29s+frap*(1.0027375)+(4m-3.4446s)*intp-1m*yy+2.71s*yy
//for BT =66610s hour=15,min=151,sec=3550
//RA of alpha UMi=2h39m00s
//correction for precession 2006.1.1=39m04s 2011.1.1=46m24s =39m+[88(yy-6)+22/3mm-10/3]s
wait_for_release();
dismenu(menu_polar1,menu_polar2);
//input year from 2000 (1-99)
year=inpint((DISP_POS|2),2);
//input month (1-12)
mon=inpint((DISP_POS|5),2);
sec-=(88*(year-6)+(22*mon-10)/3);
mon--;
mon%=12;
if(mon<2){
mon+=12;
year--;
}
min-=year; //-1m*yy
day=year/4;
sec+=(year*271)/100;//+2.71s*yy
//input day (1-31)
for(i=1;i<mon;i++) day+=dom[i-1];
day+=inpint((DISP_POS|8),2);
min+=day*4; //=2h31m29s+frap*(1.0027375)
sec-=(day*31)/9;//-3.4446s*intp
//input hour (0-24)
year=inpint((DISP_POS|11),2);
hour+=year;
sec+=(year*473)/48;//9.855s/h
//input min (0-60)
mon=inpint((DISP_POS|14),2);
min+=mon;
sec+=(mon*11)/67;//0.16425s/m
//input longitude degree (0-99)
min+=(100+inpint((DISP_LINE2|1),2))*4;
//input longitude min (0-60)
sec+=inpint((DISP_LINE2|4),2)*4;
while(sec>59) {
sec-=60;
min++;
}
while(min>59){
min-=60;
hour++;
}
while(hour>23) hour-=24;
disint(hour,(LINE2_8),2);
disint(min,(LINE2_11),2);
disint(sec,(LINE2_14),2);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -