-
Search Results
-
Topic: Delay using interrupt
Hello Guys,
I am trying to implement a delay using timer0 interrupt. I’ll just post an abstraction of the code in mikroc
void inittimer()
{
//Timer initialization for a 32ms interrupt
}
void interrupt()
{
//interrupt code;
delayvariable++;
}
void main()
{
TRISB = 0; //PORTB is output
TRISC.F0 = 1; //PORTC Pin 0 is input and connected to a switch
if (PORTC.F0 ==0) //check is the button is pressed
{
if (delayvariable==3) //~100ms second delay to check buttton debounce
{
if (PORTC.F0==0) //check if the button is still pressed
{
PORTB = ~PORTB; //toggle PORTB
delayvariable = 0; //reset the delay variable
}
}
}
}
The above code does not work as I expected. Can somebody please point out the mistake I am making or suggest a better way for achieving a 100 ms delay using interrupt?
Hi, My Project is automatic irrigation
When I build my program without interruption it works but when I add void interrupt it shows up a mistake “NOT ENOUGH RAM FOR STACK” as the picture and folders of MikroC show.hi and good day to you, i am working on pic16f877a , have interfaced push-button to trigger the ultrasonic sensor hc-sr04 and the range will control the motor speed by using the pwm function. i am very new to the programming mikroC and i really hope you can guide me. As now i just learn how to interface push button with my led. I tried to combine the code how to interfacing ultrasonic and lcd and it didn’t work, i am very sorry, here my code:
void main() { TRISA.F0 = 1; //Configure 1st bit of PORTD as input TRISA.F1 = 1; TRISA.F2 = 1; TRISB.F5 = 0; //Configure 1st bit of PORTB as output TRISB.F6 = 0; TRISB.F7 = 0; TRISA.F3 = 0; PORTB.F5 = 1; //LED OFF PORTB.F6 = 1; //LED OFF PORTB.F7 = 1; //LED OFF PORTA.F3 = 1; //BUZ OFF ADCON1 = 7; do { // LED 1 if(PORTA.F0 == 0) //If the switch is pressed PORTA.F3 = 0; //BUZ ON Delay_ms(100); //1 Second Delay PORTA.F3 = 1; //BUZ OFF { Delay_ms(150); //Switch Debounce if(PORTA.F0 == 0)//If the switch is still pressed { PORTB.F5 = !PORTB.F5; // LED out port } } // LED 2 if(PORTA.F1 == 0) //If the switch is pressed if(PORTA.F0 == 0) //If the switch is pressed PORTA.F3 = 0; //BUZ ON Delay_ms(100); //1 Second Delay PORTA.F3 = 1; //BUZ OFF { Delay_ms(150); //Switch Debounce if(PORTA.F1 == 0)//If the switch is still pressed { PORTB.F6 = !PORTB.F6; // LED out port } } // LED 3 if(PORTA.F2 == 0) //If the switch is pressed if(PORTA.F0 == 0) //If the switch is pressed PORTA.F3 = 0; //BUZ ON Delay_ms(100); //1 Second Delay PORTA.F3 = 1; //BUZ OFF { Delay_ms(150); //Switch Debounce if(PORTA.F2 == 0)//If the switch is still pressed { PORTB.F7 = !PORTB.F7; // LED out port } } }while(1); }I am doing a project which requires that I turn on and off two LED’s independently from a computer using serial port communication. I send a character like ‘A’ via the serial port and turn on one LED for say 1 minute and send another character like ‘B’ and turn on another LED for 2 minutes. My problem is that when using Timer0 of pic 18F87k22, I can’t implement the 1 minute and 2 minute delays independently. When I turn on the one LED the other one doesn’t respond and vice versa. I am simulating using Proteus and my code is is in MikroC as shown below:
char uart_rd; char cnt; void interrupt () { if (TMR0IF_bit) { cnt++; // increment counters TMR0IF_bit = 0; // clear TMR0IF TMR0L = 0xDC; // set TMR0 for aproximetly 1 sec TMR0H = 0x0B; } } void one_min_delay () { TRISB = 0; // PORTB is output TMR0H = 0x0B; TMR0L = 0xDC; // Timer0 initial value T0CON = 0x84; // Set TMR0 to 8bit mode and prescaler to 256 GIE_bit = 1; // Enable global interrupt TMR0IE_bit = 1; // Enable Timer0 interrupt cnt = 0; // Initialize cnt do { if (cnt >= 60) { LATB = 0x00; // turnoff PORTB LEDs cnt = 0; // Reset cnt } }while(1); } void two_min_delay () { TRISB = 0; // PORTB is output TMR0H = 0x0B; TMR0L = 0xDC; // Timer0 initial value T0CON = 0x84; // Set TMR0 to 8bit mode and prescaler to 256 GIE_bit = 1; // Enable global interrupt TMR0IE_bit = 1; // Enable Timer0 interrupt cnt = 0; // Initialize cnt do { if (cnt >= 120) { LATB = 0x00; // turnoff PORTB LEDs cnt = 0; // Reset cnt } }while(1); } void main() { UART1_Init(9600); // Initialize UART module at 9600 bps Delay_ms(100); // Wait for UART module to stabilize TRISB = 0x00; while (1) { if (UART1_Data_Ready()) { // If data is received, uart_rd = UART1_Read(); } if (uart_rd=='A') { LATB = 0x01; one_min_delay(); } else if (uart_rd == 'B') { PORTB = 0x02; two_min_delay (); } uart_rd ='\0'; } }Hi guys, I am kinda new to these forums and this is my first question.
I need some help in writing the code to extract NMEA GPS coordinates, display them on a 2 by 16 LCD and send them via GSM for accident alert notification purposes. i have dealt with the GSM part (or at least i think so) but now i need to be able to send the coordinates from the location of the accident occurrence (accident alert system for vehicle project). To do that, i need to extract the coordinates from the $GPGGA line or $GPGLL line (or whichever works best). I need your help guys, I do not have much time left to finish the project. I am using PIC18F45k22 and for simulation of GPS I am using Virtual GPS that i have virtually linked with Proteus (v8.0). I would very much appreciate it if you could help me with a working code that i can integrate into the whole code.
Thanks
