//Student Name:Ooi Wei Sheng
#include <pic.h>
/*Lab1.c - Turn ON PORT B 0 LED*/
__CONFIG(0x3f38);
delay1s()
{
for(int i=0;i<30000;i++)
{
NOP();
}
}
void interrupt isr(void)
{
if(INTF)
{
PORTA =0x00;
INTF = 0; /* Clear interrupt flag */
}
}
main()
{
CMCON=0b00000111;
TRISB=0;
PORTB=0;
TRISA=0xFF;
INTF =1;
INTE=1;
GIE =1;
PEIE=0;
INTEDG=1;
if(RB1)
{
while(1){
PORTA=0x01;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x02;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x04;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x08;
delay1s();
PORTA=0x00;
delay1s();
}
if(RB2)
{
while(1){
PORTA=0x08;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x04;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x02;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x01;
delay1s();
PORTA=0x00;
delay1s();
}
}
}
}
Homework requirement:
---press RB1 , led will light up from sequence start from porta0 to porta3 and the cycle repeats
press RB0 to stop the sequence
---press RB2 , led will light up from sequence start from porta3 to porta0 and the cycle repeats
press RB0 to stop the sequence
hi all , i have a problem of understanding the interrupt , based on this code, if i press RB0 switch , my portA will become zero , and i will exit the interrupt function , but then what wil the program do? it will start all over again?because from the homework requirment , i am suppose to stop all the lighting of led once the interrupt switch is pressed, but i am afraid the program might continue to carry out its previous function after exiting the interrupt, can someone pls guide and explain to me ?thank you
#include <pic.h>
/*Lab1.c - Turn ON PORT B 0 LED*/
__CONFIG(0x3f38);
delay1s()
{
for(int i=0;i<30000;i++)
{
NOP();
}
}
void interrupt isr(void)
{
if(INTF)
{
PORTA =0x00;
INTF = 0; /* Clear interrupt flag */
}
}
main()
{
CMCON=0b00000111;
TRISB=0;
PORTB=0;
TRISA=0xFF;
INTF =1;
INTE=1;
GIE =1;
PEIE=0;
INTEDG=1;
if(RB1)
{
while(1){
PORTA=0x01;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x02;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x04;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x08;
delay1s();
PORTA=0x00;
delay1s();
}
if(RB2)
{
while(1){
PORTA=0x08;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x04;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x02;
delay1s();
PORTA=0x00;
delay1s();
PORTA=0x01;
delay1s();
PORTA=0x00;
delay1s();
}
}
}
}
Homework requirement:
---press RB1 , led will light up from sequence start from porta0 to porta3 and the cycle repeats
press RB0 to stop the sequence
---press RB2 , led will light up from sequence start from porta3 to porta0 and the cycle repeats
press RB0 to stop the sequence
hi all , i have a problem of understanding the interrupt , based on this code, if i press RB0 switch , my portA will become zero , and i will exit the interrupt function , but then what wil the program do? it will start all over again?because from the homework requirment , i am suppose to stop all the lighting of led once the interrupt switch is pressed, but i am afraid the program might continue to carry out its previous function after exiting the interrupt, can someone pls guide and explain to me ?thank you