本帖最后由 lbb_1112 于 2014-5-23 11:05 编辑
编码器经过了一个D触发器,INT0加,INT1减小,T0做定时器算速度,我写的程序仿真不对,发出来都是0,求指教哪个地方出错了,
如果要一定数的脉冲再发送怎么加入?
#include <Reg52.h>
#include <stdio.h>
#define uint unsigned int
#define uchar unsigned char
uint time, counter,shen,su;
void init()
{ TMOD = 0x21; // 00100001,T1在模式2,T0在模式1,都是定时器方式,
TH1 = 0xfd;
TL1 = 0xfd;
SCON=0x50;
TR1 = 1; // 器动T1,
EA=1; // 总中断开,
// ES=1; //串行叫断开
TH0=0xfc; //定时器初值
TL0=0x67;
TR0=1; //T0启动
ET0=1; //T0允许中断
EX1=1; //外部中断1允许
IT1=1; // 下降沿触发
IT0=1; // 下降沿触发
}
void main(void)
{
init();
while(1)
{
SBUF=shen/256;
while(!TI );
TI=0;
SBUF=shen%256;
while(!TI );
TI=0;
SBUF=su/256;
while(!TI );
TI=0;
SBUF=su%256;
while(!TI );
TI=0;
}
}
void ex1_int0() interrupt 0
{
counter++;
time++;
if(counter==4)
{shen++;
counter=0;
if(shen==99999)
{ shen=0;
}
}
}
void ex2_int1(void) interrupt 2
{counter++;
time++;
if(counter==4)
{shen--;
counter=0;
if(shen==0)
{shen=9999;}
}
}
void T0js(void) interrupt 1
{ int t0s;
t0s++;
if(t0s==300)
{
t0s=0;
su=time*5*60;
time=0;
TH0=0xfc;
TL0=0x67;
}
} |