?? wt-paris.c
字號:
#include <AT89X52.h>
#include <wt-paris.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);
LightLed=0;
TwingleLed=0;
/* for(n=0;n<20;n++)
{
PBYTE[CS3]=0xff;
Delay10ms(50);
PBYTE[CS3]=0;
Delay10ms(50);
}*/
LightLed=0;
while(1)
{
PIO1=PIO2=PIO3=PIO4=PIO5=PIO6=0;
Initial8255();
InitialH8255A();
if(ng)
{
LightLed=0x40;TwingleLed=0;
PBYTE[CS3+1]=0x8;Delay10ms(5);PBYTE[CS3+1]=0;Delay10ms(5);
PBYTE[CS3+1]=0x8;Delay10ms(5);PBYTE[CS3+1]=0;Delay10ms(5);
PBYTE[CS3+1]=0x8;Delay10ms(5);PBYTE[CS3+1]=0;Delay10ms(5);
}
if(ok)
{
LightLed=0x80;TwingleLed=0;
PBYTE[CS3+1]=0x8;Delay10ms(50);PBYTE[CS3+1]=0;
}
ln=0;
PIO2=~0x20;
PIO6=~0x10;
PBYTE[CS1+1]=PIO2;
PBYTE[CS2+2]=PIO6;
if(ng||ok)
{
ng=ok=0;
for(n=0;n<20;n++)
{
if(!(PBYTE[CS4+1]&(~PIO2))) n=0;
if(!(PBYTE[CS5+2]&(~PIO6))) n=0;
if(ng) break;
if(!CN3) break;
}
}
else
{
LightLed=0;
TwingleLed=0xff;
Delay10ms(300);
TwingleLed=0xc0;
}
if(ng) continue;
ng=ok=0;LightLed=0;
for(n=0;n<20;n++)
{
if((dd=PBYTE[CS4+1])&(~PIO2)) n=0;
if((dd=PBYTE[CS5+2])&(~PIO6)) n=0;
if(ng) break;
}
if(ng) continue;
//Power switch test
PIO1=PIO2=PIO3=PIO4=PIO5=PIO6=0;
Initial8255();
Delay10ms(50);
LightLed=0;
TwingleLed=0x20;
PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0;Delay10ms(20);
for(n=0;n<5;n++)
{
if(!(PBYTE[CS4+2]&0x40)) //0x40 power switch
{
ng=1;
break;
}
Delay10ms(1);
}
if(ng)
{
LightLed|=0x40;
continue;
}
for(n=0;n<5;n++)
{
if(PBYTE[CS4+2]&0x40) n=0;
if(ng) break;
Delay10ms(1);
}
while(!(PBYTE[CS4+2]&0x40)&&ng==0);
Delay10ms(10);
//Shortcut test
// PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0;Delay10ms(20);
PIO1=PIO2=PIO3=PIO4=PIO5=PIO6=0;
Initial8255();
LightLed&=0x0;TwingleLed=0x10;
PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0;Delay10ms(20);
n=PBYTE[CS4];
n=PBYTE[CS4+1];
n=PBYTE[CS4+2];
n=PBYTE[CS5];
n=PBYTE[CS5+1];
n=PBYTE[CS5+2];
PIO1=0xd7;
PIO2=0xdd;
PIO3=0xff;
PIO4=0xf7;
PIO5=0xb6;
PIO6=0xf; //?
PU2=0x3F;
PU1=0x3F;
while(1)
{
if(PIO1!=(dd=PBYTE[CS4])) {ng=1;break;}
if(PIO2!=PBYTE[CS4+1]) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d=0x1;
for(n=0;n<8;n++)
{
PBYTE[CS1]=d;
Delay10ms(10);
if(((~d)&PIO1)!=(dd=PBYTE[CS4])) {ng=1;break;}
if(PIO2!=(dd=PBYTE[CS4+1])) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d<<=1;
}
PBYTE[CS1]=0;
if(ng) break;
d=0x1;
for(n=0;n<8;n++)
{
PBYTE[CS1+1]=d;
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if((~d&PIO2)!=PBYTE[CS4+1]) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if(d==1)
{
if((0x7f&PIO5)!=PBYTE[CS5+1]) {ng=1;break;}
}
else
{
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d<<=1;
}
PBYTE[CS1+1]=0;
if(ng) break;
d=0x1;
for(n=0;n<8;n++)
{
PBYTE[CS1+2]=d;
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if(PIO2!=PBYTE[CS4+1]) {ng=1;break;}
if((~d&PIO3)!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if(PIO5!=(dd=PBYTE[CS5+1])) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d<<=1;
}
PBYTE[CS1+2]=0;
if(ng) break;
d=0x1;
for(n=0;n<8;n++,d<<=1)
{
if(d&(0x10|0x20|0x40)) continue;
PBYTE[CS2]=d;
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if(PIO2!=PBYTE[CS4+1]) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if((~d&PIO4)!=(dd=PBYTE[CS5])) {ng=1;break;}
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
// if((d==4?PIO6&0xf7:PIO6)!=(dd=PBYTE[CS5+2])) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
// d<<=1;
}
PBYTE[CS2]=0;
if(ng) break;
d=0x1;
for(n=0;n<8;n++)
{
PBYTE[CS2+1]=d;
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if((d==0x80?(0xfe&PIO2):PIO2)!=(dd=PBYTE[CS4+1])) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if((~d&PIO5)!=PBYTE[CS5+1]) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d<<=1;
}
PBYTE[CS2+1]=0;
if(ng) break;
d=0x1;
for(n=0;n<7;n++)
{
PBYTE[CS2+2]=d;
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if(PIO2!=PBYTE[CS4+1]) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
if((~d&PIO6)!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d<<=1;
}
PBYTE[CS2+2]=0;
if(ng) break;
d=0x20;
for(n=0;n<6;n++)
{
P2=(P2|0x3f)&(~d);
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if(PIO2!=PBYTE[CS4+1]) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(d==1||d==2)
{
if((~3&PU2)!=(0x3f&P2)) {ng=1;break;}
}
else
{
if((~d&PU2)!=(0x3f&P2)) {ng=1;break;}
}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d>>=1;
}
P2|=0x3f;
if(ng) break;
d=0x20;
for(n=0;n<6;n++)
{
P1=(P1|0x3f)&(~d);
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if(PIO2!=PBYTE[CS4+1]) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if(PIO4!=PBYTE[CS5]) {ng=1;break;}
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if((~d&PU1)!=(0x3f&P1)) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
d>>=1;
}
P1|=0x3f;
if(ng) break;
d=0x10;
for(n=0;n<3;n++)
{
PBYTE[CS2]=d;
Delay10ms(3);
if(PIO1!=PBYTE[CS4]) {ng=1;break;}
if(PIO2!=PBYTE[CS4+1]) {ng=1;break;}
if(PIO3!=PBYTE[CS4+2]) {ng=1;break;}
if((~(0x10|0x20|0x40)&PIO4)!=PBYTE[CS5]) {ng=1;break;}
if(PIO5!=PBYTE[CS5+1]) {ng=1;break;}
if(PIO6!=(0x7f&PBYTE[CS5+2])) {ng=1;break;}
if(PU2!=(0x3f&P2)) {ng=1;break;}
if(PU1!=(0x3f&P1)) {ng=1;break;}
d<<=1;
}
PBYTE[CS2]=0;
if(ng) break;
break;
}
if(ng)
{
LightLed=0x40;TwingleLed=0;
continue;
}
//Jack test
/* LightLed=0;TwingleLed=0x8;
PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0x4;Delay10ms(20); //3.3V on
for(n=0;n<5;n++)
{
if(PBYTE[CS4]&0x82) n=0;
if(ng) break;
Delay10ms(1);
}
//方波測試
PIO1=PIO2=PIO3=PIO4=PIO5=PIO6=0;
Initial8255A();
for(n=0;n<3;n++)
{
while((PBYTE[CS4]&5)!=5&&ng==0) {PIO1&=~5;PBYTE[CS1]=PIO1;Delay10ms(1);}
Delay10ms(20);
PIO1|=1;PBYTE[CS1]=PIO1;
if((dd=PBYTE[CS4])&4)
{
ng=1;
break;
}
PIO1&=~5;PBYTE[CS1]=PIO1;
}
if(ng)
{
LightLed=0x40;TwingleLed=0;
continue;
}
for(n=0;n<3;n++)
{
while((PBYTE[CS4]&0x50)!=0x50&&ng==0) {PIO1&=~0x50;PBYTE[CS1]=PIO1;Delay10ms(1);}
Delay10ms(20);
PIO1|=0x40;PBYTE[CS1]=PIO1;
Delay10ms(1);
if(PBYTE[CS4]&0x10) {ng=1;break;}
PIO1&=~0x40;PBYTE[CS1]=PIO1;
}
*/
LightLed=0;TwingleLed=0x8;
PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0x4;Delay10ms(20); //3.3V on
PBYTE[CS1]=0x8;
for(n=0;n<5;n++)
{
if((dd=PBYTE[CS4])&0x82) n=0;
if(ng) break;
Delay10ms(1);
}
PBYTE[CS1]=0;
//方波測試
PIO1=PIO2=PIO3=PIO4=PIO5=PIO6=0;
Initial8255A();
#define LCH 0x11
#define RCH 0x44
//L changle
for(n=0;n<3;n++)
{
//L
PIO1&=((~LCH)&(~RCH));PBYTE[CS1]=PIO1;
while((PBYTE[CS4]&LCH)!=LCH&&ng==0) {PIO1&=~LCH;PBYTE[CS1]=PIO1;Delay10ms(1);}
Delay10ms(30);
PIO1|=(LCH&0xf0);PBYTE[CS1]=PIO1;
if((dd=PBYTE[CS4])&(LCH&0xf0))
{
ng=1;
break;
}
PIO1&=~LCH;PBYTE[CS1]=PIO1;
//R
while((PBYTE[CS4]&RCH)!=RCH&&ng==0) {PIO1&=~RCH;PBYTE[CS1]=PIO1;Delay10ms(1);}
Delay10ms(30);
PIO1|=(RCH&0xf0);PBYTE[CS1]=PIO1;
if((dd=PBYTE[CS4])&(RCH&0xf0))
{
ng=1;
break;
}
PIO1&=~RCH;PBYTE[CS1]=PIO1;
}
if(ng)
{
LightLed=0x40;TwingleLed=0;
continue;
}
//USB test
LightLed=0;TwingleLed=0x4;
PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0;Delay10ms(1);
for(n=0;n<5;n++)
{
if((dd=PBYTE[CS5])&0x70) n=0;
if((dd=PBYTE[CS5+1])&0x36) n=0;
if(ng) break;
}
if(ng)
{
LightLed=0x40;TwingleLed=0;
continue;
}
Delay10ms(20);
//1394 test
LightLed=0;TwingleLed=0x2;
PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0;Delay10ms(20);
for(n=0;n<5;n++)
{
if(P2&0x3f) n=0;
if(ng) break;
}
if(ng)
{
LightLed=0x40;TwingleLed=0;
continue;
}
//LED test
LightLed&=0x0;TwingleLed=0x1;light=0;
PBYTE[CS3+1]=0x8;Delay10ms(20);PBYTE[CS3+1]=0;Delay10ms(20);
if(ln==0)
{
PIO2=0; //Set 3Color destroy
PIO1=PIO3=PIO4=PIO5=PIO6=0;
Initial8255A();
PBYTE[CS1+1]=(PIO2|=0xc0);
PBYTE[CS1+2]=(PIO3|=6);
PBYTE[CS3+1]=0x7; //3.3V 5V 5Vaux on
ln=1;
}
while(ng==0)
{
if(!CN1) {ok=1;break;}
}
}
}
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)
{
ET0=0;
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]=LightLed;
// PBYTE[CS3+0]=0;
PBYTE[CS3+1]=0;
PBYTE[CS3+2]=0;
P1=0xff;
P2=0xff;
P3|=0x3c;
ET0=1;
}
void InitialH8255A(void)
{
ET0=0;
PBYTE[CS1+0]=0xff;
PBYTE[CS1+1]=0xff;
PBYTE[CS1+2]=0xff;
PBYTE[CS2+0]=0xff;
PBYTE[CS2+1]=0xff;
PBYTE[CS2+2]=0xff;
PBYTE[CS3+0]=0;
PBYTE[CS3+1]=0;
PBYTE[CS3+2]=0;
P1=0;
P2=0;
ET0=1;
}
/*
void PowerOff (void) interrupt INT0INT
{
// StopPwrdn();
EA=0;
ET0=0;
P0=P1=P2=P3=0;
PCON|=0x2;
}*/
void Time10ms (void) interrupt TIMER0INT
{
#define tt 30
// #define PNO 6
static char cn=tt;
static char InP1=0,InP2=0;
// char pp,p1;
char InP,InP3;
static char lt=0;
// kn=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(!CN2) {ng=1;ok=0;}
if(ln)
{
if(lt<=0)
{
light=!light;
switch(ln)
{
case 1:
// LightLedL(CS1+1,PIO2,0x80,50,1); //DLED_4
LightLedL(CS1+1,PIO2,0x80,50,1); //DLED_4
break;
case 5:
LightLedH(CS1+2,PIO3,0x80,50,1); //LAN_LED
break;
case 3:
LightLedL(CS1+2,PIO3,0x4,50,1); //DLED_3
break;
case 4:
LightLedL(CS1+2,PIO3,0X2,50,1); //DLED_2 twinkle
break;
case 2:
LightLedH(CS1+2,PIO3,1,50,1); //HD_LED twinkle
break;
case 6:
LightLedL(CS1+1,PIO2,0x40,50,1); //DLED_1
break;
case 7:
LightLedH(CS1+2,PIO3,0x8,50,1); //PWR_LED1
break;
case 8:
LightLedH(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(ln>6)
{
LightLedL(CS1+1,PIO2,0x80,50,1); //DLED_4
LightLedH(CS1+2,PIO3,0x80,50,1); //LAN_LED
LightLedL(CS1+2,PIO3,0x4,50,1); //DLED_3
LightLedL(CS1+2,PIO3,0X2,50,1); //DLED_2 twinkle
LightLedH(CS1+2,PIO3,1,50,1); //HD_LED twinkle
LightLedL(CS1+1,PIO2,0x40,50,1); //DLED_1
}
if(!light) if(++ln>8) ln=1;
}
}
if(lt) lt--;
if(td) td--;
if((--cn)==0)
{
cn=tt;
LightLed^=TwingleLed;
PBYTE[CS3]=LightLed;
}
}
void Delay10ms(unsigned int a)
{
td=a;
while(td);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -