Archives
-
[SOLVED] Need help on Interrupt
I am a beginner at programming microcontrollers in C using MPLABX and HI-TECH C
I am having a problem with a code that I made where 4 LEDs will blink one after another, and when an Interrupt is detected it should stop at the position where the LED is on and blink 3 times.
The problem that I am encountering is when I service the interrupt, the LED doesnt blink.
Here is my code:
Code:/*************************************************************************
*Description: LED Flash Interrupt *
* *
* Services an Interrupt when the external interrupt is asserted *
* *
* *
* Four LEDs blinks in succession until an interrupt is asserted where *
* it will blink in the specified LED for three times, and resumes after *
* ***********************************************************************
* Pin Assignments: *
* BUTTON – RB0 *
* *
* **********************************************************************/#include <htc.h>
/*CONFIGURATION*/
__CONFIG(FOSC_XT & CP_OFF & WDTE_OFF & PWRTE_ON);#define _XTAL_FREQ 4000000 //Crystal in Hz
/*PIN ASSIGNMENTS*/
#define BUTTON RB0 //BUTTON as RB0/*GLOBAL VARIABLES*/
unsigned char sPORTB; //Shadow copy of PORTB
unsigned char store_LED = 1; //Stores the LED value/*FUNCTION PROTOTYPING*/
void init();/*MAIN FUNCTION*/
void main()
{
init();
//Main Loop
for(;;)
{
__delay_ms(500); //Delay of 500ms
sPORTB = (1<<store_LED); //Turns on the LED on the position specified by store_LED
store_LED++; //Increments the value of Store LED
if(store_LED == 5) //If store_LED is 5
{
store_LED = 1; //RESET store_LED to 1
}
PORTB = sPORTB; //UPDATE PORTB
sPORTB = ~(1<<store_LED); //RESET the previous position of store_LED to 0
}
}void init()
{
TRISB = 0b11100001; //SET RB1 to RB4 as OUTPUTS
PORTB = 0b00000000; //SET PORTB to 0
sPORTB = 0b00000000; //SET Shadow of PORTB to 0/*CONFIGURE INTERRUPTS*/
INTEDG = 0; //Trigger on Falling Edge
INTE = 1; //ENABLE External Input
ei(); //ENABLE Global Interrupt
}void interrupt isr(void)
{
unsigned int led_count = 0; //led_count Variable
INTF = 0; //RESET Interrupt Flag
for(led_count=0;led_count <3;led_count++) //Repeat 3 times
{
__delay_ms(500); //Delay of 500ms
sPORTB ^= (1<<store_LED); //Toggles store_LED
}
}
.By the way, I am using the PIC16F84A microcontroller
Related Forum Messages
- Interrupt on Change Problem
- MikroEleKronika Timer 0 Problem
- Need help on pic16f690 stopwatch debug
- PIC18F46J50 Timer 0 Issue
- PIC16F887 Hardware Interrupt
- Button on interrupt. Need help
- PORTB Interrupt On Change (IOC) problem
- Interrupts on Port B not released – who can help?
- Using the WDT as an RTC on a Attiny10
- Interrupt programming doubt
- Atmega8 interrupt
- Can’t wake up from power down via int0 level interrupt
- Interrupt Issues, PIC12HV615 HI-TECH Compiler
- Ext Interrupt Blink LED
- Inteerupt programming doubt
- Problem with Timer1_Interrupt atmega8A
- External interrupt example
- ATtiny 45 and Timer interrupts
- Trouble controlling ports
- Someone help me with timer0. i m new to PIC
I am having a problem with implementing an IOC using the PIC16F84A where an LED should turn on when a push button is pressed. I can't seem to find as to what causes this problem, here is the code that I made. Code: #include <htc.h> /*CONFIGURATION*/ __CONFIG(FOSC_XT & WDTE_OFF & CP_OFF & PWRTE_OFF); /*PIN ASSIGNMENTS*/ #define BUTTON 4 #define bLED 0 /*GLOBAL VARIABLES*/ unsigned char sPORTB; //Create Shadow copy of PORTB /*FUNCTION PROTOTYPING*/ void init(); void toggle(); void main() { init(); ...Hi All, I'm trying to get my timer 0 interrupt to go in Mikro C Pro. I can't seem to get it going. Even with their examples. I looked over the SFR's and am pretty sure they're right. I'm programming a PIC18F46J50. Any ideas? Code: void INIT(void); unsigned int count = 0; unsigned int LED_COUNT = 10; void interrupt(){ if(INTCON.TMR0IF) { count = count + 1; INTCON.TMR0IF = 0; } } void main() { ADCON1 |= 0x0F; // Configure AN pins ...dear all, my stopwatch seems like not working. as for timing, it should be inside the interrupt loop together with my external interrupt (infrared sensor), * once the infrared sensor detect signal, the stopwatch will start to count, once detect again the stop watch will stop. based on my current code, it seems like when the infrared detect, the stopwatch will run , but when a second interrupt occur, the stopwatch cannot stop. May some one help to edit my code. i had already cleared all possible flag after each interrupt. #include ltpic.hgt #define _XTAL_FREQ 4000000L //__CONFIG (FOSC_INTRCIO amp WDTE_OFF amp PWRTE_ON ...Hi All, I"m new to Mikro C and can't get Timer 0 to count. I don't even enter my ISR. Must be something I'm overlooking. I've looked over my SFR's and those seem to be correct especially when looking at the examples provided for Timer 0 interrupts. Any have any ideas of where I'm coming short? Thanks Code: Select all void INIT(void); unsigned int count = 0; unsigned int LED_COUNT = 10; void interrupt(){ if(INTCON.TMR0IF) { count = count + 1; INTCON.TMR0IF = 0; } } void main() { ADCON1 |= 0x0F; ...Hi, I am trying to create a software for the alarm and alarm reset button. Here I use pic 16f88 microcontroller to to d this. I am using the RB0(hardware int) pin to read the input from one master microcontroller. So when ever the RB0 becomes High i wanna make PORTB.F2 is 1. and when ever the reset button connected to PORTB.F1 is pushed(from 1 to 0 transition) the alarm (PORTB.F2 ) should go 0 irrespective of the RB0 condition. SO here I am detecting the switch using button function and the external hardware interrupt to detect the alarm condition. [code][/* Signal at Rb0 Switch at Rb1 Alarm ...Hi. I try to remember how to work with PIC. The code below dont work. You have no idea where I make mistakes? It seems that not even enter the interrupt. So I think that it is set up wrong. But where? /************************************************************************ * Processor: 12F675 * * Demonstrates use of interrupt-on-change interrupts * * * * Toggles LED on GP4 * * when pushbutton on GP5 is pressed (high -gt low transition) * * * ************************************************************************* * * * Pin assignments: * * GP4 - indicator LED * * GP5 - pushbutton switch * * * ************************************************************************/ // Pin assignments #define nB_LED 4 #define nBUTTON 5 /***** GLOBAL VARIABLES *****/ unsigned char sGPIO; // shadow copy of GPIO unsigned ...I've been searching and Googleing all afternoon and can't find the answer. I'm new to interrupts on the PIC. I'm using a 16F687. I want PORTB bits 5,6,7 to generate an IOC, but it doesn't work. I suspect it's an initialization problem, but I just can't figure it out. Here's my sloppy code. Code: Select all void Init() { OSCCON = 0b01110001; // setup for internal oscillator at 8Mhz. INTCON = 0b11011000; // Why do the following 3 lines cause compiler errors??? //INTCON.GIE = 1; ...Hi Community! My project consists of a double light barrier connected to easyPIC6 PortB. When the beams are interrupted some LEDs on PortB should light (its only for testing purposes, later additional time measurement should be realized). Unfortunately I have no success with my interrupts. Although the LEDs on PortB change her status when the beams are blocked there is no interrupt released. This is the code: Code: Select all /* Testprogram 'Lichtschranke_03' PIC: 16F887 Board: easyPIC6 Clock: 8MHz Switch SW2 RB0, RB1 = off! external connection: one ...I am having trouble using the WDT as an RTC. I want to run the tiny10 in power down mode and have a timer running that measures times up to 20 hours. Accuracy is not important. Here is my code: Code: volatile uint16_t watchdog = 0; ISR(WDT_vect) { watchdog++; if (watchdog == 2) { blink(); } } int main(void) { ioinit(); while(1) { ...Code : #include <pic.h> void main(void) { int tmp; TRISB = 0b00000000; RBPU = 0; // Use internal pullups T0IE = 1; // Enable interrupt on TMR0 overflow INTEDG = 1; // falling edge trigger the interrupt INTE = 1; // enable the external interrupt GIE = 1; // Global interrupt enable tmp=1; for(;;) { CLRWDT(); // Idly kick the dog } } static void ...I need help in resolving a problem with the interrupts in atmega8 microcontroller. I saw in mikroC manual that for atmega16 setting an interrupt it's something like this: Code: Select all const char _THRESHOLD = 10; char counter; void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_OVF { if (counter gt= _THRESHOLD) { PORTB = ~PORTB; // toggle PORTB counter = 0; // reset counter } else counter++; ...I can't seem to be able to get attiny13a out of power down sleep. Here's the code. Any help will be appreciated. Code: #include ltavr/io.hgt #include ltavr/interrupt.hgt #include ltavr/sleep.hgt #define on_duration 6 //30 secs duration static volatile char duration = 0; void init(); void power_off(); int main (void) { init(); for(;;) // main loop ...hi, i've been trying to enable interrupt on change for GPIO pins 0 and 1 except it doesn't seem to be working... Could someone take a look at my code and tell me where i'm going wrong, thank you. Code : #include <pic.h> #include <htc.h> void init(void) { TRISIO=0b00000011; //set GPIO<1:0> as inputs GPIO=0b11111111; //set GPIO high IOC=0b00000011; ...Hi, Newb here. Please go easy on me. I've been reading tutorials, threads, and my specsheet like a madman and am only starting to get a grasp. I have a ATMEGA168 and my goal is to have it interpret a 500cpr optical encoder. I'm going to try to read the level of the two quadrature channels using the external interrupt INT0 and INT1. THey'll be read into a global variable. I'll interpret the position of the encoder within the main program. I pieced together a test program that should turn an led on and then off after a brief delay. ...Code : #include <pic.h> void main(void) { int tmp; TRISB = 0b00000000; RBPU = 0; // Use internal pullups T0IE = 1; // Enable interrupt on TMR0 overflow INTEDG = 1; // falling edge trigger the interrupt INTE = 1; // enable the external interrupt GIE = 1; // Global interrupt enable tmp=1; for(;;) { CLRWDT(); // Idly kick the dog } } static void interrupt isr(void) ...I am using the sample program Timer1_Interrupt with the version 5.40. It's running, the interrupt is normaly called, the PORTB is switched ON when the "counter gt= _THRESHOLD", but it's automatically reset at the end of the interrupt routine Timer1Overflow_ISR ! Why ? on the scope the PORTB has not a duty cycle of 50%, but 1% ! const char _THRESHOLD = 10; char counter; void Timer1Overflow_ISR() org IVT_ADDR_TIMER1_OVF { if (counter gt= _THRESHOLD) { PORTB = ~PORTB; // toggle PORTB counter = 0; // reset counter } else counter++; // increment counter } void main() { DDRB = 0xFF; // set PORTB as output PORTB = 0; // clear PORTB SREG_I_bit = 1; // ...a complete example of external interrupt usage RB0/INT for 16F887 Code: Select all //************************************************************************ // // PIC16F887 // xtal = 20MHz // // EasyPIC 5 board settings // J2 set to pull down // J17 set to VCC // SW2 pin1 RB0 switch on (up position) // SW6 pin4 PORTD LED switch on (to the right) // // EasyPIC 6 board settings // J2 set to pull down // J17 set to VCC // SW2 RB0 switch on (up position) // SW9 PORTD LED switch on (to the right) // // This short program is a demo of external interrupt usage // there is also ...Hello list, I'm a newbie in microcontroller programming, and this is my second project - and it is giving me a headache. The object of this project is to make use of the timer interrupt of the ATtiny 45. Here is the code I try to make work: Code: // Blink LED on PB0 using the timer interrupt // #include ltavr/io.hgt #include ltavr/interrupt.hgt int main(void) { cli(); // Disable global interrupts TCCR0B |= ((1 ltlt CS02) | (1 ltlt CS00)); // Timer 0 prescaling - divides by 1024 */ TCCR0A |= (1 ltlt WGM01); // ...Can someone tell me why this code results in PORTB staying high all of the time except for when it's executing the RXC interrupt? If I comment out the PORTB= 0xFF; line it works fine, and the characters transmitted via the serial port show up on the 8 leds and stay that way until another character is transmitted. However that means the program starts with the initial value of PORTB= 0, which is not what I want. If I uncomment the line then PORTB stays high except for the split second the interrupt executes, where I can see the lights ...HI, I m new to PIC and learning it. I have an example of timer0 but could not understand where it has run the timer. is there inbuilt function of interrupt in PIC as delay function.I understood the whole example but could not understand where it has run the timer so that int, can occur, example is unsigned cnt void interrupt() { if (TMR0IF_bit==1) { cnt++; // increment counter TMR0IF_bit = 0; // clear TMR0IF TMR0 = 96; } } void main() { OPTION_REG = 0x84; // Assign prescaler to TMR0 ANSEL = 0; // Configure AN pins as digital ...
