- Joined
- Jan 22, 2008
- Messages
- 53,351
- Helped
- 14,796
- Reputation
- 29,879
- Reaction score
- 14,335
- Trophy points
- 1,393
- Location
- Bochum, Germany
- Activity points
- 302,083
No. An interrupt function is assigned to a specific interrupt by the interrupt number. You have only interrupt 1 (Timer 0) and no external interrupt function in your code.In my program u can see rpm_start subroutine, in this routine i am enabling Timer 0, and my Timer 0 is used as external interrupt following edge, right?
#include <AT89X55.H>
#include <MATH.H>
//#include <lcd.h>
sfr lcd_data_pin=0xA0; // data port P2
sbit rs=P3^7; // Register select pin
sbit rw=P3^6; // Read write pin
sbit en=P3^5; // Enable pin
unsigned long c,d,frequency,rpm_count,rpm;
unsigned char d1,d2,d3,d4,d5,pulse_ov,pulse_count,lo_count;
void delay(unsigned int msec) //delay function
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void lcd_command(unsigned char comm) // function to send command to LCD
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(1);
en=0;
}
void lcd_data(unsigned char disp) // function to send data on LCD
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
lcd_dataa(unsigned char *disp) // function to send string to LCD
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
void lcd_ini() //Function to inisialize the LCD
{
lcd_command(0x38);
delay(5);
lcd_command(0x0C);
delay(5);
}
void bitsep16()
{
d = c/10;
d1 = c%10; // LSB
c = d/10;
d2 = d%10; // LSB-1
d = c/10;
d3 = c%10; // LSB-2
c = d/10;
d4 = d%10; // MSB+1
d5 = d/10; // MSB
d1 = d1+0x30;
d2 = d2+0x30;
d3 = d3+0x30;
d4 = d4+0x30;
d5 = d5+0x30;
}
void lcd()
{
// c = rpm;
bitsep16();
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x52;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x50;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4D;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void ISR_Timer0(void) interrupt 1
{
TF0 = 0x00;
pulse_count = pulse_count++;
if (pulse_count == 1)
{
pulse_ov = 0x00;
TH1 = 0x00;
TL1 = 0X00;
TR1 = 1;
}
else
{
TR1 = 0;
TR0 = 0;
rpm_count = (65536*pulse_ov)+(256*TH1)+TL1;
rpm = ((0x36ee8000/rpm_count)*0x3c)/0x3e8;
pulse_count = 0;
pulse_ov = 0;
c = rpm;
return;
}
}
void ISR_Timer1(void) interrupt 3
{
TF1 = 0;
pulse_ov = ++pulse_ov;
return;
}
void rpm_start()
{
pulse_ov = 0x00;
pulse_count = 0x00;
TH1 = 0x00;
TL1 = 0x00;
ET1 = 1;
ET0 = 1;
EA = 1;
TR0 = 1;
}
void main()
{
P1 = 0x00;
lcd_ini();
TMOD = 0x16;
T2CON = 0x01;
IT0 = 0;
// IE0 = 1;
EX0 = 1;
EA = 1;
rpm_start();
lcd();
}
You have been asking about external interrupt rather than counter interrupt. I see now that Timer0 is configured as counter. It will trigger the interrupt when the counter overflows from all '1' to '0', not on each counter input event.But interrupt 1 is only enable when on that pin following edge is occur and as counter. so when following edge is occur on Int 0 pin at that time PC is directly go to interrupt sub routine, right?
Which global variable are you taken & what it is getting highlight it, then i can understand your problem.
#include <AT89X55.H>
#include <MATH.H>
//#include <lcd.h>
sfr lcd_data_pin=0xA0; // data port P2
sbit rs=P3^7; // Register select pin
sbit rw=P3^6; // Read write pin
sbit en=P3^5; // Enable pin
[COLOR="#FF0000"]unsigned long c,d,frequency,rpm_count,rpm;[/COLOR]
unsigned char d1,d2,d3,d4,d5,pulse_ov,pulse_count,lo_count;
void delay(unsigned int msec) //delay function
{
int i,j;
for(i=0;i<msec;i++)
for(j=0;j<1275;j++);
}
void lcd_command(unsigned char comm) // function to send command to LCD
{
lcd_data_pin=comm;
en=1;
rs=0;
rw=0;
delay(1);
en=0;
}
void lcd_data(unsigned char disp) // function to send data on LCD
{
lcd_data_pin=disp;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
lcd_dataa(unsigned char *disp) // function to send string to LCD
{
int x;
for(x=0;disp[x]!=0;x++)
{
lcd_data(disp[x]);
}
}
void lcd_ini() //Function to inisialize the LCD
{
lcd_command(0x38);
delay(5);
lcd_command(0x0C);
delay(5);
}
void bitsep16()
{
[COLOR="#FF0000"]d = c/10;[/COLOR]
d1 = c%10; // LSB
c = d/10;
d2 = d%10; // LSB-1
d = c/10;
d3 = c%10; // LSB-2
c = d/10;
d4 = d%10; // MSB+1
d5 = d/10; // MSB
d1 = d1+0x30;
d2 = d2+0x30;
d3 = d3+0x30;
d4 = d4+0x30;
d5 = d5+0x30;
}
void lcd()
{
// c = rpm;
bitsep16();
lcd_command(0xC0);
delay(5);
lcd_data_pin=0x52;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x50;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x4D;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x3a;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d4;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d3;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d2;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=d1;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
lcd_data_pin=0x20;
en=1;
rs=1;
rw=0;
delay(1);
en=0;
}
void ISR_Timer0(void) interrupt 1
{
TF0 = 0x00;
pulse_count = pulse_count++;
if (pulse_count == 1)
{
pulse_ov = 0x00;
TH1 = 0x00;
TL1 = 0X00;
TR1 = 1;
}
else
{
TR1 = 0;
TR0 = 0;
rpm_count = (65536*pulse_ov)+(256*TH1)+TL1;
rpm = ((0x36ee8000/rpm_count)*0x3c)/0x3e8;
pulse_count = 0;
pulse_ov = 0;
[COLOR="#FF0000"]c = rpm;[/COLOR]
return;
}
}
void ISR_Timer1(void) interrupt 3
{
TF1 = 0;
pulse_ov = ++pulse_ov;
return;
}
void rpm_start()
{
pulse_ov = 0x00;
pulse_count = 0x00;
TH1 = 0x00;
TL1 = 0x00;
ET1 = 1;
ET0 = 1;
EA = 1;
TR0 = 1;
}
void main()
{
P1 = 0x00;
lcd_ini();
TMOD = 0x16;
T2CON = 0x01;
IT0 = 0;
// IE0 = 1;
EX0 = 1;
EA = 1;
rpm_start();
lcd();
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?