// Global
unsigned int gPos = 0;
unsigned int gSMTarget = 0; //raw
unsigned int gSMTarget2 = 0; //filter
static unsigned int gSMTargetDIF = 0;
unsigned int REFRESH_COUNT = 0;
//Average
unsigned int e0 = 0;
unsigned int e1 = 0;
unsigned int e2 = 0;
unsigned int e3 = 0;
unsigned int e4 = 0;
unsigned int e5 = 0;
unsigned int e6 = 0;
unsigned int e7 = 0;
unsigned int e8 = 0;
unsigned int e9 = 0;
unsigned int e10 = 0;
unsigned int e11 = 0;
unsigned int e12 = 0;
unsigned int AVERAGE = 0;
// set up oscillator control register
OSCCON= 0b01110010; // 8Mhz
//OSCCON= 0b00011010; // 16Mhz
//OSCCON= 0b11110000; // 32Mhz
// Set up I/O pins
// PORT A Assignments
APFCON= 0b00000001; // CCP1 function is on RA5
TRISA= 0b00101000; //
PORTA= 0b00000000; // Reset port
ANSELA= 0b00000000; // Disable analog input
LED11()
// Timer1 Clock Source Select bits
T1CONbits.TMR1CS=0x00; // 00 = Timer1 clock source is instruction clock (FOSC/4)
T1CONbits.T1CKPS=0x01; // Timer1 Input Clock Prescale Select bits 1:2 Prescale value
T1CONbits.T1OSCEN=0; // Dedicated Timer1 oscillator circuit disabled
T1CONbits.nT1SYNC=1; // 1 = Do not synchronize external clock input
T1CONbits.TMR1ON=0; // Timer1 On bit
// Set up Capture input
CCP1CON= 0b00000100; // Capture mode: every falling edge
//CCP1CON= 0b00000101; // Capture mode: every rizing edge
// Reset CCP1/Timer interrupt flag
CCP1IF=0;
TMR1IF=0;
startupdemo();
// Enable Interrupt
PEIE=1; // Enable peripheral interrupt
GIE=1; // enable global interrupt
CCP1IE=1; // enable the CCP1 interrupt
TMR1IE=1; // enable Timer1 intterupt on
TMR1ON=1; // Timer1 On
}
/*
Copyright 2012-2014 Rilassaru All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list
of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* Neither the name of the Rilassaru nor the names of its contributors may be used
to endorse or promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/