|
89c51中断的问题~~~~~~~麻烦大家帮我看看哈
[复制链接]
请帮各位帮我看看为什么interrupt0总是不被执行?当高电平进来时,interrupt0开始执行,同时定时器开始定时,直到下一个高电平进来,定时也结束,这样可以吗?请各位大侠帮忙修改下,谢谢了~~~~我实在不太明白为什么了
#include"at89x51.h"
#include"stdio.h"
#include"stdlib.h"
#define timer 2000000//晶振12MHz
typedef unsigned long ulong;
typedef unsigned int uint;
typedef unsigned char uchar;
ulong count; //计数器
sfr CKCON = 0x8f;
void delay(uchar time);
void WriteP1_0(uchar nowbit);
void WriteData(uchar addr,uchar pos,uchar dp);
void WriteLcdData(ulong number);
/*对使用了的端口及寄存器进行初始化,在转速仪中用到了以下端口:
P3.1(TXD)口用作lcd的DATA输入口;P1.1作为lcd的片选控制端;P1.0用着;T0、T1、UINT0、UINT1都接入到方波信号输入端;
X1、X2用作两分频的时钟信号输入;RD与P1.5用来控制输出频率或者转速*/
void reg_init()
{
ET0 = 1;
CKCON = 1; //6时钟模式
TF1 = 0x1;
P1_0 = 0X0; // DATA
P1_1 = 0X1; // /WR
P1_2 = 0X1; // /CS选通端
TCON = 0XFE;
EA = 1;
// TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-nowbit reload */
}
/*UINT count_speed()
{
UINT speed;
UINT frequency = 0; //频率
speed = frequency*60;
return speed;
}*/
uchar flag = 0;
ulong count1 = 0; //计算计数器溢出的次数
void time0(void) interrupt 1
{
if(flag == 0)
{
TR0 = 0;
TH0 = 0x00; //定时0.002ms
TL0 = 0x20;
count1++;
ET0 = 0; //允许定时器0中断
TR0 = 1; //启动定时器/计数器0
}else{TR0 = 0;}
}
void t_int0(void) interrupt 0
{
TR0 =1;
flag = 1;
//TR0 = 0;//关闭计数器0
//count1 = 0;;
// ET1 = 1; //允许定时器1中断
}
ulong count_frequency()
{
//UINT time; //转一圈的时间
//UINT tcount = 0;
//tcount = time0_count();
//time = count / timer;
ulong frequency; //频率
count = TH0*256+TL0+count1*65536;
frequency = (timer*10*60)/count;
return frequency;
}
void main()
{
void reg_init();
volatile ulong frequency; //频率
// UINT roundspeed = 0; //转速
TMOD = (TMOD & 0x01); //定时器0工作模式 方式一
while(1)
{
if(flag == 0)
{
EX0 = 1;
IE = 0X82;
IE0 = 1;
IT0 =1;
frequency = count_frequency();
TR0 = 1;
}
else if(flag == 1)
{
EX0 = 0;
count1 = 0;
flag = 0;
}
// roundspeed = count_speed();
WriteLcdData(frequency);
}
|
|