RishabhG
Member level 3
- Joined
- Aug 10, 2012
- Messages
- 65
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,815
I am using PIC16F877A with a 16MHz crystal. MPLAB v8.4 HiTech C compiler
I have written the following code (Hope it is self-explanatory)
But the control stays always at the PORTB change interrupt ISR. Please help me find the mistake I am doing.
I have written the following code (Hope it is self-explanatory)
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 /* This program does the following: Ext int : Start Running the motor Port b int : Stop running the motor Author : RKG Date: 18/03/13 */ #include<htc.h> __CONFIG(0x2F0A); unsigned char motor_status; void delay() { for(int i=0;i<750;i++); } void run_motor() { PORTC=0x09; PORTC=0x08; // for half step sequence delay(); PORTC=0x0C; PORTC=0x04; // for half step sequence delay(); PORTC=0x06; PORTC=0x02; // for half step sequence delay(); PORTC=0x03; PORTC=0x01; // for half step sequence delay(); } void interrupt ISR() { if(INTF==1) { RB1=1; motor_status=1; //run INTF=0; } if(RBIF == 1) { RB1=0; //turn off run LED RB2=1; //glow stop LED motor_status=0; RBIF=0; } } void main() { TRISC=0; //motor o/p port RBPU=0; TRISB=0xF0; //i/p port PORTB & =0xF0; GIE=1; //global int enable INTE=1; //external int enable INTEDG=0; //neg edge triggered RBIE=1; //PORTB change int enable while(1) { if(motor_status==1) { run_motor(); } } }
But the control stays always at the PORTB change interrupt ISR. Please help me find the mistake I am doing.