Thanks I have written code for hardware interrupt. I have tested on simulator it's work for meOn every interrupt, it will check the button once and turn the LED on or off accordingly. It will do this as long as the interrupt is enabled and the timer is running.
#include<reg51.h>
#define Pressed 1
sbit LED = P1^0; // LED connected to P1.0
sbit Button = P3^2; // Switch button connected to P3.2
void initialize_Port(void); //Function declarations
void initialize_Port(void) // Make all ports zero
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
void main(void) // Main function
{
initialize_Port();
Button = Pressed ;
EX0 = 0; //Disable external interrupt INT0
IT0 = 1; //Edge triggered interrupt mode (Neg Edge)
EX0 = 1; //Enable external interrupt INT0
EA = 1; //Enable global interrupts
while(1)
{
}
}
void Hardware_ISR(void) interrupt 0
{
LED = ~LED; // Toggle LED pin
}
No. When interrupted, the processor disables all other interrupts of the same priority. Priority is set by the IP register. If all sources of interrupts are at the same priority, only one at a time is processed.Do I need to disable external interrupt in ISR ?
Did you check my program?. I think both of my programs are correct Do I need to improve in program somewhere ?If all sources of interrupts are at the same priority, only one at a time is processed.
void delay(void)
{
int x = 10500; 11.89uS
while(x--); // So 10500 * 11.89uS = nearly 125mS
}
I have set all the ports to 0 in main function at starting. Then I am setting button port 3.2. I think if I don't set port Pin 3.2 then MCU will not get the signal.In #22, why are you doing button=pressed if the LED is toggled by interrupt?.
OK. But in that case, you should just unit the port with:I have set all the ports to 0 in main function at starting. Then I am setting button port 3.2. I think if I don't set port Pin 3.2 then MCU will not get the signal.
In below program I have set two hardware interrupts. Which of these two interrupts is responded to first?.Priority is set by the IP register. If all sources of interrupts are at the same priority, only one at a time is processed.
#include<reg51.h>
sbit LED1 = P1^0; // LED 1 connected to P1.0
sbit LED2 = P1^1; // LED 2 connected to P1.1
sbit Button1 = P3^2; //Switch button 1 connected to P3.2
sbit Button2 = P3^3; // Switch button connected to P3.3
void initialize_Port(void);
void initialize_Port(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0xOC; // Make P3.2 and P3.3 pin Highy only
}
void main(void)
{
initialize_Port();
EX0 = 0; //Disable external interrupt INT0
EX1 = 0; //Disable external interrupt INT1
IP = 0x01; // assign High priority
IT0 = 1; //Edge triggered interrupt mode (Neg Edge)
EX0 = 1; //Enable external interrupt INT0
EX1 = 1; //Enable external interrupt INT1
EA = 1; //Enable global interrupts
while(1);
}
void Hardware1_ISR(void) interrupt 0
{
LED1 = ~LED1; // Toggle LED1 pin
}
void Hardware2_ISR(void) interrupt 1
{
LED2 = ~LED2; // Toggle LED2 pin
}
It would be P3 = 00001100 binary = 0x0c Hexa decimalRecheck the init for P3.
The higher priority interrupt takes precidence over the low priority one. If it comes when servicing the low priority interrupt, the low priority interrupt processing will be suspended until the high priority interrupt service is complete. Also, a low priority interrupt will not be serviced if any high priority interrupts are being serviced.
I would also like to work on real hardware but I don't have 8051 board right now. I'm trying to test 8051's program on simulator. I am planning to purchase ARM Board. Very soon I will start working on real hardwareSimulators are fine but going to real hardware you will find that the interrupt pins need to be tied to +V and pulled to gnd by the switches..
#include<reg51.h>
sbit LED = P1^0; // LED connected to P1.0
sbit Button = P3^3; // Switch button connected to P3.3
void initialize_Port(void); //Function declarations
void initialize_Port(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x08; // Make P3.3 pin high
}
void main(void)
{
initialize_Port();
EX1 = 0; //Disable external interrupt INT1
IT0 = 1; //Edge triggered interrupt mode (Neg Edge)
EX1 = 1; //Enable external interrupt INT1
EA = 1; //Enable global interrupts
while(1)
{
}
}
void Hardware_ISR(void) interrupt 1
{
LED = ~LED; // Toggle LED pin
}
EXTERNAL INT 1 2You have specified the wrong interrupt vector for IE1.
void Hardware_ISR(void) interrupt 2
{
LED = ~LED; // Toggle LED pin
}
Here is complete code.Post #33, line 23.
#include<reg51.h>
sbit LED1 = P1^0; // LED 1 connected to P1.0
sbit LED2 = P1^1; // LED 2 connected to P1.1
sbit Button1 = P3^2; //Switch button 1 connected to P3.2
sbit Button2 = P3^3; // Switch button connected to P3.3
void initialize_Port(void);
void initialize_Port(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x0c; // Make P3.2 and P3.3 pin Highy only
}
void main(void)
{
initialize_Port();
EX0 = 0; //Disable external interrupt INT0
EX1 = 0; //Disable external interrupt INT1
IP = 0x01; // assign High priority
IT0 = 1; //Edge triggered interrupt mode (Neg Edge)
IT1 = 1; //Edge triggered interrupt mode (Neg Edge)
EX0 = 1; //Enable external interrupt INT0
EX1 = 1; //Enable external interrupt INT1
EA = 1; //Enable global interrupts
while(1);
}
void Hardware1_ISR(void) interrupt 0
{
LED1 = ~LED1; // Toggle LED1 pin
}
void Hardware2_ISR(void) interrupt 2
{
LED2 = ~LED2; // Toggle LED2 pin
}
If the goal was to play with the external interrupts and it works in the sim then OK by me.if all look's like correct then Next I will try to write code for serial interrupt
I am not thinking about the GPS programming. I am trying to do something simple like I will send the data from computer terminal to microcontroller and this data will display on LCD screen. I have to use uart and I want use serial interrupt. because my goal is to learn about serial interrupt. this is what I am thinking. should I do this. Is there any other way easier than this ?So about the serial interrupt. Before going on, tell us why you would want to do that.
Give it some thought.
Sure. Implement the UART receiver then make your main routine just send the characters back to the terminal. Simple and that avoids the additional complexity of the LCD code. That can come later.I am not thinking about the GPS programming. I am trying to do something simple like I will send the data from computer terminal to microcontroller and this data will display on LCD screen. I have to use uart and I want use serial interrupt. because my goal is to learn about serial interrupt. this is what I am thinking. should I do this. Is there any other way easier than this ?
by Jake Hertz
by Aaron Carman
by Jake Hertz
by Jeff Child