发表于:2006/10/16 13:30:00
#0楼
#include<reg51.h>
#include<absacc.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
#define TRUE 1
#define FALSE 0
#define ADC0804 XBYTE[0X9FFF]
#define DAC0832A XBYTE[0X3FFF]
#define DAC0832B XBYTE[0X5FFF]
#define DAC0832C XBYTE[0X7FFF]
#define P2764 CODE[0X1FFF]
#define x DBYTE[0X40]
sbit add0=P3^4;
sbit sub0=P3^5;
sbit A_M=P1^3;
sbit P1_4=P1^4;
sbit chanl=P3^2;
sbit SCL=P1^0;
sbit SAD=P1^1;
sbit P1_2=P1^2;
sbit PSW_5=PSW^5;
sbit PSW_1=PSW^1;
uchar *xp,i;
code uchar TAB[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar outdata, indata ,iout;
uchar kdu;
delay(int t)
{int m;
P1_2=!P1_2;
for(m=0;m<t;m++) //延时子程序,同时喂狗
{;}
}
void display(void) /*循环显示子程序*/
{
uchar j;
for(j=0;j<5;j++)
{
if(i==0||i==5||i==10) //亮绿色自动运行指示灯
SBUF=TAB[*(xp+i+j)]|0x80;
else
SBUF=TAB[*(xp+i+j)]; /*将数据传输到串口寄存器*/
while(TI==0); /*串口发送数据,没发送完,等待*/
TI=0;
}
}
void start_e2rom(void) /*启动 E2ROM */
{
data char j;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SAD=1;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
SAD=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
}
void end_e2rom(void) //关断E2ROM
{
data char j;
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SAD=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
SAD=1;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
}
uchar read_one_e2rom(void)
{
data char i,j;
uchar ret_value,temp;
SAD=1;
temp=0x80;
ret_value=0;
for(i=0;i<8;i++)
{
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
if(SAD==1)
{
ret_value=ret_value+temp;
}
temp=temp>>1;
};
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
return ret_value;
}
void write_one_e2rom(uchar one_ch)
{
data char j;
for(j=0;j<8;j++)
{
SCL=0;
if(one_ch>=0x80)
{
SAD=1;
}
else SAD=0;
SCL=1;
one_ch=one_ch<<1;
};
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
/* while (SAD==1); */
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
}
uchar read_char(uint address)
{
uchar con; /* first control byte to E2ROM */
con=0xa0;
start_e2rom(); /*initition and start E2ROM */
write_one_e2rom(con); /* send control byte write */
write_one_e2rom( (uchar)(address&0x0ff) ); /* send word address */
start_e2rom();
write_one_e2rom(con+1); /* send control byte read*/
con=read_one_e2rom(); /* read one charater */
end_e2rom();
return con;
}
void write_char(uint address,uchar val)
{
uchar con; /* first control byte to E2ROM */
con=0xa0;
start_e2rom(); /*initition and start E2ROM */
write_one_e2rom(con); /* send control byte */
write_one_e2rom( (uchar)(address & 0xff) ); /* send word address */
write_one_e2rom(val); /* write one charater */
end_e2rom();
delay(120);
return;
}
uchar read_string(uint address,uchar len,uchar *pnt)
{
uchar i_r;
for(i_r=0;i_r<len;i_r++)
{
*pnt=read_char(address+i_r); /* read one charater */
pnt=pnt+1;
};
return TRUE;
}
uchar write_string(uint address,uchar len,uchar *pnt)
{
uchar *tmp_pnt; /* temporal pointer */
uchar ret_v; /* read value */
uchar i_w;
tmp_pnt=pnt;
for(i_w=0;i_w<len;i_w++)
{
write_char(address+i_w,*tmp_pnt);
tmp_pnt=tmp_pnt+1;
};
tmp_pnt=pnt;
for(i_w=0;i_w<len;i_w++)
{
ret_v=read_char(address+i_w);
if(ret_v!=*tmp_pnt)
{
return FALSE;
};
tmp_pnt=tmp_pnt+1;
};
return TRUE;
}
void dream (void) // 蒸汽子程序
{
uint temp;
temp=99*(indata-50);
temp=temp/75;
kdu=99-temp;
temp=16*kdu;
temp=temp/99;
iout=temp+4;
temp=200*kdu;
temp=temp/99;
outdata=temp+50;
DAC0832A=outdata;
DAC0832B=50;
DAC0832C=50;
*xp=1;
*(xp+1)=kdu/10;
*(xp+2)=kdu%10;
*(xp+3)=iout/10;
*(xp+4)=iout%10;
*(xp+5)=2;
*(xp+6)=0;
*(xp+7)=0;
*(xp+8)=0;
*(xp+9)=4;
*(xp+10)=3;
*(xp+11)=0;
*(xp+12)=0;
*(xp+13)=0;
*(xp+14)=4;
}
void coolwater1(void) //表冷1子程序
{
uint temp;
temp=99*(indata-150);
temp=temp/50;
kdu=temp;
temp=8*kdu;
temp=temp/99;
iout=temp+4;
temp=100*kdu;
temp=temp/99;
outdata=temp+50;
DAC0832A=50;
DAC0832B=outdata;
DAC0832C=50;
*xp=1;
*(xp+1)=0;
*(xp+2)=0;
*(xp+3)=0;
*(xp+4)=4;
*(xp+5)=2;
*(xp+6)=kdu/10;
*(xp+7)=kdu%10;
*(xp+8)=iout/10;
*(xp+9)=iout%10;
*(xp+10)=3;
*(xp+11)=0;
*(xp+12)=0;
*(xp+13)=0;
*(xp+14)=4;
}
void coolwater2(void) //表冷2子程序
{
uint temp;
temp=99*(indata-200);
temp=temp/50;
kdu=temp;
temp=8*kdu;
temp=temp/99;
iout=temp+4;
temp=100*kdu;
temp=temp/99;
outdata=temp+150;
DAC0832A=50;
DAC0832B=250;
DAC0832C=outdata;
*xp=1;
*(xp+1)=0;
*(xp+2)=0;
*(xp+3)=0;
*(xp+4)=4;
*(xp+5)=2;
*(xp+6)=9;
*(xp+7)=9;
*(xp+8)=1;
*(xp+9)=2;
*(xp+10)=3;
*(xp+11)=kdu/10;
*(xp+12)=kdu%10;
*(xp+13)=iout/10;
*(xp+14)=iout%10;
}
void newflow(void) //新风子程序
{
DAC0832A=50;
DAC0832B=50;
DAC0832C=50;
*xp=1;
*(xp+1)=0;
*(xp+2)=0;
*(xp+3)=0;
*(xp+4)=4;
*(xp+5)=2;
*(xp+6)=0;
*(xp+7)=0;
*(xp+8)=0;
*(xp+9)=4;
*(xp+10)=3;
*(xp+11)=0;
*(xp+12)=0;
*(xp+13)=0;
*(xp+14)=4;
}
void sdadd(void)interrupt 1 //定义一个中断服务开度加子程序
{
if(kdu==99); //判断开度等于99,不增加
else
kdu+=1; //开度值加一
sd_display(); //手动状态显示
}
void sdsub(void)interrupt 3 //定义一个中断服务开度减子程序
{
if(kdu==0);
else
kdu-=1; // 开度减一
sd_display();
}
void sdchanl(void)interrupt 0 //定义一个中断服务通道转换子程序
{
uchar i;
if(i==10)
i=0; // 通道循环显示
else
i+=5;
sd_display();
}
sd_display() //手动状态显示子程序
{
uint temp;
uchar j;
swich(i)
{
case 0:
{
*xp=1; 通道1 蒸汽显示
temp=16*kdu;
temp=temp/99;
iout=temp+4;
temp=200*kdu;
temp=temp/99;
outdata=temp+50;
*(xp+1)=kdu/10;
*(xp+2)=kdu%10;
*(xp+3)=iout/10
*(xp+4)=iout%10
DAC0832A=outdata;
DAC0832B=50;
DAC0832C=50;
}
break;
case5:
{
*(xp+5)=2; 通道2 表冷1显示
temp=8*kdu;
temp=temp/99;
iout=temp+4;
temp=100*kdu;
temp=temp/99;
outdata=temp+50;
*(xp+6)=kdu/10;
*(xp+7)=kdu%10;
*(xp+8)=iout/10
*(xp+9)=iout%10
DAC0832A=50;
DAC0832B=outdata;
DAC0832C=50;
}
break;
case 10:
{
*(xp+10)=3; 通道3,表冷2显示
temp=8*kdu;
temp=temp/99;
iout=temp+12;
temp=100*kdu;
temp=temp/99;
outdata=temp+150
*(xp+11)=kdu/10;
*(xp+12)=kdu%10;
*(xp+13)=iout/10
*(xp+14)=iout%10
DAC0832A=50;
DAC0832B=250;
DAC0832C=outdata;
}
break;
default:break;
}
for(j=0;j<5;j++) //传送该通道5个字节
{
if(((i+j)==1)||((i+j)==6)||((i+j)==11)) //亮红色手动指示灯
SBUF=(TAB[*(xp+i+j)]|0x80);
else
SBUF=TAB[*(xp+i+j)];
while(TI==0);
TI=0;
}
}
main()
{
uchar m,j;
uint temp;
TMOD=0x66; //T0,T1采用计数方式2
SCON=0x00; //串口采用同步移位寄存器方式
IT0=1; //外部中断采用边沿触发方式
EA=0; //关总中断开关
EX0=1; //外部中断0允许中断
ET0=1; //定时器/计数器0中断允许
ET1=1; //定时器/计数器1中断允许
TL0=0xff; //T0送初值
TH0=0xff;
TL1=0xff; //T1送初值
TH1=0xff;
i=0;
while(PSW_5==0) //如果掉电恢复
{
read_string(0x01,16,*xp); //读一组数据
indata=*(xp+15);
PSW_5=1;
if(indata>=50 &&indata<=125)
{
temp=99*(indata-50);
temp=temp/75;
kdu=99-temp;
temp=200*kdu;
temp=temp/99;
outdata=50+temp;
DAC0832A=outdata;
DAC0832B=50;
DAC0832C=50;
for(j=0;j<5;j++)
{
SBUF=TAB[*(xp+j)];
while(TI==0);
TI=0;
}
}
if(indata>125&&indata<=150)
{
DAC0832A=50;
DAC0832B=50;
DAC0832C=50;
for(j=0;j<5;j++)
{
SBUF=TAB[0];
while(TI==0);
TI=0;
}
}
if(indata>150&&indata<=200)
{
temp=99*(indata-150);
temp=temp/50;
kdu=temp;
temp=100*kdu;
temp=temp/99;
outdata=temp+50;
DAC0832A=50;
DAC0832B=outdata;
DAC0832C=50;
for(j=5;j<10;j++)
{
SBUF=TAB[*(xp+j)];
while(TI==0);
TI=0;
}
}
if(indata>200&&indata<=250)
{
temp=99*(indata-200);
temp=temp/50;
kdu=temp;
temp=100*kdu;
temp=temp/99;
outdata=temp+150;
DAC0832A=50;
DAC0832B=250;
DAC0832C=outdata;
for(j=10;j<15;j++)
{
SBUF=TAB[*(xp+j)];
while(TI==0);
TI=0;
}
}
for(m=0;m>10;m++) //延时10秒并喂狗,之后进入自动程序
delay(12000);
}
while(1)
{
while(1) //自动程序
{
for(i=0;i<11;i+5)
{
ADC0804= indata; //启动ad转换
while(P1_4==1); //查询转换是否完成
indata=ADC0804; //转换完成,读入数据
*(xp+15)=indata; //采样数据送ox4f单元
if(indata>200&&indata<=250)
coolwater2();
if(indata>150&&indata<=200)
coolwater1();
if(indata>125&&indata<=150)
newflow();
if(indata>=50&&indata<=125)
dream();
if(indata<50||indata>250) //如果超出范围,重新读。
break;
display(); //显示一组5个数据
delay(12000); //循环1秒扫描一次外部4~20ma信号,并循环显示各个通道
if(A_M==0) break; //A_M 按下跳出循环,当前通道自动进入手动
}
if(A_M==0) break; //A_M 按下跳出自动进入手动 ,显示当前通道数据
}
if(i==15)
i=10; //如果i>11,手动后显示通道3的数据
delay(5000); //消抖动
while(A_M==0);
EA=1; //开中断
for(j=0;j<5;j++) //传送该通道5个字节
{
if((j==1)||(j==6)||(j==11)) //亮红色手动指示灯
SBUF=(TAB[*(xp+i+j)]|0x80);
else
SBUF=TAB[*(xp+i+j)];
while(TI==0);
TI=0;
}
while(1) //手动程序
{
delay(12000); //都没按下,喂狗
if(A_M==0) //如果按下手动自动切换,则写入数据到e2rom
break;
}
EA=0;
write_string(0x01,16,*xp) ; /*将数据写到e2rom片内01H单元*/
delay(5000);
while(A_M==0); //写完数据,返回自动程序
}
}
请高手看看,我的email :gwei8339@163.com
#include<absacc.h>
#include<math.h>
#define uint unsigned int
#define uchar unsigned char
#define TRUE 1
#define FALSE 0
#define ADC0804 XBYTE[0X9FFF]
#define DAC0832A XBYTE[0X3FFF]
#define DAC0832B XBYTE[0X5FFF]
#define DAC0832C XBYTE[0X7FFF]
#define P2764 CODE[0X1FFF]
#define x DBYTE[0X40]
sbit add0=P3^4;
sbit sub0=P3^5;
sbit A_M=P1^3;
sbit P1_4=P1^4;
sbit chanl=P3^2;
sbit SCL=P1^0;
sbit SAD=P1^1;
sbit P1_2=P1^2;
sbit PSW_5=PSW^5;
sbit PSW_1=PSW^1;
uchar *xp,i;
code uchar TAB[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar outdata, indata ,iout;
uchar kdu;
delay(int t)
{int m;
P1_2=!P1_2;
for(m=0;m<t;m++) //延时子程序,同时喂狗
{;}
}
void display(void) /*循环显示子程序*/
{
uchar j;
for(j=0;j<5;j++)
{
if(i==0||i==5||i==10) //亮绿色自动运行指示灯
SBUF=TAB[*(xp+i+j)]|0x80;
else
SBUF=TAB[*(xp+i+j)]; /*将数据传输到串口寄存器*/
while(TI==0); /*串口发送数据,没发送完,等待*/
TI=0;
}
}
void start_e2rom(void) /*启动 E2ROM */
{
data char j;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SAD=1;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
SAD=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
}
void end_e2rom(void) //关断E2ROM
{
data char j;
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SAD=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
SAD=1;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
}
uchar read_one_e2rom(void)
{
data char i,j;
uchar ret_value,temp;
SAD=1;
temp=0x80;
ret_value=0;
for(i=0;i<8;i++)
{
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
if(SAD==1)
{
ret_value=ret_value+temp;
}
temp=temp>>1;
};
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
return ret_value;
}
void write_one_e2rom(uchar one_ch)
{
data char j;
for(j=0;j<8;j++)
{
SCL=0;
if(one_ch>=0x80)
{
SAD=1;
}
else SAD=0;
SCL=1;
one_ch=one_ch<<1;
};
for(j=1;j<10;j++) {j=j+j;};
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
SCL=1;
for(j=1;j<10;j++) {j=j+j;};
/* while (SAD==1); */
SCL=0;
for(j=1;j<10;j++) {j=j+j;};
}
uchar read_char(uint address)
{
uchar con; /* first control byte to E2ROM */
con=0xa0;
start_e2rom(); /*initition and start E2ROM */
write_one_e2rom(con); /* send control byte write */
write_one_e2rom( (uchar)(address&0x0ff) ); /* send word address */
start_e2rom();
write_one_e2rom(con+1); /* send control byte read*/
con=read_one_e2rom(); /* read one charater */
end_e2rom();
return con;
}
void write_char(uint address,uchar val)
{
uchar con; /* first control byte to E2ROM */
con=0xa0;
start_e2rom(); /*initition and start E2ROM */
write_one_e2rom(con); /* send control byte */
write_one_e2rom( (uchar)(address & 0xff) ); /* send word address */
write_one_e2rom(val); /* write one charater */
end_e2rom();
delay(120);
return;
}
uchar read_string(uint address,uchar len,uchar *pnt)
{
uchar i_r;
for(i_r=0;i_r<len;i_r++)
{
*pnt=read_char(address+i_r); /* read one charater */
pnt=pnt+1;
};
return TRUE;
}
uchar write_string(uint address,uchar len,uchar *pnt)
{
uchar *tmp_pnt; /* temporal pointer */
uchar ret_v; /* read value */
uchar i_w;
tmp_pnt=pnt;
for(i_w=0;i_w<len;i_w++)
{
write_char(address+i_w,*tmp_pnt);
tmp_pnt=tmp_pnt+1;
};
tmp_pnt=pnt;
for(i_w=0;i_w<len;i_w++)
{
ret_v=read_char(address+i_w);
if(ret_v!=*tmp_pnt)
{
return FALSE;
};
tmp_pnt=tmp_pnt+1;
};
return TRUE;
}
void dream (void) // 蒸汽子程序
{
uint temp;
temp=99*(indata-50);
temp=temp/75;
kdu=99-temp;
temp=16*kdu;
temp=temp/99;
iout=temp+4;
temp=200*kdu;
temp=temp/99;
outdata=temp+50;
DAC0832A=outdata;
DAC0832B=50;
DAC0832C=50;
*xp=1;
*(xp+1)=kdu/10;
*(xp+2)=kdu%10;
*(xp+3)=iout/10;
*(xp+4)=iout%10;
*(xp+5)=2;
*(xp+6)=0;
*(xp+7)=0;
*(xp+8)=0;
*(xp+9)=4;
*(xp+10)=3;
*(xp+11)=0;
*(xp+12)=0;
*(xp+13)=0;
*(xp+14)=4;
}
void coolwater1(void) //表冷1子程序
{
uint temp;
temp=99*(indata-150);
temp=temp/50;
kdu=temp;
temp=8*kdu;
temp=temp/99;
iout=temp+4;
temp=100*kdu;
temp=temp/99;
outdata=temp+50;
DAC0832A=50;
DAC0832B=outdata;
DAC0832C=50;
*xp=1;
*(xp+1)=0;
*(xp+2)=0;
*(xp+3)=0;
*(xp+4)=4;
*(xp+5)=2;
*(xp+6)=kdu/10;
*(xp+7)=kdu%10;
*(xp+8)=iout/10;
*(xp+9)=iout%10;
*(xp+10)=3;
*(xp+11)=0;
*(xp+12)=0;
*(xp+13)=0;
*(xp+14)=4;
}
void coolwater2(void) //表冷2子程序
{
uint temp;
temp=99*(indata-200);
temp=temp/50;
kdu=temp;
temp=8*kdu;
temp=temp/99;
iout=temp+4;
temp=100*kdu;
temp=temp/99;
outdata=temp+150;
DAC0832A=50;
DAC0832B=250;
DAC0832C=outdata;
*xp=1;
*(xp+1)=0;
*(xp+2)=0;
*(xp+3)=0;
*(xp+4)=4;
*(xp+5)=2;
*(xp+6)=9;
*(xp+7)=9;
*(xp+8)=1;
*(xp+9)=2;
*(xp+10)=3;
*(xp+11)=kdu/10;
*(xp+12)=kdu%10;
*(xp+13)=iout/10;
*(xp+14)=iout%10;
}
void newflow(void) //新风子程序
{
DAC0832A=50;
DAC0832B=50;
DAC0832C=50;
*xp=1;
*(xp+1)=0;
*(xp+2)=0;
*(xp+3)=0;
*(xp+4)=4;
*(xp+5)=2;
*(xp+6)=0;
*(xp+7)=0;
*(xp+8)=0;
*(xp+9)=4;
*(xp+10)=3;
*(xp+11)=0;
*(xp+12)=0;
*(xp+13)=0;
*(xp+14)=4;
}
void sdadd(void)interrupt 1 //定义一个中断服务开度加子程序
{
if(kdu==99); //判断开度等于99,不增加
else
kdu+=1; //开度值加一
sd_display(); //手动状态显示
}
void sdsub(void)interrupt 3 //定义一个中断服务开度减子程序
{
if(kdu==0);
else
kdu-=1; // 开度减一
sd_display();
}
void sdchanl(void)interrupt 0 //定义一个中断服务通道转换子程序
{
uchar i;
if(i==10)
i=0; // 通道循环显示
else
i+=5;
sd_display();
}
sd_display() //手动状态显示子程序
{
uint temp;
uchar j;
swich(i)
{
case 0:
{
*xp=1; 通道1 蒸汽显示
temp=16*kdu;
temp=temp/99;
iout=temp+4;
temp=200*kdu;
temp=temp/99;
outdata=temp+50;
*(xp+1)=kdu/10;
*(xp+2)=kdu%10;
*(xp+3)=iout/10
*(xp+4)=iout%10
DAC0832A=outdata;
DAC0832B=50;
DAC0832C=50;
}
break;
case5:
{
*(xp+5)=2; 通道2 表冷1显示
temp=8*kdu;
temp=temp/99;
iout=temp+4;
temp=100*kdu;
temp=temp/99;
outdata=temp+50;
*(xp+6)=kdu/10;
*(xp+7)=kdu%10;
*(xp+8)=iout/10
*(xp+9)=iout%10
DAC0832A=50;
DAC0832B=outdata;
DAC0832C=50;
}
break;
case 10:
{
*(xp+10)=3; 通道3,表冷2显示
temp=8*kdu;
temp=temp/99;
iout=temp+12;
temp=100*kdu;
temp=temp/99;
outdata=temp+150
*(xp+11)=kdu/10;
*(xp+12)=kdu%10;
*(xp+13)=iout/10
*(xp+14)=iout%10
DAC0832A=50;
DAC0832B=250;
DAC0832C=outdata;
}
break;
default:break;
}
for(j=0;j<5;j++) //传送该通道5个字节
{
if(((i+j)==1)||((i+j)==6)||((i+j)==11)) //亮红色手动指示灯
SBUF=(TAB[*(xp+i+j)]|0x80);
else
SBUF=TAB[*(xp+i+j)];
while(TI==0);
TI=0;
}
}
main()
{
uchar m,j;
uint temp;
TMOD=0x66; //T0,T1采用计数方式2
SCON=0x00; //串口采用同步移位寄存器方式
IT0=1; //外部中断采用边沿触发方式
EA=0; //关总中断开关
EX0=1; //外部中断0允许中断
ET0=1; //定时器/计数器0中断允许
ET1=1; //定时器/计数器1中断允许
TL0=0xff; //T0送初值
TH0=0xff;
TL1=0xff; //T1送初值
TH1=0xff;
i=0;
while(PSW_5==0) //如果掉电恢复
{
read_string(0x01,16,*xp); //读一组数据
indata=*(xp+15);
PSW_5=1;
if(indata>=50 &&indata<=125)
{
temp=99*(indata-50);
temp=temp/75;
kdu=99-temp;
temp=200*kdu;
temp=temp/99;
outdata=50+temp;
DAC0832A=outdata;
DAC0832B=50;
DAC0832C=50;
for(j=0;j<5;j++)
{
SBUF=TAB[*(xp+j)];
while(TI==0);
TI=0;
}
}
if(indata>125&&indata<=150)
{
DAC0832A=50;
DAC0832B=50;
DAC0832C=50;
for(j=0;j<5;j++)
{
SBUF=TAB[0];
while(TI==0);
TI=0;
}
}
if(indata>150&&indata<=200)
{
temp=99*(indata-150);
temp=temp/50;
kdu=temp;
temp=100*kdu;
temp=temp/99;
outdata=temp+50;
DAC0832A=50;
DAC0832B=outdata;
DAC0832C=50;
for(j=5;j<10;j++)
{
SBUF=TAB[*(xp+j)];
while(TI==0);
TI=0;
}
}
if(indata>200&&indata<=250)
{
temp=99*(indata-200);
temp=temp/50;
kdu=temp;
temp=100*kdu;
temp=temp/99;
outdata=temp+150;
DAC0832A=50;
DAC0832B=250;
DAC0832C=outdata;
for(j=10;j<15;j++)
{
SBUF=TAB[*(xp+j)];
while(TI==0);
TI=0;
}
}
for(m=0;m>10;m++) //延时10秒并喂狗,之后进入自动程序
delay(12000);
}
while(1)
{
while(1) //自动程序
{
for(i=0;i<11;i+5)
{
ADC0804= indata; //启动ad转换
while(P1_4==1); //查询转换是否完成
indata=ADC0804; //转换完成,读入数据
*(xp+15)=indata; //采样数据送ox4f单元
if(indata>200&&indata<=250)
coolwater2();
if(indata>150&&indata<=200)
coolwater1();
if(indata>125&&indata<=150)
newflow();
if(indata>=50&&indata<=125)
dream();
if(indata<50||indata>250) //如果超出范围,重新读。
break;
display(); //显示一组5个数据
delay(12000); //循环1秒扫描一次外部4~20ma信号,并循环显示各个通道
if(A_M==0) break; //A_M 按下跳出循环,当前通道自动进入手动
}
if(A_M==0) break; //A_M 按下跳出自动进入手动 ,显示当前通道数据
}
if(i==15)
i=10; //如果i>11,手动后显示通道3的数据
delay(5000); //消抖动
while(A_M==0);
EA=1; //开中断
for(j=0;j<5;j++) //传送该通道5个字节
{
if((j==1)||(j==6)||(j==11)) //亮红色手动指示灯
SBUF=(TAB[*(xp+i+j)]|0x80);
else
SBUF=TAB[*(xp+i+j)];
while(TI==0);
TI=0;
}
while(1) //手动程序
{
delay(12000); //都没按下,喂狗
if(A_M==0) //如果按下手动自动切换,则写入数据到e2rom
break;
}
EA=0;
write_string(0x01,16,*xp) ; /*将数据写到e2rom片内01H单元*/
delay(5000);
while(A_M==0); //写完数据,返回自动程序
}
}
请高手看看,我的email :gwei8339@163.com