📄 chentao.c
字号:
/* ======================== */
/* GUN AIM Program */
/* BY LHG */
/* 2009.02.10 */
/* ======================== */
#include <ABSACC.H>
#include <REG4051.H>
#define uint unsigned int
#define uchar unsigned char
/* ======================== */
sbit NCP10=P1^0; /* P1.0 : no use */
sbit NCP11=P1^1; /* P1.1 : no use */
sbit NCP12=P1^2; /* P1.2 : no use */
sbit XZERO=P1^3; /* X - Axis Zero */
sbit YZERO=P1^4; /* Y - Axis Zero */
sbit NCP15=P1^5; /* P1.5 : no use */
sbit NCP16=P1^6; /* P1.6 : no use */
sbit CWDT=P1^7; /* P1.7 : no use */
/* ------------------------ */
sbit RXD1=P3^0; /* RXD : RS232 RXD */
sbit TXD1=P3^1; /* TXD : RS232 TXD */
sbit YINT=P3^2; /* Y - Axis interrupt */
sbit XINT=P3^3; /* X - Axis interrupt */
sbit XSIG=P3^4; /* X - Axis signal */
sbit YSIG=P3^5; /* Y - Axis signal */
sbit NCP37=P3^7; /* P3.7 : no use */
/* ======================== */
/* ======================== */
sbit INB=ACC^0;
sbit FSDA=ACC^3;
sbit OUTB=ACC^7;
char bdata flag;
/* ======================== */
uint data XCNT; /* X - Axis Counter */
uint data YCNT; /* Y - Axis Counter */
/* ======================== */
/* ======================== */
void delay1(void);
void delay2(void);
void delay1s(void);
void clr_wdt(void);
void init_89C51(void);
/* ======================== */
/* ************************ */
/* ======================== */
void delay1(void)
{
uchar data i;
for(i=0;i<=3;i++)
{
clr_wdt();
}
}
/* ======================== */
void delay2(void)
{
uchar data i;
for(i=0;i<=20;i++)
{
clr_wdt();
}
}
/* ======================== */
void delay1s(void)
{
uint data i;
for(i=0;i<=10000;i++)
{
clr_wdt();
}
}
/* ======================== */
void clr_wdt(void) /* Clear Watchdog */
{
uchar i;
CWDT=1; /* CWDT = P1.7 = 1 */
for(i=0;i<=5;i++)
{;}
CWDT=0; /* CWDT = P1.7 = 0 */
}
/* ======================== */
/* ************************ */
/* ======================== */
void init_89C51(void)
{
P1=0x00; /* P1 : Port1 is Output */
P3=0x00; /* P3 : Port3 is Output */
XZERO=1; /* XZERO = P1.3 = 1 : input */
XZERO=1; /* YZERO = P1.4 = 1 : input */
XINT=1; /* XINT = P3.3 = 1 : input */
YINT=1; /* YINT = P3.2 = 1 : input */
XSIG=1; /* XSIG = P3.4 = 1 : input */
YSIG=1; /* YSIG = P3.5 = 1 : input */
IE=0x00; /* IE : EA,-,-,ES,ET1,EX1,ET0,EX0 */
TCON=0x00; /* TCON : TF1,TR1,TF0,TR0,IE1,IT1.IE0,IT0 */
IT0=1;
IT1=1; /* IT0 & IT1 = 1 : INT0 & INT1 fall edge Interrupt */
TMOD=0x11; /* TMOD : GATE1,C/T1,M11,M10,/ GATE0,C/T0,M01,M00 */
TH0=0x00; /* T1 & T0 : Work in Timer , 16 Bit Timer Mode */
TL0=0x00;
TH1=0x00;
TL1=0x00;
IE=0x85; /* EA = EX1 = EX0 = 1 */
EX0=0; /* Leak Current Interrupt */
EX1=0; /* Over Temperature Interrupt */
EA=0;
}
/* ======================== */
void init_variable(void)
{
XCNT=0; /* X - Axis Counter */
YCNT=0; /* Y - Axis Counter */
TH1=0x00; /* EC78H = 65536 - 5000 = 10ms TIMER */
TL1=0x00; /* 5000 * 2us = 10 000us = 10ms */
TMOD=0x00;
TR0=0;
TR1=0;
ET0=0;
ET1=0;
IT0=1; /* INT0 : Fall edge interrupt */
IT1=1; /* INT1 : Fall edge interrupt */
EX0=1;
EX1=1;
EA=1;
}
/* ======================== */
/* ************************ */
/* ======================== */
void y_counter(void) interrupt 0
{
XINT=1; /* XINT = P3.3 = 1 : input */
YINT=1; /* YINT = P3.2 = 1 : input */
XSIG=1; /* XSIG = P3.4 = 1 : input */
YSIG=1; /* YSIG = P3.5 = 1 : input */
XZERO=1; /* XZERO = P1.3 = 1 : input */
XZERO=1; /* YZERO = P1.4 = 1 : input */
if(YSIG==1)
{
YCNT=YCNT+1;
if(YCNT>99)
{
YCNT=0;
}
}
else
{
if(YCNT>=1)
{
YCNT=YCNT-1;
}
else
{
YCNT=99;
}
}
}
/* ======================== */
void timer0(void) interrupt 1
{ /* T/C0 Interrupt :2 MIN Timer for Clean */
}
/* ======================== */
void x_counter(void) interrupt 2
{ /* INT1 : Water Temperature over */
XINT=1; /* XINT = P3.3 = 1 : input */
YINT=1; /* YINT = P3.2 = 1 : input */
XSIG=1; /* XSIG = P3.4 = 1 : input */
YSIG=1; /* YSIG = P3.5 = 1 : input */
XZERO=1; /* XZERO = P1.3 = 1 : input */
XZERO=1; /* YZERO = P1.4 = 1 : input */
if(XSIG==1)
{
XCNT=XCNT+1;
if(XCNT>99)
{
XCNT=0;
}
}
else
{
if(XCNT>=1)
{
XCNT=XCNT-1;
}
else
{
XCNT=99;
}
}
}
/* ======================== */
void timer1(void) interrupt 3
{ /* T/C1 Interrupt : 10ms Timer */
}
/* ======================== */
/* ======================== */
void transmit_xy(void) /* RS-232 Transmit */
{
}
/* ======================== */
/* ************************ */
/* ======================== */
void main(void)
{
init_89c51();
init_variable();
while(1)
{
transmit_xy();
}
}
/* ======================== */
/* ========= END ========== */
/* ======================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -