⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wt1.c

📁 测试手机面板安装是否正确
💻 C
字号:
#include <AT89X51.h>
#include <wt1.h>
void main(void)
{
//	bit oldLAST=0;
//	bit oldNEXT=0;
//	unsigned char b;
	unsigned char n,d,dd;
	bit st=0;
	ln=0;
	INPORT=P3;
	Initial();
	Initial8255();
	Delay10ms(1);
/*	for(n=0;n<4;n++)
	{
		PBYTE[CS3]=0xff;
		Delay10ms(50);
		PBYTE[CS3]=0;
		Delay10ms(50);
	}*/
	while(1)
	{

		ln=0;
		while(!CN1);Delay10ms(1);
		while(!CN1);Delay10ms(1);
		while(!CN1);Delay10ms(1);
		while(CN1);Delay10ms(1);
		while(CN1);Delay10ms(1);
		while(CN1);
		while(1)
		{
			PIO1=PIO2=PIO3=PIO4=PIO5=PIO6=0;
			Initial8255();
			//Shortcut test 
			PBYTE[CS3]=0x20;   //Light first test step
			Delay10ms(10);
			PIO1=0xff;
			PIO2=0xdf;
			PIO3=0xff;
			PIO4=0xf7;
			PIO5=0x36;
			PIO6=0x8c;
			PU2=0x3f;
			PU1=0x3f;
			ShortError=0;
			while(1)
			{
				if(PIO1!=(dd=PBYTE[CS4])) {ShortError=1;break;}
				if(PIO2!=PBYTE[CS4+1]) {ShortError=1;break;}
				if(PIO3!=PBYTE[CS4+2]) {ShortError=1;break;}
				if(PIO4!=PBYTE[CS5]) {ShortError=1;break;}
				if(PIO5!=PBYTE[CS5+1])  {ShortError=1;break;}
				if(PIO6!=PBYTE[CS5+2]) ShortError=1;
				if(PU2!=0x3f&P2) ShortError=1;
				if(PU1!=0x3f&P1) ShortError=1;
				d=0x1;
				for(n=0;n<8;n++)
				{
					PBYTE[CS1]=d;
					Delay10ms(3);
					if((~d&PIO1)!=PBYTE[CS4]) ShortError=1;
					if(PIO2!=PBYTE[CS4+1]) ShortError=1;
					if(PIO3!=PBYTE[CS4+2]) ShortError=1;
					if(PIO4!=PBYTE[CS5]) ShortError=1;
					if(PIO5!=PBYTE[CS5+1]) ShortError=1;
					if(PIO6!=PBYTE[CS5+2]) ShortError=1;
					if(PU2!=0x3f&P2) ShortError=1;
					if(PU1!=0x3f&P1) ShortError=1;
					d<<=1;
				}
				PBYTE[CS1]=0;
				if(ShortError) 	break;
				d=0x1;
				for(n=0;n<8;n++)
				{
					PBYTE[CS1+1]=d;
					Delay10ms(3);
					if(PIO1!=PBYTE[CS4]) ShortError=1;
					if((~d&PIO2)!=(dd=PBYTE[CS4+1])) ShortError=1;
					if(PIO3!=PBYTE[CS4+2]) ShortError=1;
					if(PIO4!=PBYTE[CS5]) ShortError=1;
					if(PIO5!=PBYTE[CS5+1]) ShortError=1;
					if(PIO6!=PBYTE[CS5+2]) ShortError=1;
					if(PU2!=0x3f&P2) ShortError=1;
					if(PU1!=0x3f&P1) ShortError=1;
					d<<=1;
				}
				PBYTE[CS1+1]=0;
				if(ShortError) 	break;
				d=0x1;
				for(n=0;n<8;n++)
				{
					PBYTE[CS1+2]=d;
					Delay10ms(3);
					if(PIO1!=PBYTE[CS4]) ShortError=1;
					if(PIO2!=PBYTE[CS4+1]) ShortError=1;
					if((~d&PIO3)!=PBYTE[CS4+2]) ShortError=1;
					if(PIO4!=PBYTE[CS5]) ShortError=1;
					if(PIO5!=PBYTE[CS5+1]) ShortError=1;
					if(PIO6!=PBYTE[CS5+2]) ShortError=1;
					if(PU2!=0x3f&P2) ShortError=1;
					if(PU1!=0x3f&P1) ShortError=1;
					d<<=1;
				}
				PBYTE[CS1+2]=0;
				if(ShortError) 	break;
				d=0x1;
				for(n=0;n<8;n++)
				{
					PBYTE[CS2]=d;
					Delay10ms(3);
					if(PIO1!=PBYTE[CS4]) ShortError=1;
					if(PIO2!=PBYTE[CS4+1]) ShortError=1;
					if(PIO3!=PBYTE[CS4+2]) ShortError=1;
					if((~d&PIO4)!=PBYTE[CS5]) ShortError=1;
					if(PIO5!=PBYTE[CS5+1]) ShortError=1;
					if((d==4?PIO6&0xf7:PIO6)!=PBYTE[CS5+2]) ShortError=1;
					if(PU2!=0x3f&P2) ShortError=1;
					if(PU1!=0x3f&P1) ShortError=1;
					d<<=1;
				}
				PBYTE[CS2]=0;
				if(ShortError) break;
				d=0x1;
				for(n=0;n<8;n++)
				{
					PBYTE[CS2+1]=d;
					Delay10ms(3);
					if(PIO1!=PBYTE[CS4]) ShortError=1;
					if(PIO2!=PBYTE[CS4+1]) ShortError=1;
					if(PIO3!=PBYTE[CS4+2]) ShortError=1;
					if(PIO4!=PBYTE[CS5]) ShortError=1;
					if((~d&PIO5)!=PBYTE[CS5+1]) ShortError=1;
					if(PIO6!=PBYTE[CS5+2]) ShortError=1;
					if(PU2!=0x3f&P2) ShortError=1;
					if(PU1!=0x3f&P1) ShortError=1;
					d<<=1;
				}
				PBYTE[CS2+1]=0;
				if(ShortError) break;
				d=0x1;
				for(n=0;n<8;n++)
				{
					PBYTE[CS2+2]=d;
					Delay10ms(3);
					if(PIO1!=PBYTE[CS4]) ShortError=1;
					if(PIO2!=PBYTE[CS4+1]) ShortError=1;
					if(PIO3!=PBYTE[CS4+2]) ShortError=1;
					if((d!=8?PIO4:PIO4&0xfb)!=PBYTE[CS5]) ShortError=1;
					if(PIO5!=PBYTE[CS5+1]) ShortError=1;
					if((~d&PIO6)!=PBYTE[CS5+2]) ShortError=1;
					if(PU2!=0x3f&P2) ShortError=1;
					if(PU1!=0x3f&P1) ShortError=1;
					d<<=1;
				}
				PBYTE[CS2+2]=0;
				if(ShortError) break;
				d=0x1;
				for(n=0;n<6;n++)
				{
					P2&=~d;
					Delay10ms(3);
					if(PIO1!=PBYTE[CS4]) ShortError=1;
					if(PIO2!=PBYTE[CS4+1]) ShortError=1;
					if(PIO3!=PBYTE[CS4+2]) ShortError=1;
					if(PIO4!=PBYTE[CS5]) ShortError=1;
					if(PIO5!=PBYTE[CS5+1]) ShortError=1;
					if(PIO6!=PBYTE[CS5+2]) ShortError=1;
					if((~d&PU2)!=0x3f&P2) ShortError=1;
					if(PU1!=0x3f&P1) ShortError=1;
					d<<=1;
				}
				P2|=0x3f;
				if(ShortError) break;
				d=0x1;
				for(n=0;n<6;n++)
				{
					P1&=~d;
					Delay10ms(3);
					if(PIO1!=PBYTE[CS4]) ShortError=1;
					if(PIO2!=PBYTE[CS4+1]) ShortError=1;
					if(PIO3!=PBYTE[CS4+2]) ShortError=1;
					if(PIO4!=PBYTE[CS5]) ShortError=1;
					if(PIO5!=PBYTE[CS5+1]) ShortError=1;
					if(PIO6!=PBYTE[CS5+2]) ShortError=1;
					if((~d&PU1)!=0x3f&P1) ShortError=1;
					if(PU2!=0x3f&P2) ShortError=1;
					d<<=1;
				}
				P1|=0x3f;
				if(ShortError) break;
				break;
			}
			PBYTE[CS3]=0;   //Destroy first test step
			if(ShortError)
			{
				PBYTE[CS3]=0x40;
				break;
			}
			//LED test
			if(ln==0)
			{
				PIO2=0xe;						//Set 3Color destroy
				PIO1=PIO3=PIO4=PIO5=PIO6=0;
				Initial8255A();
				PBYTE[CS3+1]=0x7;		//3.3V 5V 5Vaux on
				ln=1;
			}
			while(1);
		}
	}
}
/*		//Static Initial
		PowerBtnOk1=PowerBtnOk2=0;
		Jack1Ok=Jack2Ok=0;
		GpiLedOk=0;
		UsbOk1=0;UsbOk2=0;
		Jack1394Ok1=0;Jack1394Ok2=0;
		HP_JackOk1=HP_JackOk2=HP_JackOk3=0;
		MIC_JackOk1=MIC_JackOk2=MIC_JackOk3=0;
		Led=0;

//		PA1=0xfe;
//		PA2=0xff;
//		PBYTE[DP1A]=PA1;PBYTE[DP2A]=PA2;
		#define ON5V (~0x4)
		while(1)
		{
			if(!UsbOk1)
			{
				P2=~8;Delay10ms(20);
				st=(P2==~8);
				P2=~16;Delay10ms(20);
				st=st&&(P2==~16);
				P2=~32;Delay10ms(20);
				st=st&&(P2==~32);
				P2=~64;Delay10ms(20);
				st=st&&(P2==~64);
				P2=~128;Delay10ms(20);
				st=st&&(P2==0x7f);
				P2=~2;Delay10ms(50);
				st=st&&(P2==0xf9);
				P2=~4;Delay10ms(50);
				st=st&&(P2==0xf9);
				UsbOk1=st;
				P2=0xff;
			}
			if(!Jack1394Ok1)
			{
				P1=~1;Delay10ms(20);
				st=(P1=~1,(P1|0xc0)==~1);
				P1=~2;Delay10ms(20);
				st&=(P1=~2,(P1|0xc0)==~2);
				P1=~4;Delay10ms(20);
				st&=(P1=~4,(P1|0xc0)==(~4));
				P1=~8;Delay10ms(20);
				st&=(P1=~8,(P1|0xc0)==(~8));
				P1=~16;Delay10ms(20);
				st&=(P1=~16,(P1|0xc0)==(~16));
				P1=~32;Delay10ms(20);
				st&=(P1=~32,(P1|0xc0)==(~32));
				Jack1394Ok1=st;
				P1=0xff;
			}
			if(!(PBYTE[DP1B]&0x80)) GpiLedOk=1; 
//			if(!(PBYTE[DP1B]&JACK1)) {LightLedH(DP4C,PC4,0Xfd);} 					//DLED_2 light
			if(!(PBYTE[DP1B]&JACK2)) {LightLedH(DP4C,PC4,0xfe);} 					//HD_LED light
		}*/
/*		{
			ln=0;
			PBYTE[DP2A]=PA2;
			PBYTE[DP4A]=PA4=0;
		}*/
		//shortcut test
/*		PBYTE[DP2]=PBYTE[DP3]=PMODE0|PAIN|PBIN&PCLOUT&PCHOUT;
		PBYTE[DP1C]=PBYTE[DP2C]=PBYTE[DP3C]=PBYTE[DP4C]=0xff;
		PB1=PBYTE[DP1B];
		PB2=PBYTE[DP2B];
		PB3=PBYTE[DP3B];
		PB4=PBYTE[DP4B];
		PA2=PBYTE[DP2A];
		PA3=PBYTE[DP3A];
		for(b=1,i=0;i<8;i++,b<<=1)
		{
			PA1;
		}
				
*/
/*		PBYTE[DP1]=PBYTE[DP2]=PBYTE[DP3]=PBYTE[DP4]=PMODE0|PAIN|PBIN|PCLIN|PCHIN;
		PA1=PBYTE[DP1A];
		PB1=PBYTE[DP1B];
		PC1=PBYTE[DP1C];

		PA2=PBYTE[DP2A];
		PB2=PBYTE[DP2B];
		PC2=PBYTE[DP2C];

		PA3=PBYTE[DP3A];
		PB3=PBYTE[DP3B];
		PC3=PBYTE[DP3C];

		PA4=PBYTE[DP4A];
		PB4=PBYTE[DP4B];
		PC4=PBYTE[DP4C];*/




//		PBYTE[DP4A]=0xa5;
//		delay(20000);
//		PBYTE[DP4A]=0x5a;
//		delay(20000);
		
//		PBYTE[DP1A]=0x7e;
//		delay(5000);
//		PBYTE[DP1A]=0x81;
//		PBYTE[DP2B]=1;
//		delay(5000);
//		PBYTE[DP2B]=0;
//		PBYTE[DP2B]=2;
//		delay(5000);
//		PBYTE[DP2B]=0;

void Initial(void)
{
	P1=P2=P3=0xff;
//	RECLED=1;
	INPORT=P3;
	TMOD=0X11;
	TR0=1;
	EX0=EX1=0;
	ET0=1;
	EA=1;
	TL0=T10MS & 256;
	TH0=T10MS/256;
}
void Initial8255(void)
{
	PBYTE[CS1+3]=PMODE0&PAOUT&PBOUT&PCLOUT&PCHOUT;
	PBYTE[CS2+3]=PMODE0&PAOUT&PBOUT&PCLOUT&PCHOUT;
	PBYTE[CS3+3]=PMODE0&PAOUT&PBOUT&PCLOUT&PCHOUT;
	PBYTE[CS4+3]=PMODE0|PAIN|PBIN|PCLIN|PCHIN;
	PBYTE[CS5+3]=PMODE0|PAIN|PBIN|PCLIN|PCHIN;
	PBYTE[CS6+3]=PMODE0|PAIN|PBIN|PCLIN|PCHIN;
	Initial8255A();
}
	
