?? little torch底蓋零件測試治具.c
字號:
#include <reg52.h>
#include <GRESSY.h>
void main(void)
{
bit ledchange=1;
bit oldLAST=0;
bit oldNEXT=0;
// bit recerr=0;
unsigned int addr=0;
unsigned char addrh=0,addrl=0;
playno=1;
// bit oldSTSP=0;
// bit last=1;
// bit lastno=CN;
// bit nextno=CN;
// bit next=1;
// bit play=1;
// bit rec=1;
isrecord=isplay=0;
Initial();
// InitialINT();
// LedTest();
// Initial();
// start=0;
oldLAST=LAST;
oldNEXT=NEXT;
//LED TEST
start=1;
// while(1)
{
P0&=0xe0;P1=0;
BELL=0;Delay(1000);BELL=1;
P14=0;
Delay(1000);
LedTest(P10,P10);
LedTest(P11,P11);
LedTest(P12,P12);
LedTest(P13,P13);
LedTest(P15,P15);
LedTest(P16,P16);
LedTest(P17,P17);
LedTest(P00,P01);
LedTest(P02,P02);
LedTest(P03,P03);
LedTest(P04,P04);
P0=0XFF;
P1=0XEF;
Delay(1000);
P1=0XFF;
Delay(1000);
}
start=0;
PowerUp();Delay(5);PowerUp();Delay(10);
// OKNUM=0;
sd=SHOWTIME;BELL=1;
while(1)
{
if(PLAY|REC)
{
if(PLAY)
{
RECERROR=1;RECLED=1;
RECSEL=1;
isrecord=0;
if(!isplay)
{
if(playno<1||playno>MAXNO) playno=1;
isplay=1;
ledchange=1;
}
if(ledchange)
{
Stop();
Delay(20);
addr=(playno-1)*PERDURATION;
addrl=addr%256;
addrh=addr>>8;
// SMG=~(LED[playno]);
}
if(ledchange||(!INT))
{
SetPlay(addrl,addrh);
Play();
}
}
else
{
isplay=0;RECSEL=0;
if(!isrecord)
{
ledchange=1;
isrecord=1;
if(playno<1||playno>MAXNO) playno=1;
}
if(ledchange)
{
Stop();
Delay(20);
addr=(playno-1)*PERDURATION;
addrl=addr%256;
addrh=addr>>8;
// SMG=~(LED[playno]);
}
if(STSP)
{
/* PowerUp();
Delay(5);
PowerUp();
Delay(10);
*/
RECERROR=1;
SetRec(addrl,addrh);
// Delay(1);
Rec();
RECLED=0;
td=MAXRECTIME;
while(STSP&&td&&REC){if(!RECERR) ed=100;}
while((!STSP)&&td&&REC){if(!RECERR) ed=100;}
Stop();
RECLED=1;
Delay(20);
// StopPwrdn();
// Delay(1);
while(STSP);
}
}
ledchange=0;
if(oldLAST&&LAST)
{
if(playno<=1||playno>MAXNO) playno=MAXNO;else playno--;
sd=SHOWTIME;
ledchange=1;
}
if(oldNEXT&&NEXT)
{
if(playno<1||playno>=MAXNO) playno=1;else playno++;
sd=SHOWTIME;
ledchange=1;
}
oldLAST=!LAST;
oldNEXT=!NEXT;
}
else
{
// StopPwrdn();
Stop();
Delay(20);
// SMG=~0;
isplay=0;isrecord=0;ledchange=0;
RECERROR=1;
}
}
}
void Initial(void)
{
P0=P1=P2=P3=0xff;
// RECLED=1;
INPORT=0XFF;
TMOD=0X11;
TR0=1;
EX0=0;
ET0=1;
EA=1;
TL0=T5MS & 256;
TH0=T5MS/256;
}
void SendByte(char sd)
{
char i;
unsigned char shd;
for(shd=1,i=0;i<8;i++,shd<<=1)
{
SCLK=0;
MOSI=shd&sd?1:0;
SCLK=0;
SCLK=0;
SCLK=0;
SCLK=0;
SCLK=0;
SCLK=0;
SCLK=0;
SCLK=1;
SCLK=1;
SCLK=1;
SCLK=1;
SCLK=1;
SCLK=1;
SCLK=1;
}
MOSI=0;
SCLK=0;
}
void PowerOff (void) interrupt INT0INT
{
// StopPwrdn();
EA=0;
ET0=0;
P0=P1=P2=P3=0;
PCON|=0x2;
}
void Time5ms (void) interrupt TIMER0INT
{
#define FLASHTIME 60
static unsigned char ft=FLASHTIME;
static bit fd;
static char InP1=0,InP2=0,PP1=0XFF;
char InP,InP3;
static char Digital=0,OKNUM=0;
static unsigned char TestDelay;
// bit LAST1=0,LAST2=0,LAST3=0;
// bit NEXT1=0,NEXT2=0,NEXT3=0;
// bit PLAY1=0,PLAY2=0,PLAY3=0;
// bit STST1=0,STST2=0,STST3=0;
TL0=T5MS & 256;
TH0=T5MS/256;
if(P14)
{
TestDelay=TESTDELAYTIME;
BELL=1;
OK=0;
}
else
{
if(TestDelay) TestDelay--;
}
Digital++;
switch(Digital)
{
case 1:
if(SWITCHIN)
{
PP1|=0x1;
}
else
{
PP1&=~0x1;
}
P2=0X8F; //B1=B2=B3=0;
if(!OK&&!TestDelay)
{
B1=P13;
B2=P15;
B3=P16;
}
if(sd)
{
switch(playno)
{
case 4:B1^=fd;break;
case 5:B2^=fd;break;
case 6:B3^=fd;break;
}
}
P2&=~2;
break;
case 2:
if(SWITCHIN)
{
PP1|=0x2;
}
else
{
PP1&=~0x2;
}
P2=0X8F; //B1=B2=B3=0;
if(!OK&&!TestDelay)
{
B1=P17;
B2=(P00|P01);
B3=P02;
}
P2&=~4;
break;
case 3:
if(SWITCHIN)
{
PP1|=0x4;
}
else
{
PP1&=~0x4;
}
P2=0X8F; //B1=B2=B3=0;
if(!OK&&!TestDelay)
{
B1=P03;
B2=P04;
B3=0;
}
if(sd)
{
switch(playno)
{
case 7:B1^=fd;break;
case 8:B2^=fd;break;
}
}
if(OK) B3=1;
P2&=~8;
break;
default:
Digital=0;
if(SWITCHIN)
{
PP1|=0x8;
}
else
{
PP1&=~0x8;
}
P2=0X8F; //B1=B2=B3=0;
if(!OK&&!TestDelay)
{
B1=P10;
B2=P11;
B3=P12;
}
if(sd)
{
switch(playno)
{
case 1:B1^=fd;break;
case 2:B2^=fd;break;
case 3:B3^=fd;break;
}
}
P2&=~1;
break;
}
InP=INPORT^PP1;
InP3=InP&InP2; //count 3
InP2=InP&InP1&(~InP3);
InP1=InP&(~InP3);
InP^=INPORT; //InP=PP1
InP&=InP3;
INPORT&=~InP3;
INPORT|=InP;
if(!start)
{
if(P1||(P0&0x1f))
{
//NG
OKNUM=0;
OK=0;
if(!P14) BELL=0;
}
else
{
//OK
OKNUM++;
if(OKNUM>=100)
{
OKNUM=0;
OK=1;
BELL=1;
}
}
if(ft)
{
ft--;
}
else
{
ft=FLASHTIME;
fd=~fd;
}
if(ed)
{
RECERROR=0;
ed--;
}
else
{
RECERROR=1;
}
}
if(sd) sd--;
if(td) td--;
// if(!(--cn))
// {
// cn=100;
// SMG^=0x80;
// }
}
void Delay(int a)
{
td=a/5;
while(td);
}
/*
bit TestS(bit a,bit A)
{
if(a)
{
if(!A&!A&!A&!A) a=0;
}
else
{
if(A&A&A&A) a=1;
}
return(a);
}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -