#include "Exter0.h"
#include "Public.h"
#include<STC89C5xRC.H>
void init_Exter0()
{
//设置INT0
IT0=1;//跳变沿出发方式(下降沿)
EX0=1;//打开INT0的中断允许。程序中断0口上电就运行
EA=1; //IE中断允许寄存器
}
#include<STC89C5xRC.H>
#include "24c02.h"
#include <stdio.h>
#include "Lcd1602.h"
#include "4x4keyboard.h"
#include "intrins.h"
#include "Exter0.h"
#include "Exter1.h"
#include"Timer0_ZJ.h"
//#include<reg52.h>
#include <absacc.h>
#include "Public.h"
#include "auto485SF-ZJ.h"
#define uint_long unsigned long int
sbit S1=P1^0;//测试按钮
sbit S2=P1^1;//临时测试
sbit M1ZZ=P2^0;//电机控制-正转
sbit M1FZ=P2^1;//电机控制-反转
sbit M2ZZ=P2^2;//电机控制-正转
sbit M2FZ=P2^3;//电机控制-反转
uint_long M1_pluse_val,M2_pluse_val;//电机运转发出的脉冲数
uint M1_pluse_val_read,M2_pluse_val_read;//电机单量脉冲数--根据机械设计的行程换算存入24C02中的数据
uchar x,y,x1,y1;
uchar a,a1,b,b1;
uint m1,yyy,m2,yyy1;
void main(void)
{
P2=0;//所有电机不工作
LCD_Init();//LCD初始化
LCD_ShowString(1,1,"At ");
LCD_ShowString(2,1,"Send: ");
delay(500);
timer0_init();//定时器0初始化
init_Exter0();//外部中断0初始化
init_Exter1();//外部中断1初始化
while(1)
{
if(S1==0) M1ZZ=1;else M1ZZ=0;
if(S2==0) M1FZ=1;else M1FZ=0;
LCD_ShowNum(2,7,yyy,3);
LCD_ShowNum(2,11,yyy1,3);
}
}
void timer0() interrupt 1
{
uint i;
i++;
TH0=(65536-46080)/256;
TL0=(65536-46080)%256;
if(i==20)
{
TR0=0;
i=0;
yyy=m1;
yyy1=m2;
// LCD_ShowNum(2,7,m1,3);
// LCD_ShowNum(2,11,yyy1,3);
TR0=1;
}
}
void Exter0() interrupt 0
{
if(S1==0) {M1_pluse_val++; m1=M1_pluse_val;}
if(S2==0) {M1_pluse_val--; m1=M1_pluse_val;}
m1=(M1_pluse_val/10);
}
void Exter1() interrupt 2
{
M2_pluse_val++;
m2=(M2_pluse_val/10);
} |