Hello, friends i need some help for my project. i am trying to hook up the output from ADC to the pic. what i did was hooking ADC output directly to PORTC of the pic (all 8 bits). is it the correct way?
What i am trying to do is, i am using two ADC one hooking to PORTC and output of the other one hooking up to PORTD. ADC input is light sensor. I am comparing the two ports. Pls give me some idea how am i suppose to do it. Below here is my code of comparing the two ports. The thing is that it is not working. I am not sure either hardware of software problem. Any easy sensor circuit for suggestion for this project. Thanks
What i am trying to do is, i am using two ADC one hooking to PORTC and output of the other one hooking up to PORTD. ADC input is light sensor. I am comparing the two ports. Pls give me some idea how am i suppose to do it. Below here is my code of comparing the two ports. The thing is that it is not working. I am not sure either hardware of software problem. Any easy sensor circuit for suggestion for this project. Thanks
/*
Class: Senior Project
Date: 02/13/08
*/
#include <htc.h>
#include <pic.h>
__CONFIG(HS & WDTDIS & PWRTEN & BOREN & LVPEN & WRTEN & DEBUGEN & UNPROTECT );
#define signal RB0
#define DtoU PORTC //Time = 2ms
#define UtoD PORTD //Time = 1ms
int i, j;
delay(int iEnd,int jEnd)
{
for(i = 0; i < iEnd; i++)
for(j = 0; j < jEnd; j++);
return;
}
main()
{
PORTA = 0x00; //Ports initialization
PORTB = 0x00;
PORTC = 0x00;
PORTD = 0x00;
PCFG2 = 1;
PCFG1 = 1;
TRISB = 0x00;
TRISC = 0xff;
TRISA = 0xff;
TRISD = 0xff;
signal = 0; //Clear PORTB bit0
while(1 == 1) // Loop forever
{
if(UtoD != DtoU) // If both sensor not equal each other
{
if(UtoD > DtoU) // If push button 0 is pressed
{
signal = 1; // Pulse high
delay(1,472); // 2 ms which is turning from left to right
signal = 0; // Low
delay(19,243); // 18 ms
}
else if(UtoD < DtoU) // If push button 1 is pressed
{
signal = 1; //Pulse high
delay(1,144); // 1 ms which is turning from right to left
signal = 0;
delay(19,271); // 19 ms
}
delay(2,100000); //Delay for ten minutes
}
else if (UtoD == DtoU)
{
signal = 0; //Pulse Low
delay(19,250); // 18.5 ms which is doing nothing
delay(2,100000); //Delay for ten minutes
}
if(UtoD == 0 && DtoU == 0)
{
signal = 1; //Pulse High
delay(1,532); //2 ms which reset the position of solar panel of 45 degree angle
signal = 0; //Pulse Low
delay(19,243);
}
}
}