PIC18F4550 ADC for infrared signal

Thread Starter

unoeusux

Joined Jan 20, 2010
2
I am not too sure whether this will work, any one can help me? this program is suppose to record the highest signal level and location, go back to the infrared signal to shoot a target.:confused:

#include <p18F4550.h>
#include <delays.h>
// Include this when using Bootloader Program ================================
#pragma udata
extern void _startup (void); // See c018i.c in your C18 compiler dir
#pragma code _RESET_INTERRUPT_VECTOR = 0x000800
void _reset (void)
{
_asm goto _startup _endasm
}
#pragma code
#pragma code _HIGH_INTERRUPT_VECTOR = 0x000808
void _high_ISR (void)
{
;
}
#pragma code _LOW_INTERRUPT_VECTOR = 0x000818
void _low_ISR (void)
{
;
}
#pragma code
#pragma code
// additional codes ends here ===============================================================
// Your program declarations start here:====
unsigned char v_name;
double Vmax = 0;
double Vpre = 0;
double V = 0;
int Pmax = 0;
int count = 0;
int i = 0;
main(void)
{
// Do not remove these as well=============
ADCON1 = 0x0F;
CMCON = 0x07;
// ========================================
// Your MAIN program Starts here: =========
TRISAbits.TRISA0 = 1;
TRISAbits.TRISA1 = 1;
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC2 = 0;
TRISB = 0b00000111;
TRISD = 0x00;

ADCON0 = 0b00000001; // AN0,IDLE,ON //Converting Comparing
ADCON1 = 0b00001110; // Vref - 0v,5v , AN0 analog input$
ADCON2 = 0b00000111; // left justified

if(PORTBbits.RB0 == 0)
{
CCP1CON = 0b00001100;
PR2 = 29; //25khz, 40us

CCPR1L = 0b00001001; // Generating 30% dutycycle Wave
CCP1CONbits.DC1B1 = 0;
CCP1CONbits.DC1B0 = 0;

T0CON = 0b00000111;
T2CON = 0b00000111;

while(count < 124) // while duty cycle <=70%
{
count ++;
CCPR1L++;
Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);
Delay1KTCYx(250);


ADCON0bits.GO = 1;

while(ADCON0bits.GO == 1)
{
Vpre = ADRESH;
if (Vpre >= Vmax)
{
Vmax = Vpre;
}
else
i++;

}
}

while(i>0)
{
CCPR1L--;
i--;
}



}
 
Top