pipec
Joined: 21 May 2010 Posts: 1
|
PORTB Interrupt |
Posted: Fri May 21, 2010 3:10 pm |
|
|
Hi!
I am new in programming PIC in C, but maybe my code will be usefull.
I have tested it with proteus. If you like to make interrupt both edge (H2L and L2H) just take off the variable "d". I hope you like it.
Code: |
#include <16F877.h>
#include "F:\progik\Programozás\PIC\saját_c\Interrupt\PIC16F877_registers.h"
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=20000000)
BYTE blink = 0;
byte c,d;
#int_rb
void button_isr() {
c=portb;
d=~d;
if (d!=0){
if (!blink)
blink=1;
else
blink=0;
}
}
void main() {
clear_interrupt(INT_RB);
enable_interrupts(INT_RB);
enable_interrupts(GLOBAL);
d=0;
trisd=0x00;
portd=0x00;
do {
if(blink){
output_high(PIN_D1);
delay_ms(500);
output_low(PIN_D1);
delay_ms(500);
}
} while (TRUE);
} |
|
|