sanjusony
Newbie level 5
- Joined
- Dec 2, 2015
- Messages
- 8
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,283
- Location
- Kerala. India
- Activity points
- 1,370
// Program(For PIC16F882 MP lab X IDE) is not working on Hardware even though its working in simulation.:bang::bang::bang::bang:
Description
Description
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 //*********************************************************************************************************// /* * File : ExtIntrToggle.c * * IDE : MPlab X IDE /* // Program to check led toggle on external interrupt on RB0 using push button and // led at RC1 #include <pic.h> //Use this to include the device header for your PIC. //In our case, this will include pic16882.h. #define _XTAL_FREQ 20000000 //20MHz, which is default //This is used by the compiler to calculate how many //instructions to delay in the calls to __delay_ms(). #define LED1 PORTCbits.RC3 //Normal led blinking check #define LED1_TRIS TRISCbits.TRISC3 #define LED2 PORTCbits.RC1 // Interrupt Led blinking check #define LED2_TRIS TRISCbits.TRISC1 void interrupt isr() { if(INTCONbits.INTF == 1) { // //reset the interrupt flag INTCONbits.INTF = 0; LED2 = ~LED2; //flip the bit //The ~ (tilde) is the complement operator } } int main() { TRISA = 0xFF; //set all digital I/O to inputs TRISB = 0xFF; TRISC = 0x00; ANSEL = 0x00; //disable all analog ports ANSELH = 0x00; WPUB = 0x00; IOCB = 0X00; LED1_TRIS = 0; //LED1 is an output LED2_TRIS = 0; //LED2 is an output INTCONbits.INTF = 0; //reset the external interrupt flag OPTION_REGbits.INTEDG = 1; //interrupt on the rising edge INTCONbits.INTE = 1; //enable the external interrupt INTCONbits.GIE = 1; //set the Global Interrupt Enable /////////////////////// // Main Program Loop // /////////////////////// while(1) { LED2 = 1; //Flash LED1 __delay_ms(500); LED2 = 0; __delay_ms(500); } return 0; } //*********************************************************************************************************//