这段代码通过计算特定时间延迟的INT0外部中断数来写入显示速度,以mph为单位工作,即只显示“读出:” 然后什么也没有。 我在c51开发工具中看到了8051衍生品页面。它告诉我没有必要的信息。 http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.kui0002a/c51_dv_8051deriv.htm 我不明白为什么有时写它 void ex0_isr(void)interrupt 0 使用2
有人可以帮我理解哪里错了吗? 模拟工作正常。
//Calculating speed
#include <reg51.h>
#include <string.h>
void read(unsigned int q);
void delay(void);
void delay1(unsigned long int time);
void SerInit();
void SerTx(unsigned char x);
void SerTx_str(unsigned char msg[]);
unsigned char msg[]="Speed= ";
unsigned char buffer[12];
sbit in_port=P3^2;
sbit EDGT=TCON^0;
unsigned char volatile count;
unsigned int q;
void ex0_isr(void) interrupt 0
{
count++;
}
void timer0(void) interrupt 1
{
TR0=0;
{
void main()
{
SerInit(); //serial initialisation
SerTx_str("Read out:"); //send string to hyperterminal
SerTx('\n');
delay1(20); //delay using loop
SerTx('\r');
in_port=1; //input port pin
EDGT=1; //make IT0 =1 an edge triggered
while(1)
{
count=0; //initialize count
IE=IE|0x81; //enable global and INT0
delay(); //delay using timers for a time to measure count
SerTx_str("Dbg"); //check
IE=IE&0xFE; //disable INT0
q=count;
read(q); //function called for ASCII conversion
SerTx_str(msg); //send message to terminal
SerTx_str(buffer); // send count to terminal
SerTx('\n');
delay1(2000);
SerTx('\r');
}
}
void read( unsigned int q)
{
unsigned int d1,d2,d3;
d1=q%10;
q=q/10;
d2=q%10;
d3=q/10;
buffer[0]=d3+'0';
buffer[1]=d2+'0';
buffer[2]=d1+'0';
}
void delay(void)
{
unsigned int i;
for(i=0;i<45;i++)
{
TMOD=0x01; //Timer 0, mode1(16 bit)
TL0=0xFD; //load TL0
TH0=0x4B; //load TH0
IE=IE|0x02; //enable Timer 0 interrupt
TR0=1; //turn on Timer 0
do
{
q=count;
}
while(TF0==0);
//if there's overflow ie, TF=1, goto interrupt 1
//
//> TMOD=0x01;
> TL0=0xFD;
> TH0=0x4B;
> TR0=1;
> while(TF==0);
> TR0=0;
> TF0=0; // previous code
}
}
答案 0 :(得分:0)
我的猜测是通过这样做:
IE=0x81;
您不小心禁用了计时器中断,这意味着您的delay()函数永远不会返回。我怀疑你可能想做这样的事情:
IE = IE | 0x01; // enable INT0
delay(); // delay using timers for a time to measure count
IE = IE & 0xFE; // disable INT0