// *********************************************************************************************************************************/
// FILE NAME:witness.c
// Version: 1.0
// Compiler HI-Tech PICC-Lite version 9.83
// Compiled using MPLAB IDE v8.80 of microchip
// Processor: PIC12F683 8 pins
// Date: June 22, 2012
// ********************************************************************************************************************************/
// Global includes
// #define _LEGACY_HEADERS // Not Necessary, Syntax Errors
#include <htc.h>
// Fuse configuration for the PIC12F683
__CONFIG(FCMEN_OFF & IESO_OFF & BOREN_OFF & CP_OFF & MCLRE_OFF &
PWRTE_OFF & WDTE_OFF & FOSC_INTOSCIO);
// Define oscillator frequency
#define _XTAL_FREQ 4000000
// Hardware mapping definitions
#define SHOOT [COLOR="#FF0000"]GP0[/COLOR] //GP0
#define POWER [COLOR="#FF0000"]GP1[/COLOR] //GP1
#define SW0 [COLOR="#FF0000"]GP4 [/COLOR] //GP4
#define SW1 [COLOR="#FF0000"]GP5[/COLOR] //GP5
// Globals for Seconds Counter
unsigned char uSecCounter = 0; // Micro Seconds Counter
unsigned char SecCounter = 0; //Seconds Counter
unsigned char MinCounter = 0; //Minutes Counter
unsigned char FiveMinCounter = 0; //5Min Counter
// Interrupt Service Request handler
void interrupt isr()
{
// Is this timer1 interrupting?
if (TMR1IF) // If the Interrupt Flag = 1 then do...
{
// Update the uSeconds Counter
uSecCounter++; //Increment uSecCounter by one until 20 pulses are counted then its 1 sec.
// Update Secounds Counter
if (uSecCounter > 20) // If the uSecCounter has counted 20 then its One Sec.
{
uSecCounter = 0; // Reset the uSec Counter to Zero
SecCounter++; // Increment Seconds Counter
}
// Update the Minutes Counter
if (SecCounter > 60)
{
SecCounter = 0; // If the SecCounter has reached 60, reset it first and increment Minutes Counter.
MinCounter++;
}
// Update the 5Minutes Counter
if (MinCounter > 5)
{
MinCounter = 0; // If the MinCounter has reached 5, then reset it first and increment 5Minutes Counter.
FiveMinCounter++;
}
// Check to see if 10 minutes have passed.
if (FiveMinCounter > 1)
{
FiveMinCounter = 0; // If the 5MinCounter has reached 2 then its 10 minutes have passed, then reset it.
}
// Reset the timer1 counter bytes
TMR1H = 0x3C;
TMR1L = 0xB0;
// Reset the timer1 interrupt flag
TMR1IF = 0;
}
}
// Main procedure
void main(void)
{
OSCCON = 0b01100001; // 4Mhz INT OSC
// Set up the PIC12F683 IO pins
GPIO = 0b00110100; // Set all GPIO pins to Output except GP2(PIR), GP4(SW0) and GP5(SW1) as Input
ANSEL = 0b00000000; // Disable analogue inputs
TRISIO = 0b00000100; // Set all IO pins to output except GP2 which is input
OPTION_REG = 0b00000000;// Set the option register
WPU = 0b00000000; // Set weak pull-up off on all pins
CMCON0 = 7; // Disable comparator 0
// Set up the TIMER1 (16 bit timer, and a max count = 65,536)
TMR1IF = 0; // Reset the timer1 interrupt flag
nT1SYNC = 0; // nT1SYNC as I check it against PIC12F683 header file
T1CON = 0b00000001;
TMR1IE = 1; // Turn on the timer1 interrupt
TMR1H = 0x3C;
TMR1L = 0xB0;
// Enable the interrupts
PEIE = 1;
GIE = 1;
// Main loop
while(1)
{
//Read Input Switches
//SW1 SW0
// 00 = AUTO MODE with PIR
// 01 = Fix Mode: Shot every 10 Sec
// 10 = Fix Mode: Shot every 30 Sec
// 11 = Fix Mode: Shot every 1 Minute
// Read the DIP switch settings
[COLOR="#FF0000"] i[/COLOR]f(SW1==0 && SW0==0){ // I am having trouble with this line of code?????
// AUTO MODE
// This would be external interrupt trigger driven code
// Turn Power ON
// POWER = 1;
// Delay 3 usec
__delay_ms(3000);
// Take a shot
// SHOOT = 1;
// Wait for it to be saved on the SD Card
__delay_ms(3000);
}
[COLOR="#FF0000"]e[/COLOR]lse if(SW1==0 && SW0==1){
//Fix Mode: Shot every 10 sec
// Turn Power ON
//POWER = 1;
// Delay 3 usec
//__delay_s(3);
//If(SecCounter >0)
//{
// Take a shot
//SHOOT = 1;
// Wait for it to be saved on the SD Card
//__delay_s(3);
}
[COLOR="#FF0000"]e[/COLOR]lse if(SW1==1 && SW0==0){
//Fix Mode: Shot every 30 sec
//
}
[COLOR="#FF0000"]e[/COLOR]lse [COLOR="#FF0000"]if[/COLOR](SW1==1 && SW0==1){
// Either "else" without conditional test or "else if" with conditional test
//Fix Mode: Shot every 1 Minute
//
}
}//While loop end
} // Main loop