WStevens_sa
Member level 2
- Joined
- Jan 5, 2011
- Messages
- 47
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Location
- South Africa
- Activity points
- 1,695
Hi all
Please can you help me with the following. I am newbie to MCU's and C. I am familiar with programming ASP.NET, VB, C# and Java as a Microsoft developer. I have read the datasheet and I cannot figure it out.
I have the following project. PORTA flashes LEDS all outputs. I want to interrupt this and output to PORTD and delay for 2 sec and then return to PORTA flashing. Is the code below correct.
void interrupt(void) {
if(INTCON.INTF == 1)
{
PORTD = 0x01; //To see if interrupt is triggered
Delay_ms(2000);
INTCON.INTF = 0; //You HAVE to clear interrupt flag
}
}
void main()
{
INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.PEIE = 0; //Disable all unmasked peripheral interrupt
OPTION_REG.INTEDG = 1; //Interrupt on rising edge
PORTA = 0x00; /*set RA0-RA5 low */
TRISA = 0x00; /*set PORTA to output*/
TRISD = 0x00; /*set PORTD to output*/
do{ //Flash all LED's
PORTA = ~PORTA;
Delay_ms(100);
}while(1);
}
Please can you help me with the following. I am newbie to MCU's and C. I am familiar with programming ASP.NET, VB, C# and Java as a Microsoft developer. I have read the datasheet and I cannot figure it out.
I have the following project. PORTA flashes LEDS all outputs. I want to interrupt this and output to PORTD and delay for 2 sec and then return to PORTA flashing. Is the code below correct.
void interrupt(void) {
if(INTCON.INTF == 1)
{
PORTD = 0x01; //To see if interrupt is triggered
Delay_ms(2000);
INTCON.INTF = 0; //You HAVE to clear interrupt flag
}
}
void main()
{
INTCON.GIE = 1; //Enable Global Interrupt
INTCON.INTE = 1; //Enable RB0/INT external Interrupt
INTCON.PEIE = 0; //Disable all unmasked peripheral interrupt
OPTION_REG.INTEDG = 1; //Interrupt on rising edge
PORTA = 0x00; /*set RA0-RA5 low */
TRISA = 0x00; /*set PORTA to output*/
TRISD = 0x00; /*set PORTD to output*/
do{ //Flash all LED's
PORTA = ~PORTA;
Delay_ms(100);
}while(1);
}