Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

ADC0804 to PIC16f877a

Status
Not open for further replies.

doo20000

New Member
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
/*
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);
}
}
}
 
It seems to be silly to use an external ADC when the 16F877 has one built in! Are they trying to teach you how to do a task the most expensive and least efficient way? Or is this more about learning how the ADC0804 works?
Maybe post a diagram showing how you've connected the ADC0804 to the PIC. You need more than just the 8 data lines. What about the RD, WR, CS, and INTR pins? Post a diagram to go with your code and repost the code using the code tags so the formatting isn't lost.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top