void Initial8255A(void)
{
	PBYTE[CS1+0]=PIO1;
	PBYTE[CS1+1]=PIO2;
	PBYTE[CS1+2]=PIO3;

	PBYTE[CS2+0]=PIO4;
	PBYTE[CS2+1]=PIO5;
	PBYTE[CS2+2]=PIO6;

	PBYTE[CS3+0]=0;
	PBYTE[CS3+1]=0;
	PBYTE[CS3+2]=0;

	P1=0xff;
	P2=0xff;
	P3=0xff;

}

/*
void PowerOff (void) interrupt INT0INT
{
//	StopPwrdn();
	EA=0;
	ET0=0;
	P0=P1=P2=P3=0;
	PCON|=0x2;
}*/
void Time10ms (void) interrupt TIMER0INT
{
	#define LightLedA(a,b,c,d,e) {if(light) {(b)|=(c);PBYTE[a]=(b);lt=d;}else{(b)&=~(c);PBYTE[a]=(b);lt=e;}}
	#define LightLedA2(a,b,c,d,e) {if(light) {(b)&=~(c);PBYTE[a]=(b);lt=d;}else{(b)|=(c);PBYTE[a]=(b);lt=e;}}
	#define tt 10
	#define PNO 6
	static char cn=tt;
	static char InP1=0,InP2=0;
	char pp,p1;
	char InP,InP3;
	static bit light=0;
	static char lt=0;
	static char jn1,jn2;
	static char pn;
	static char un;
	static char jn;
	static bit hl=0;
	bit st;
	TL0=T10MS & 256;
	TH0=T10MS/256;


	InP=INPORT^P3;
	InP3=InP&InP2;
	InP2=InP&InP1&(~InP3);
	InP1=InP&(~InP3);
	InP^=INPORT;
	InP&=InP3;
	INPORT&=~InP3;
	INPORT|=InP;
	if(ln)
	{
		if(lt<=0)
		{
			light=!light;
			switch(ln)
			{
			case 1:
				if(!Jack1394Ok2) LightLedA(CS1+1,PIO2,0x80,50,1);		//DLED_4
				break;
			case 2:
				if(!UsbOk2) LightLedA(CS1+2,PIO3,0x80,50,1);		//LAN_LED
				break;
		    case 3:
				if(!UsbOk2) LightLedA(CS1+2,PIO3,0x4,50,1);		//DLED_3
				break;
			case 4:
	//			if(PBYTE[DP1B]&JACK1) {LightLedA(DP4C,PC4,0Xfd,5,8);}		//DLED_2 twinkle
				if(!HP_JackOk3) 
					{LightLedA(CS1+2,PIO3,0X2,50,1);}		//DLED_2 twinkle
				break;
			case 5:
//				if(PBYTE[DP1B]&JACK2) {LightLedA(CS1+2,PIO3,1,50,1);}	//HD_LED twinkle
				{LightLedA(CS1+2,PIO3,1,50,1);}	//HD_LED twinkle
				break;
		    case 6:
				if(!PowerBtnOk2) LightLedA(CS1+1,PIO2,0x40,50,1);		//DLED_1
				break;
			case 7:
				LightLedA(CS1+2,PIO3,0x8,50,1);					//PWR_LED1
				break;
			case 8:
				LightLedA(CS1+2,PIO3,0x20,50,1);					//PWR_LED2
				break;
			case 9:
				if(!(PBYTE[CS4+1]&1))
				{
					LightLedA2(CS1+1,PIO2,0x2,100,1);			//J1-10
				}
				else
				{
					PBYTE[CS1+1]=(PIO2|=0xe);						//Destroy the LED
				}
				break;
			case 10:
				if(!(PBYTE[CS4+1]&1))
				{
					LightLedA2(CS1+1,PIO2,0x4,100,1);			//J1-11
				}
				else
				{
					PBYTE[CS1+1]=(PIO2|=0xe);						//Destroy the LED
				}
				break;
			case 11:
				if(!(PBYTE[CS4+1]&1))
				{
					LightLedA2(CS1+1,PIO2,0x8,100,1);			//J1-12
				}
				else
				{
					PBYTE[CS1+1]=(PIO2|=0xe);						//Destroy the LED
				}			
			break;
			default:lt=0;
			}
			if(!light) if(++ln>11) ln=1;
				
			//HP Jack test
			if(HP_JackOk3)
			{
	//			LightLedH(DP4C,PC4,0Xfd);		//DLED_2 light
				LightLedH(CS1+2,PIO3,0x2);		//DLED_2 light
				PBYTE[CS3]=0x10;
			}
			if(HP_JackOk2&&!HP_JackOk3)			//方波测试
			{
				if(hl)						//jn:number of test 奇数方波低电平,偶数高电平
				{
					st=((p1=PBYTE[CS4])&4!=0);
					hl=0;
				}
				else
				{
					PIO1|=1;PBYTE[CS1]=PIO1;
					st=(!((p1=PBYTE[CS4])&4));
					PIO1&=~1;PBYTE[CS1]=PIO1;
					hl=1;
				}
				if(st)
				{
					jn1++;
					if(jn1>=PNO)			//方波数=PNO/2
					{
						jn1=0;
						HP_JackOk3=st;
					}
				}
				else jn1=0;
			}
			if(HP_JackOk1&&!HP_JackOk2)			//插头感应开关变低 
			{
				if((!((p1=PBYTE[CS4])&JACK1)))
				{
					jn1++;
					if(jn1>=PNO) {HP_JackOk2=1;jn1=0;}
				}
				else
				{
					jn1=0;
				}
			}
			if(!HP_JackOk1)					//插头感应开关起始为高
			{
				if(((p1=PBYTE[CS4])&JACK1))
				{
					jn1++;
					if(jn1>=PNO) {HP_JackOk1=1;jn1=0;}
					Led|=16;
				}
				else
				{
					jn1=0;
				}
			}
		}
/*
		//Power botton
		#define POWER_BTN 0x8
		if(!PowerBtnOk1)
		{
			if(!(PBYTE[DP2B]&POWER_BTN))
			{
				pn=0;
			}
			else
			{
				pn++;
				if(pn>=PNO)
				{
					PowerBtnOk1=1;
				}
			}
		}
		if(!PowerBtnOk2&&PowerBtnOk1)
		{
			if(PBYTE[DP2B]&POWER_BTN)
			{
				pn=PNO;
			}
			else
			{
				pn--;
				if(!pn)
				{
					PowerBtnOk2=1;
					LightLedH(DP3C,PC3,0xbf);		//DLED_1
					Led|=64;
				}
			}
		}
		//USB
		if(UsbOk1&&!UsbOk2&&!(PBYTE[DP3A]&0x18)&&Line_A&&Line_H)
		{
			if(P2&0x7e)
				un=0;
			else
			{
				un++;
				if(un>=PNO)
				{
					UsbOk2=1;
					LightLedH(DP4C,PC4,0xdf);		//LAN_LED
					LightLedH(DP4C,PC4,0xfb);		//DLED_3
					Led|=8;
					un=0;
				}
			}
		}
		//1394 test
		if(Jack1394Ok1&&!Jack1394Ok2) //!((pp=PBYTE[DP3A])&0xe0))
		{
			if(P1&0x3d)
				jn=0;
			else
			{
				jn++;
				if(jn>=PNO)
				{
					Jack1394Ok2=1;
					LightLedH(DP3C,PC3,0x7f);		//DLED_4
					Led|=4;
					jn=0;
				}
			}
		}
		PBYTE[DP4A]=Led;*/
	}
	if(lt) lt--;
	if(td) td--;	
	if((--cn)==0)
	{
		cn=tt;
		if(ps>0)
		{
//			PA4^=(2<<ps);
//			PBYTE[DP4A]=PA4;
		}
	}
}

void Delay10ms(unsigned int a)
{
	td=a;
	while(td);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -