nayakajit87
Member level 5
Dear all.
I am looking for code where i could achieve below functionality.
function requirement: Once Test button pressed in timer interrupt timing should start after 1 min automatically RUN_RESET() should be called.
in below code unless keyreset is pressed RUN_RESET() function wont be called. Can some one suggest how can implement logic
i have used PIC16F886
I am looking for code where i could achieve below functionality.
function requirement: Once Test button pressed in timer interrupt timing should start after 1 min automatically RUN_RESET() should be called.
in below code unless keyreset is pressed RUN_RESET() function wont be called. Can some one suggest how can implement logic
i have used PIC16F886
Code:
#include <htc.h>
#include <stdio.h>
#include <math.h>
#include "delay.h"
__CONFIG(WDTE_OFF & PWRTE_ON & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & FCMEN_ON & IESO_OFF & CP_OFF & MCLRE_ON);
#define TEST RA5
#define RESET RC0
#define ACK RC1
#define MUTE RC2
#define AUTO_RST RA4
unsigned char Auto_Counter=0;
void interrupt isr(void) {
asm("clrwdt"); //ANN
if (TMR1IF) {
TMR1IF = 0;
/// TMR1H = 0xD8; //
// TMR1L = 0xFC; //
TMR1H = 0xAF;
TMR1L = 0xC8;
}
INTF = 0;
}
void InitController() {
OSCCON = 0b01110010; //changes 8Mhz
WREN = 0;
WDTCON = 0b00010111; //2sec Watch Dog Reset //STP //ANN
PORTA = 0b00000000;
TRISA = 0b00111000;
TRISB = 0b11001000;
PORTB = 0b00000000;
WPUB = 0b00000000;
ANSEL = 0b00000000;
ADCON0 = 0b00000000;
// TRISC = 0b10000111;
TRISC = 0b11001111;
PORTC = 0b00000000;
ANSELH = 0b00000000;
ADDEN = 0;
T1OSCEN = 0;
INTEDG = 0; //falling edge
INTF = 0;
INTE = 1;
PIE1 = 0b00000001;
PIR1 = 0x01;
INTCON = 0; //ANN
T1CON = 0b00000101; //Timer Settings //ANN
TMR1H = 0xF0; //ANN
TMR1L = 0x61; //ANN
TMR1IE = 1;
PEIE = 1; //ANN
GIE = 1; // Global interrupt enabled.
}
//********************************************************************************************
//// CHECK IF TEST IS PRESSED
//********************************************************************************************
void Key_CHK_TEST() {
if (!TEST && !bits.KeyLock_TEST1) {
Debounce++;
if (Debounce > 30) {
Debounce = 0;
bits.KeyLock_TEST1 = 1;
RUN_TEST();
}
} else if (TEST && bits.KeyLock_TEST1) {
bits.KeyLock_TEST1 = 0;
Debounce = 0;
}
}
//**********************************************************************************************
//// CHECK MUTE KEY pressed
//**********************************************************************************************
void Key_CHK_MUTE() {
if (!MUTE && !bits.KeyLock_MUTE1) {
Debounce++;
if (Debounce > 30) {
Debounce = 0;
bits.KeyLock_MUTE1 = 1;
RUN_MUTE();
}
} else if (MUTE && bits.KeyLock_MUTE1) {
bits.KeyLock_MUTE1 = 0;
Debounce = 0;
}
}
//**********************************************************************************************
//// CHECK ACK KEY PRESS IN RUN MODE
//**********************************************************************************************
void Key_CHK_ACK() {
if (!ACK && !bits.KeyLock_ACK1) { // CHECK IF ack IS PRESSED
Debounce++;
if (Debounce > 30) {
Debounce = 0;
bits.KeyLock_ACK1 = 1;
RUN_ACK();
}
} else if (ACK && bits.KeyLock_ACK1) {
bits.KeyLock_ACK1 = 0;
Debounce = 0;
}
}
//**********************************************************************************************
//// CHECK RESET KEY PRESS IN RUN MODE
//**********************************************************************************************
void Key_CHK_RESET() {
if (!RESET && !bits.KeyLock_RESET1) { // CHECK IF SELECT IS PRESSED
Debounce++;
if (Debounce > 30) {
Debounce = 0;
bits.KeyLock_RESET1 = 1;
RUN_RESET();
}
} else if (RESET && bits.KeyLock_RESET1) {
bits.KeyLock_RESET1 = 0;
Debounce = 0;
}
}
void CHECK_SEQ(void) {
if (AUTO_RST == 1) {
bits.MANUAL_RESET = 1;
bits.AUTO_RESET = 0;
}
if (AUTO_RST == 0) {
bits.MANUAL_RESET = 0;
bits.AUTO_RESET = 1;
}
}
void main() {
InitController();
CHECK_SEQ();
while(1) {
Key_CHK_TEST();
Key_CHK_MUTE();
Key_CHK_ACK();
if (bits.MANUAL_RESET == 1)
Key_CHK_RESET();
if (bits.AUTO_RESET == 1) {
Auto_Counter++;
if (Auto_Counter >= 100) {
Auto_Counter = 0;
RUN_RESET();
}
}
}
}