📄 ytr_ycr._c
字号:
#include"lcd1602.h"
#include"eeprom.h"
#include <io8515v.h>
#define Uchar unsigned char
#define Uint unsigned int
Uint read2543(Uchar);
void bcdchange(Uint);
void delay(Uint);
void IGT_YCR(void);
void IGT_YTR(void);
void YTR_1(void);
void YTR_2(void);
void YTR_3(void);
void YTR_4(void);
void KeyCook(void);
void CHange_XY(Uchar);
void YTRTest(void);
void YTR_LCD(Uchar,Uchar);
void KEY_SF(void);
void delay200ms(void);
void YCR_IGTMAX(Uchar,Uchar);
void (*Rset)(void);
Uchar LCDBUF[3];
Uchar XYBUF[4];
Uchar i1,YCR_YTR,CountN,CountX,CT,XY_Show,YCR,YTR;
Uchar IGT1,IGT2,IGT3,IGT4,IGFlash,UN,UNC,IGTMAX,IGTMIN,VGTFL,IGTF,SoftWare;
Uint Count;
void main(void)
{
Uint igtm;
LcdReset();
delay(4);
DDRD|=(1<<PD2)|(1<<PD3)|(1<<PD4);
DDRB|=(1<<PB7)|(1<<PB6)|(1<<PB4);
DDRB&=~(1<<PB5);
DDRA&=~((1<<PA1)|(1<<PA3)|(1<<PA4));
PORTB|=1<<PB5;
PORTD&=~((1<<PD4));
YCR_YTR=1;
XYBUF[0]=1;
XYBUF[1]=1;
XYBUF[2]=1;
XYBUF[3]=1;
Count=0;
CountN=0;
CountX=0;
CT=0;
XY_Show=0;
YCR=0;
YTR=1;
IGT1=1;
IGTF=0;
SoftWare=0;
Rset=0;
/*EEPROM_WRITE(0x21,YCR);
EEPROM_WRITE(0x22,YTR);
EEPROM_WRITE(0x11,YCR);
EEPROM_WRITE(0x12,YCR);
EEPROM_WRITE(0x13,YCR);
EEPROM_WRITE(0x14,YCR);
EEPROM_WRITE(0x34,YCR);*/
EEPROM_READ(0x21,YCR);
EEPROM_READ(0x22,YTR);
EEPROM_READ(0x11,IGT1);
EEPROM_READ(0x12,IGT2);
EEPROM_READ(0x13,IGT3);
EEPROM_READ(0x14,IGT4);
EEPROM_READ(0x33,IGTMAX);
EEPROM_READ(0x34,VGTFL);
EEPROM_READ(0x43,IGTMIN);
while(1)
{
delay(4);
//YCR=1;
KeyCook();
if(YCR==1)
{
PORTD|=1<<PD4;
CHange_XY(1);
YTRTest();
}
if(YTR==1)
{
PORTD&=~(1<<PD4);
if((IGT1==1)&&(YTR==1))
{
CHange_XY(1);
PORTD&=~(1<<PD4);
XY_Show=1;
Delay5Ms();
YTRTest();
ePutstr(0,0,"IG1 ");
if(YTR==1)
{
YTR_LCD(4,0);
if((IGT2==0)&&(IGT4==0))
{
ePutstr(10,0,"mA");
}
}
}
if((IGT2==1)&&(YTR==1))
{
CHange_XY(2);
PORTD&=~(1<<PD4);
Delay5Ms();
XY_Show=2;
YTRTest();
if(YTR==1)
{
ePutstr(9,0,"I2");
YTR_LCD(12,0);
}
}
if((IGT3==1)&&(YTR==1))
{
CHange_XY(3);
PORTD&=~(1<<PD4);
Delay5Ms();
XY_Show=3;
YTRTest();
if(YTR==1)
{
ePutstr(0,1,"IG3");
YTR_LCD(4,1);
if((IGT2==0)&&(IGT4==0))
{
ePutstr(10,1,"mA");
}
}
}
if((IGT4==1)&&(YTR==1))
{
CHange_XY(4);
PORTD&=~(1<<PD4);
Delay5Ms();
XY_Show=4;
YTRTest();
if(YTR==1)
{
ePutstr(9,1,"I4");
YTR_LCD(12,1);
}
}
}
}
}
Uint read2543(Uchar CON_WORD)
{
Uint ad=0;
Uint i;
DDRB|=(1<<PB3)|(1<<PB0)|(1<<PB1);
DDRB&=~(1<<PB2);
PORTB&=~(1<<PB0);
PORTB&=~(1<<PB3);
for(i=0;i<12;i++)
{
if(PINB&(1<<PB2)) ad|=0x01;
if(CON_WORD&0X80) PORTB|=1<<PB1;
else PORTB&=~(1<<PB1);
PORTB|=1<<PB0;
delay(3);
PORTB&=~(1<<PB0);
delay(3);
CON_WORD<<=1;
ad<<=1;
}
PORTB|=1<<PB3;
ad>>=1;
return(ad);
}
void delay(Uint N)
{
Uint i;
for(i=0;i<N;i++);
}
void bcdchange(Uint bcd)
{
float temp;
Uint temp1;
Uchar i,temp2;
temp=((float)bcd)/4096;
temp1=(Uint)(temp*500);
for(i=0;i<3;i++)
{
temp2=temp1%10;
LCDBUF[i]=temp2|0x30;
temp1=temp1/10;
}
}
void IGT_YCR(void)
{
Uint CTemp1,CTemp2,CTemp,CTem;
Uchar i,FlaYCR;
double CTemp3;
FlaYCR=0;
read2543(0x0);
CTemp1=read2543(0x0);
read2543(0x10);
CTemp2=read2543(0x10);
if(VGTFL==1) CTem=CTemp2;
CTemp=CTemp1-CTemp2;
CTemp3=((double)CTemp)/4096;
CTemp3=(CTemp3*5)/14;
CTemp2=(Uint)(CTemp3*1000);
if((CTemp2<=IGTMAX)&&(CTemp2>=IGTMIN)) FlaYCR=1;
if(CountX<=1)
{
for(i=0;i<3;i++)
{
CTemp1=CTemp2%10;
LCDBUF[i]=CTemp1|0x30;
CTemp2=CTemp2/10;
}
ePutstr(0,0,"IGT:");
if(LCDBUF[2]==0x30)
{
ePutstr(5,0,"");
}
else
{
DispOneChar(5,0,LCDBUF[2]);
}
DispOneChar(6,0,LCDBUF[1]);
DispOneChar(7,0,LCDBUF[0]);
ePutstr(8,0,"uA");
if(FlaYCR==1)
{
ePutstr(11,0,"PASS");
}
else
{
ePutstr(11,0,"OVER");
}
if(VGTFL==1)
{
bcdchange(CTem);
ePutstr(0,1,"VGT ");
DispOneChar(6,1,LCDBUF[2]);
DispOneChar(7,1,0x2e);
DispOneChar(8,1,LCDBUF[1]);
DispOneChar(9,1,LCDBUF[0]);
ePutstr(10,1,"V");
}
}
}
void IGT_YTR(void)
{
Uint CTemp1,CTemp2,CTemp;
Uchar i;
float CTemp3;
read2543(0x0);
CTemp1=read2543(0x0);
read2543(0x10);
CTemp2=read2543(0x10);
CTemp=CTemp1-CTemp2;
CTemp3=((float)CTemp)/4096;
CTemp3=(CTemp3*5)/140;
CTemp3=CTemp3*1000;
if(CTemp3<1)
{
CTemp2=(Uint)(CTemp3*1000);
i1=1;
}
else if(CTemp3<10)
{
CTemp2=(Uint)(CTemp3*100);
i1=2;
}
else if(CTemp3<100)
{
CTemp2=(Uint)(CTemp3*10);
i1=3;
}
else
{
i1=0;
}
for(i=0;i<3;i++)
{
CTemp1=CTemp2%10;
LCDBUF[i]=CTemp1|0x30;
CTemp2=CTemp2/10;
}
}
void YTR_LCD(Uchar x1,Uchar y1)
{
if(i1==1)
{
DispOneChar(x1,y1,0x30);
DispOneChar(x1+1,y1,0x2e);
DispOneChar(x1+2,y1,LCDBUF[2]);
DispOneChar(x1+3,y1,LCDBUF[1]);
}
else if(i1==2)
{
DispOneChar(x1,y1,LCDBUF[2]);
DispOneChar(x1+1,y1,0x2e);
DispOneChar(x1+2,y1,LCDBUF[1]);
DispOneChar(x1+3,y1,LCDBUF[0]);
}
else if(i1==3)
{
DispOneChar(x1,y1,LCDBUF[2]);
DispOneChar(x1+1,y1,LCDBUF[1]);
DispOneChar(x1+2,y1,0x2e);
DispOneChar(x1+3,y1,LCDBUF[0]);
}
else
{
ePutstr(10,1,"mA1");
}
}
void YTR_1(void)
{
PORTD|=(1<<PD2)|(1<<PD3);
}
void YTR_2(void)
{
PORTD|=1<<PD2;
PORTD&=~(1<<PD3);
}
void YTR_3(void)
{
PORTD&=~((1<<PD2)|(1<<PD3));
}
void YTR_4(void)
{
PORTD|=1<<PD3;
PORTD&=~(1<<PD2);
}
void CHange_XY(Uchar XY)
{
switch(XY)
{
case 1: YTR_1(); break;
case 2: YTR_2(); break;
case 3: YTR_3(); break;
case 4: YTR_4(); break;
}
}
void YTRTest(void)
{
delay(4);
ll: PORTB&=~((1<<PB7)|(1<<PB6)|(1<<PB4));//fd
delay200ms();
Delay5Ms();
Delay5Ms();
PORTB|=((1<<PB7)|(1<<PB6)|(1<<PB4));//cd
while(PINB&(1<<PB5))
{
Count=Count+1;
if(Count==500)
{
CountN=CountN+1;
Count=0;
}
if(CountN==12)
{
CountN=0;
Count=0;
CountX=0;
CT=1;
PORTD|=((1<<PD2)|(1<<PD3));
KeyCook();
if(YTR==1)
{
ePutstr(0,0,"INSERT YTR ");
PORTD&=~(1<<PD4);
UN=IGT1+IGT2+IGT3+IGT4;
}
if(YCR==1)
{
ePutstr(0,0,"INSERT YCR ");
PORTD|=1<<PD4;
CHange_XY(1);
UN=2;
}
goto ll;
}
}
PORTB&=~((1<<PB7)|(1<<PB6));//ksad
if(CT==1)
{
CT=0;
if(YTR==1)
{
CHange_XY(XY_Show);
}
if(YCR==1)
{
CHange_XY(1);
}
LcdWriteCommand( 0x01, 1);
goto ll;
}
if(YTR==1)
{
IGT_YTR();
}
if(YCR==1)
{
IGT_YCR();
}
CountN=0;
Count=0;
if(YTR==1)
{
UN=IGT1+IGT2+IGT3+IGT4;
}
if(YCR==1)
{
UN=2;
}
if(CountX==UN) goto ll;
CountX=CountX+1;
KK: delay(200);
}
Uchar KeyScan(void)
{
if(!(PINA&(1<<PA1)))
{
Delay5Ms();
if(!(PINA&(1<<PA1)))
{
return 1;
}
}
if(!(PINA&(1<<PA2)))
{
Delay5Ms();
if(!(PINA&(1<<PA2)))
{
return 2;
}
}
if(!(PINA&(1<<PA3)))
{
Delay5Ms();
if(!(PINA&(1<<PA3)))
{
return 3;
}
}
if(!(PINA&(1<<PA4)))
{
Delay5Ms();
if(!(PINA&(1<<PA4)))
{
return 4;
}
}
return 0;
}
void KeyCook(void)
{
Uchar Keyn;
Keyn=KeyScan();
switch(Keyn)
{
case 1:
{
LcdReset();
ePutstr(0,0,"Choose YCR");
DispOneChar(12,0,YCR|0x30);
ePutstr(0,1," YTR");
DispOneChar(12,1,YTR|0x30);
Disp_XY(13,0);
LcdWriteCommand(0x0F, 1);
KEY_SF();
while(!(KeyScan()==1))
{
if(KeyScan()==3)
{
if(YCR==1)
{
YCR=0;
YTR=1;
SoftWare=1;
EEPROM_WRITE(0x21,YCR);
EEPROM_WRITE(0x22,YTR);
}
else
{
YCR=1;
YTR=0;
EEPROM_WRITE(0x21,YCR);
EEPROM_WRITE(0x22,YTR);
}
ePutstr(0,0,"Choose YCR");
DispOneChar(12,0,YCR|0x30);
ePutstr(0,1," YTR");
DispOneChar(12,1,YTR|0x30);
KEY_SF();
}
}
if(YCR==1)
{
LcdReset();
ePutstr(0,0,"IGT MIN");
YCR_IGTMAX(IGTMIN,0);
ePutstr(4,1,"MAX");
YCR_IGTMAX(IGTMAX,1);
Disp_XY(11,0);
LcdWriteCommand(0x0F, 1);
KEY_SF();
while(!(KeyScan()==1))
{
if(KeyScan()==4)
{
IGTF^=0x01;
if(IGTF==1) Disp_XY(11,0);
else Disp_XY(11,1);
KEY_SF();
}
if(KeyScan()==3)
{
if(IGTF==1)
{
IGTMIN=IGTMIN+1;
if(IGTMIN>IGTMAX) IGTMIN=IGTMAX-1;
YCR_IGTMAX(IGTMIN,0);
}
if(IGTF==0)
{
IGTMAX=IGTMAX+1;
if(IGTMAX<IGTMIN) IGTMAX=IGTMIN+1;
YCR_IGTMAX(IGTMAX,1);
}
}
if(KeyScan()==2)
{
if(IGTF==1)
{
IGTMIN=IGTMIN-1;
if(IGTMIN>IGTMAX) IGTMIN=IGTMAX-1;
YCR_IGTMAX(IGTMIN,0);
}
if(IGTF==0)
{
IGTMAX=IGTMAX-1;
if(IGTMAX<IGTMIN) IGTMAX=IGTMIN+1;
YCR_IGTMAX(IGTMAX,1);
}
}
Delay400Ms();
}
EEPROM_WRITE(0x33,IGTMAX);
EEPROM_WRITE(0x43,IGTMIN);
LcdReset();
ePutstr(0,0,"YCR VGT ");
DispOneChar(8,0,VGTFL|0x30);
Disp_XY(9,0);
LcdWriteCommand(0x0F, 1);
KEY_SF();
while(!(KeyScan()==1))
{
if(KeyScan()==3)
{
VGTFL^=0x01;
DispOneChar(8,0,VGTFL|0x30);
KEY_SF();
}
}
EEPROM_WRITE(0x34,VGTFL);
}
if(YTR==1)
{
LcdReset();
ePutstr(0,0,"IGT1 ");
DispOneChar(5,0,IGT1|0x30);
ePutstr(8,0,"IGT2 ");
DispOneChar(13,0,IGT2|0x30);
ePutstr(0,1,"IGT3 ");
DispOneChar(5,1,IGT3|0x30);
ePutstr(8,1,"IGT4 ");
DispOneChar(13,1,IGT4|0x30);
IGFlash=1;
LcdWriteCommand( 0x0F, 1);
Disp_XY(6,0);
KEY_SF();
while(!(KeyScan()==1))
{
if(KeyScan()==4)
{
IGFlash=IGFlash+1;
if(IGFlash==5) IGFlash=1;
if(IGFlash==1) Disp_XY(6,0);
else if(IGFlash==2) Disp_XY(14,0);
else if(IGFlash==3) Disp_XY(6,1);
else if(IGFlash==4) Disp_XY(14,1);
LcdWriteCommand(0x0F, 1);
KEY_SF();
}
if(KeyScan()==3)
{
SoftWare=1;
switch(IGFlash)
{
case 1:
{
if(IGT1==1) IGT1=0;
else IGT1=1;
EEPROM_WRITE(0x11,IGT1);
DispOneChar(5,0,IGT1|0x30);
}
break;
case 2:
{
if(IGT2==1) IGT2=0;
else IGT2=1;
EEPROM_WRITE(0x12,IGT2);
DispOneChar(13,0,IGT2|0x30);
}
break;
case 3:
{
if(IGT3==1) IGT3=0;
else IGT3=1;
EEPROM_WRITE(0x13,IGT3);
DispOneChar(5,1,IGT3|0x30);
}
break;
case 4:
{
if(IGT4==1) IGT4=0;
else IGT4=1;
EEPROM_WRITE(0x14,IGT4);
DispOneChar(13,1,IGT4|0x30);
}
break;
}
KEY_SF();
}
}
}
}
LcdReset();
}
Delay400Ms();
Delay400Ms();
if(SoftWare==1)
{
SoftWare=0;
Rset();
}
}
void KEY_SF(void)
{
while((KeyScan()==1)|(KeyScan()==3)|(KeyScan()==4)|(KeyScan()==2));
}
void delay200ms(void)
{
Uchar iu;
for(iu=0;iu<=10;iu++)
{
Delay5Ms();
}
}
void YCR_IGTMAX(Uchar IGTTEMP,Uchar hxy)
{
Uchar EYN,i;
for(i=0;i<3;i++)
{
EYN=IGTTEMP%10;
LCDBUF[i]=EYN|0x30;
IGTTEMP=IGTTEMP/10;
}
if(LCDBUF[2]==0x30)
{
ePutstr(8,hxy," ");
}
else DispOneChar(8,hxy,LCDBUF[2]);
DispOneChar(9,hxy,LCDBUF[1]);
DispOneChar(10,hxy,LCDBUF[0]);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -