📄 main.cpp
字号:
#include <stdio.h>
#include <graphics.h>
#include <dos.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <conio.h>
#include <assert.h>
#include <time.h>
#include <bios.h>
#include <alloc.h>
#include "xms.h"
#include "map.h"
#include "g_func.h"
#include "global.h"
#include "powerkey.h"
#include "marker.h"
#include "keydef.h"
#include "set9852.h"
#include "freqkey.h"
#include "set7249.h"
#include "store.h"
#include "verify.h"
#include "rd7472.h"
#include "display.h"
#include "scale.h"
//#include "keylink.h"
#ifdef __cplusplus
#define __CPPARGS ...
#else
#define __CPPARGS
#endif
void interrupt_init();
void interrupt_destory();
void interrupt (*old_key)(__CPPARGS);
void interrupt new_key(__CPPARGS);
void key_process();
void interrupt (*old_IRQ9)(__CPPARGS);
void interrupt new_IRQ9(__CPPARGS);
void IRQ9_process(void);
void InitGraph();
void CloseGraph();
void StoreStatus();
void Greet();
void draw_graph(int);
//void marker();
FILETOXMS *font12;
//add on 04-09-24
//KeyLink *keylink;
extern char disp_switch;
extern char*disp[];
extern BOOL KeyBusy;
extern BOOL _sys_exit;
extern BOOL _sys_Reset;
//extern int ch_colora;
//extern int ch_colorb;
void graph();
int x_mark[2][8],y_mark[2][8];
BOOL DispSwitchBusy = FALSE;
BOOL WritingFile = FALSE;
BOOL recall_end = FALSE;
char flag_disp = 0;
//int x_mkr_search[2][4],y_mkr_search[2][4];
//float ymax[2],ymin[2];
//extern int alter;
MDAMAP *mda_map;
extern void init_vars();
extern int color_xch;
char aflag;
char chss;
void InitCom2()
{
outportb(0x2fb,0x80); //set div
outportb(0x2f9,0x0); //9600 baud
outportb(0x2f8,0x0c);
outportb(0x2fb,0x03); //no check,1 stop bit,8 bits data
outportb(0x2f9,0x00); //enable receive interrupt
outportb(0x2fc,0x0); //
}
void main()
{
int i,j,data,swp_pnt,flag,the_points,cen_i,follow_min,follow_max,follow_cen,f_i1,f_i2;
// char color;
float pwr_now;
float max_in_pb,min_in_pb;
long ld_cnt,freq_now_cen,freq[2];
long freq_step,freq_now;
float power_step;
unsigned char load[3];
int x_max,x_min,temp_max,temp_min;
char msg[20],msg1[2],msg2[2],msg3[2];
// int x_old,y_old;
double FTW;
int color;
// keylink = new KeyLink;
InitGraph();
interrupt_init();
InitCom2();
Greet();
// XMS::Init();
// mda_map=new MDAMAP();
////lingyi
// clear_rect(450,450,639,470);
// clear_rect(450,450,639,470);
start:
XMS::Init();
mda_map=new MDAMAP();
////lingyi
clear_rect(450,450,639,470);
clear_rect(450,450,639,470);
// graph();
mda_map->ScreenClear();
init9852();
init_vars();
StoreStatus();
StoreMarker();
StoreScale();
StoreDisp();
// StoreInfo();
TEXTFRTLN=_system.colora;
TEXTTHRLN=_system.colora;
TEXTSEDLN=_system.colorb;
// key_process();
while(1){
key_process();
scan:
enable();
if(_sys_exit){
delete mda_map;
interrupt_destory();
CLR_LN4;
outtextxy(35,464,"Press any key to exit!");
// printf("%d",sizeof(_SYSTEMP));
getch();
CloseGraph();
exit(0);
}
if(_sys_Reset){
delete mda_map;
_sys_Reset=FALSE;
goto start;
}
// store and recall process
// if(_store.is_store==1){
// Store(_store.mem_sel);
// _store.is_store=0;
// }
/* if(_store.is_recall==1){
int save_chs=chs;
mda_map->ScreenClear();
mda_map->Line(0,0,0,0);
mda_map->ScreenMove();
chs=1-chs;
mda_map->ScreenClear();
mda_map->Line(0,0,0,0);
mda_map->ScreenMove();
chs=1-chs;
Recall(_store.mem_sel);
chs=ch_sel;
if(chs!=save_chs)
chss=1-chss;
aflag=0;
vision();
refr_ln3();
refresh_up();
StoreStatus();
mkr_xch = TRUE;
scl_xch = TRUE;
dsp_xch = TRUE;
_store.is_recall=0;
}
*/
// disp_time();
key_process();
// if (_disp.disp_way == 2&&(_chab[0].on_off==ON&&_chab[1].on_off==OFF))
swp_pnt=_status[chs].sweep_points-1;
//set
assert(swp_pnt>0);
ld_cnt=(long)((double)_sweep[chs].sweep_time*100/(double)swp_pnt);
load[0]=ld_cnt%256;
load[1]=(ld_cnt>>=8)%256;
load[2]=(ld_cnt>>=8)%256;
outportb(0x345,load[0]);
outportb(0x346,load[1]);
outportb(0x347,load[2]);
if(_sweep[chs].flag1==0) //automatic sweep
the_points=_status[chs].sweep_points;
else if(_sweep[chs].flag1==1){
the_points=_sweep[chs].swp_pc+1;
}
//begin to sweep
freq_step=(long)((double)_freq[chs].freq_width/swp_pnt);
// if(_chab[0].on_off==OFF&&_chab[1].on_off==OFF)
// {
// goto MAP;
// }
if(_chab[chs].on_off==OFF)
{ //delay(100);
// printf("%d",chs);
goto MAP;
}
// key_process();
if(_power[chs].power_sweep==ON){
power_step=(_power[chs].end_power-_power[chs].start_power)/swp_pnt;
}
else
power_step=0;
if(_power[chs].flag==1){
if(_power[chs].power_sweep){
// set_relay(_power[chs].start_power);
freq_now=_freq[chs].start_freq;
}
else {
// set_relay(_power[chs].output_power);
freq_now=_freq[chs].start_freq;
}
}
set9852(freq_now);
// set7249(freq_now,_power[chs].output_power);
if(_power[chs].power_sweep){
set7249(_freq[chs].start_freq,_power[chs].start_power);
}
else
set7249(_freq[chs].start_freq,_power[chs].output_power);
if(_isverify&&ch_sel==chs) //modify on 04-09-20
disable();
for(i=0;i<the_points-1;i++){ // repeat sweep_points-1
key_process();
if(stat_xch==1){
StoreStatus();
disable();
mda_map->ScreenClear();
stat_xch=0;
goto scan;
}
if(dsp_xch == 1){
StoreDisp();
dsp_xch = 0;
goto scan;
}
if(color_xch==1){
color_xch=0;
StoreStatus();
setcolor(7);
mda_map->ScreenClear();
mda_map->Line(0,0,0,0,chs==0?_system.colora:_system.colorb);
mda_map->ScreenMove();
goto scan;
}
if(recall_end){
TEXTFRTLN=_system.colora;
TEXTTHRLN=_system.colora;
TEXTSEDLN=_system.colorb;
setcolor(7);
mda_map->ScreenClear();
mda_map->Line(0,0,0,0,chs==0?_system.colora:_system.colorb);
mda_map->ScreenMove();
// printf("%d%d ",ch_sel,chs);
vision();
refr_ln3();
recall_end = FALSE;
goto scan;
}
while((inportb(0x348)&0x01)); // wait for a plus pulse
while((inportb(0x348)&0x01));
while(!(inportb(0x348)&0x01));
while(!(inportb(0x348)&0x01));
if(freq_now<500000){
while((inportb(0x348)&0x01)); // wait for a plus pulse
while((inportb(0x348)&0x01));
while(!(inportb(0x348)&0x01));
while(!(inportb(0x348)&0x01));
while((inportb(0x348)&0x01)); // wait for a plus pulse
while((inportb(0x348)&0x01));
while(!(inportb(0x348)&0x01));
while(!(inportb(0x348)&0x01));
}
// if(freq_now<500000)
// delay(1);
if(chs==0){
y_a[i]=read7472();
}
else if(chs==1)
y_b[i]=read7472();
if(_freq[chs].is_dot_freq==TRUE)
continue;
freq_now+=freq_step;
if(_power[chs].power_sweep){
if((_power[chs].start_power+(i-1)*power_step<-60
&&_power[chs].start_power+(i)*power_step>=-60)||
(_power[chs].start_power+(i-1)*power_step<-50
&&_power[chs].start_power+(i)*power_step>=-50)||
(_power[chs].start_power+(i-1)*power_step<-40
&&_power[chs].start_power+(i)*power_step>=-40)||
(_power[chs].start_power+(i-1)*power_step<-30
&&_power[chs].start_power+(i)*power_step>=-30)||
(_power[chs].start_power+(i-1)*power_step<-20
&&_power[chs].start_power+(i)*power_step>=-20)||
(_power[chs].start_power+(i-1)*power_step<-10
&&_power[chs].start_power+(i)*power_step>=-10)||
(_power[chs].start_power+(i-1)*power_step<0
&&_power[chs].start_power+(i)*power_step>=0)){
set_relay(_power[chs].start_power+i*power_step);
delay(200);
}
set7249(freq_now,_power[chs].start_power+i*power_step);
}
else
set7249(freq_now,_power[chs].output_power);
set9852(freq_now);
}
if(chs==0)
y_a[the_points-1]=read7472();
else if(chs==1)
y_b[the_points-1]=read7472();
enable();
if(_isverify&&ch_sel==chs){
for(i=0;i<the_points;i++)
(chs==0?y_a_verify[i]:y_b_verify[i])=4096*(_power[chs].output_power+110)/125-(chs==0?y_a[i]:y_b[i]);
_isverify=0;
// StoreVerify();
CLR_DIGITAL;
Outchar12(105,462,"校准结束!",TEXTDIGITAL);
}
else{
if(_freq[chs].is_dot_freq==FALSE){
if(chs==0)
for(i=0;i<the_points;i++)
y_a[i]+=y_a_verify[i];
else if(chs==1)
for(i=0;i<the_points;i++)
y_b[i]+=y_b_verify[i];
}
}
//reset scan signal
enable();
if(alternative==ON&&_chab[1-chs].on_off==ON){
set9852(_freq[1-chs].start_freq);
if(_power[chs].power_sweep){
set7249(_freq[1-chs].start_freq,_power[1-chs].start_power);
}
else
set7249(_freq[1-chs].start_freq,_power[1-chs].output_power);
}
else{
set9852(_freq[chs].start_freq);
// clear_rect(100,100,200,120);
if(_power[chs].power_sweep){
set7249(_freq[chs].start_freq,_power[chs].start_power);
}
else{
set7249(_freq[chs].start_freq,_power[chs].output_power);
// char str[20];
// sprintf(str, "%f", _power[chs].output_power);
// outtextxy(100, 100, str);
}
}
MAP:
//printf("%d ",chs);
color=(chs==0?_system.colora:_system.colorb);
if(mkr_xch){
StoreMarker();
mkr_xch = FALSE;
}
if(scl_xch){
StoreScale();
scl_xch = FALSE;
}
if(dsp_xch){
StoreDisp();
dsp_xch = FALSE;
}
temp_max = -32000;
temp_min = 32000;
// color=(chs==0?CHAWAVELINE:CHBWAVELINE);
// _marker[chs].max_mkr.power = Max(_freq[chs].start_freq,_freq[chs].end_freq,chs);
// _marker[chs].min_mkr.power = Min(_freq[chs].start_freq,_freq[chs].end_freq,chs);
for(i=0;i<the_points;i++){
if(chs==0){
if(y_a[i] > temp_max){
temp_max = y_a[i];
x_max = i;
}
if(y_a[i] < temp_min){
temp_min = y_a[i];
x_min = i;
}
}
else {
if(y_b[i] > temp_max){
temp_max = y_b[i];
x_max = i;
}
if(y_b[i] < temp_min){
temp_min = y_b[i];
x_min = i;
}
}
}//end for
if(_chab[chs].flag == 0){
_marker[chs].max_mkr.power = conv(temp_max) - _power[chs].output_power;
_marker[chs].min_mkr.power = conv(temp_min) - _power[chs].output_power;
}
else if(_chab[chs].flag == 1){
_marker[chs].max_mkr.power = conv(temp_max);
_marker[chs].min_mkr.power = conv(temp_min);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -