📄 90c58.c00
字号:
#include <reg52.h>
#include <absacc.h>
#include <stdio.h>
sfr P4 = 0xC0;
//#include <math.h>
unsigned char TLV=0x00;
unsigned char THV=0xf1;//0xe7;
unsigned short SECTICKS=240; //24; //65536/(65536-(THV*256+TLV))*18;
unsigned short HALFSECTICKS=120; //12;
unsigned short Q1SECTICKS=60; //12;
unsigned short Q3SECTICKS=180; //12;
unsigned short TICKS_U=6;
unsigned short TICKS_D=2;
unsigned char sbuff[16];
unsigned char count=0,triggle=0,chno=0,cycles=0;
static unsigned char ticks[8][4]; //oldP1Stat;
//sbit RLed = P1^3;
//sbit GLed = P1^2;
sbit Y00 = P2^3;
sbit Y01 = P2^4;
sbit Y02 = P2^5;
sbit Y03 = P2^6;
sbit Y04 = P2^7;
sbit Y05 = P4^4;//P0^7;
sbit Y06 = P4^1; //P0^6;
sbit Y07 = P0^7;
sbit Y10 = P0^6;
sbit Y11 = P0^4;
sbit X00 = P2^2;
sbit X01 = P2^1;
sbit X02 = P2^0;
sbit X03 = P4^0;//P3^6;//?
sbit X04 = P3^7;
sbit X05 = P3^6;
sbit X06 = P3^4;
sbit X07 = P3^5 ;
sbit X10 = P3^3;
sbit X11 = P4^3;//P3^0;//?
sbit X12 = P1^7;
sbit X13 = P1^6;
sbit X14 = P1^5;
sbit X15 = P1^4;
sbit X16 = P1^3;
sbit X17 = P1^2;
sbit X20 = P1^1;
sbit X21 = P1^0;
sbit X22 = P4^2;//P0^5;//?
sbit X23 = P0^0;
sbit X24 = P0^1;
sbit X25 = P0^2;
sbit X26 = P0^3;
sbit X27 = P0^5;
bit direction=0,direction1=0,direction2=0;
bit oldX20Stat;
bit oldX21Stat;
bit oldX22Stat;
bit oldX23Stat;
bit oldX24Stat;
bit oldX25Stat;
bit oldX26Stat;
bit oldX27Stat;
/*void delay()
{
unsigned short i,j;
for(i=0;i<30;i++) j=i;
}*/
void t0int() interrupt 1
{
unsigned char i;
TH0=THV; //Bcause TLV=0,no need to init TL0;
count++;
/* if ((oldP1Stat&0x10)==0x10 && (P1&0x10)==0x00) //UP triggle.
{
//if ((P1&0x20)==0x20) direction1=1;
//else direction1=0;
}
if ((oldP1Stat&0x20)==0x20 && (P1&0x20)==0x00) //UP triggle.
{
//if ((P1&0x10)==0x10) direction2=1;
//else direction2=0;
} */
if(oldX20Stat^X20) ticks[0][cycles]++;
if(oldX21Stat^X21) ticks[1][cycles]++;
if(oldX22Stat^X22) ticks[2][cycles]++;
if(oldX23Stat^X23) ticks[3][cycles]++;
if(oldX24Stat^X24) ticks[4][cycles]++;
if(oldX25Stat^X25) ticks[5][cycles]++;
if(oldX26Stat^X26) ticks[6][cycles]++;
if(oldX27Stat^X27) ticks[7][cycles]++;
//oldP1Stat=P1;
oldX20Stat=X20;
oldX21Stat=X21;
oldX22Stat=X22;
oldX23Stat=X23;
oldX24Stat=X24;
oldX25Stat=X25;
oldX26Stat=X26;
oldX27Stat=X27;
if(count == Q1SECTICKS)
{
cycles=1;
for(i=0;i<8;i++)
{
sbuff[4+i]=ticks[i][0]+ticks[i][1]+ticks[i][2]+ticks[i][3];
ticks[i][cycles]=0;
}
triggle=1;
}
if(count == HALFSECTICKS)
{
cycles=2;
for(i=0;i<8;i++)
{
sbuff[4+i]=ticks[i][0]+ticks[i][1]+ticks[i][2]+ticks[i][3];
ticks[i][cycles]=0;
}
triggle=1;
}
if(count == Q3SECTICKS)
{
cycles=3;
for(i=0;i<8;i++)
{
sbuff[4+i]=ticks[i][0]+ticks[i][1]+ticks[i][2]+ticks[i][3];
ticks[i][cycles]=0;
}
triggle=1;
}
if(count == SECTICKS)
{
count=0;
cycles=0;
for(i=0;i<8;i++)
{
sbuff[4+i]=ticks[i][0]+ticks[i][1]+ticks[i][2]+ticks[i][3];
ticks[i][cycles]=0;
}
triggle=1;
}
}
void main (void)
{
unsigned char i;
//sbuff[0]=0xD7;
//sbuff[1]=6;
sbuff[0]='S';
sbuff[1]=0; //X0
sbuff[2]=0; //X1
sbuff[3]=0; //X2
sbuff[4]=0; //Count X20
sbuff[4]=0; //Count X21
sbuff[6]=0; //Count X22
sbuff[7]=0; //Count X23
sbuff[8]=0; //Count X24
sbuff[9]=0; //Count X24
sbuff[10]=0; //Count X26
sbuff[11]=0; //Count X27
sbuff[12]=0; //Y0
sbuff[13]=0; //Y1
sbuff[14]=0;
sbuff[15]='E';
cycles=0; //cycles can be 0,1,2,3; stand for 0/4,1/4,2/4,3/4 seconds;
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x21; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xfa; //4800bps, as for 11059200
// reload value for 1200 baud @ 18.432MHz */
TR1 = 1; /* TR1: timer 1 run */
TR0 = 1;
TI = 1;
oldX20Stat=X20;
oldX21Stat=X21;
oldX22Stat=X22;
oldX23Stat=X23;
oldX24Stat=X24;
oldX25Stat=X25;
oldX26Stat=X26;
oldX27Stat=X27;
P0 = 0xff;
P4 = 0xff;
IE = 0x82;
//Y00=Y01=Y02=Y03=Y04=Y05=Y06=0;
//?Y07=0;
//Y10=0;
//?Y11=0;
while (1)
{
if (triggle)
{
triggle=0;
sbuff[1]=sbuff[2]=sbuff[3]=0;
if(X00) sbuff[1]+=1;
if(X01) sbuff[1]+=2;
if(X02) sbuff[1]+=4;
if(X03) sbuff[1]+=8;
if(X04) sbuff[1]+=16;
if(X05) sbuff[1]+=32;
if(X06) sbuff[1]+=64;
if(X07) sbuff[1]+=128;
if(X10) sbuff[2]+=1;
if(X11) sbuff[2]+=2;
if(X12) sbuff[2]+=4;
if(X13) sbuff[2]+=8;
if(X14) sbuff[2]+=16;
if(X15) sbuff[2]+=32;
if(X16) sbuff[2]+=64;
if(X17) sbuff[2]+=128;
if(X20) sbuff[3]+=1;
if(X21) sbuff[3]+=2;
if(X22) sbuff[3]+=4;
if(X23) sbuff[3]+=8;
if(X24) sbuff[3]+=16;
if(X25) sbuff[3]+=32;
if(X26) sbuff[3]+=64;
if(X27) sbuff[3]+=128;
if(sbuff[4]>=TICKS_U) Y00=0;
if(sbuff[4]<=TICKS_D) Y00=1;
if(sbuff[5]>=TICKS_U) Y01=0;
if(sbuff[5]<=TICKS_D) Y01=1;
if(sbuff[6]>=TICKS_U) Y02=0;
if(sbuff[6]<=TICKS_D) Y02=1;
if(sbuff[7]>=TICKS_U) Y03=0;
if(sbuff[7]<=TICKS_D) Y03=1;
if(sbuff[8]>=TICKS_U) Y04=0;
if(sbuff[8]<=TICKS_D) Y04=1;
if(sbuff[9]>=TICKS_U) Y05=0;
if(sbuff[9]<=TICKS_D) Y05=1;
if(sbuff[10]>=TICKS_U) Y06=0;
if(sbuff[10]<=TICKS_D) Y06=1;
if(sbuff[11]>=TICKS_U) Y07=0;
if(sbuff[11]<=TICKS_D) Y07=1;
//if((cycles & 1)==0) //Two times per second.
for(i=0;i<16;i++) putchar(sbuff[i]);
//RLed=1;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -