Hey all
Having a problem with a PIC project hope that you guys here can help me..
In school I´m making a temprature controllor and I have the problem that one of my two analog inputs doesn´t work!
the tempratures is coming from two LM35 sending out 10mV/C and one of them is giving me an input to my PIC on approx. 0.25 V the other one is where the problem is, the LM35 is working but the PIN on the PIC is having an output on approx 4.1 V - IT`S AN INPUT PIN!?!?!?!
I know my problem is in my programming (programming C for the first time) so please help me out here.
My Code:
#include <16f88.h>
#FUSES NOWDT // Slå watchdog timer fra.
#FUSES INTRC_IO // Ingen clock out.
#FUSES NOPUT // Ingen power up timer.
#FUSES NOPROTECT // Ingen read protection.
#FUSES NOBROWNOUT // Ingen brownout reset.
#FUSES NOMCLR // Master clear bruges som input/output.
#FUSES NOLVP // B3 skal bruges som input/output.
#FUSES NOCPD // Ingen EE protection.
#use delay(clock=4000000) // Chippen er 4MHz.
//globale variabler.
int input1 = 0;
int input2 = 0;
int temp_10 = 0;
int temp = 0;
void display(int tal, int display)
{
//Defines the two LM35 signal pins
bit_clear(tal, 4);
bit_clear(tal, 5);
if (display == 0)
bit_set(tal, 5);
else
bit_set(tal, 4);
output_b(tal);
delay_ms(5);
}
// Her starter the program
void main()
{
set_tris_a(0b10001111);
set_tris_b(0b00000000);
//Analog - Digital konverter
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN1);
setup_adc(ADC_CLOCK_INTERNAL);
while(1){
//Læs temperaturene
set_adc_channel(0);
input1 = read_adc();
set_adc_channel(1);
input2 = read_adc();
//Konverts Input til temp
input1=input1*2;
input2=input2*2;
if (input(PIN_A2))
{
temp_10 = input1/10;
temp = input1-(temp_10*10);
display(temp_10, 0);
display(temp, 1);
}
if (input(PIN_A3))
{
temp_10 = input2/10;
temp = input2-(temp_10*10);
display(temp_10, 0);
display(temp, 1);
}
}
}
THX for helping me out here gys... It needs to me fast! - have deadline tomorrow!
Having a problem with a PIC project hope that you guys here can help me..
In school I´m making a temprature controllor and I have the problem that one of my two analog inputs doesn´t work!
the tempratures is coming from two LM35 sending out 10mV/C and one of them is giving me an input to my PIC on approx. 0.25 V the other one is where the problem is, the LM35 is working but the PIN on the PIC is having an output on approx 4.1 V - IT`S AN INPUT PIN!?!?!?!
I know my problem is in my programming (programming C for the first time) so please help me out here.
My Code:
#include <16f88.h>
#FUSES NOWDT // Slå watchdog timer fra.
#FUSES INTRC_IO // Ingen clock out.
#FUSES NOPUT // Ingen power up timer.
#FUSES NOPROTECT // Ingen read protection.
#FUSES NOBROWNOUT // Ingen brownout reset.
#FUSES NOMCLR // Master clear bruges som input/output.
#FUSES NOLVP // B3 skal bruges som input/output.
#FUSES NOCPD // Ingen EE protection.
#use delay(clock=4000000) // Chippen er 4MHz.
//globale variabler.
int input1 = 0;
int input2 = 0;
int temp_10 = 0;
int temp = 0;
void display(int tal, int display)
{
//Defines the two LM35 signal pins
bit_clear(tal, 4);
bit_clear(tal, 5);
if (display == 0)
bit_set(tal, 5);
else
bit_set(tal, 4);
output_b(tal);
delay_ms(5);
}
// Her starter the program
void main()
{
set_tris_a(0b10001111);
set_tris_b(0b00000000);
//Analog - Digital konverter
setup_adc_ports(sAN0);
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(sAN1);
setup_adc(ADC_CLOCK_INTERNAL);
while(1){
//Læs temperaturene
set_adc_channel(0);
input1 = read_adc();
set_adc_channel(1);
input2 = read_adc();
//Konverts Input til temp
input1=input1*2;
input2=input2*2;
if (input(PIN_A2))
{
temp_10 = input1/10;
temp = input1-(temp_10*10);
display(temp_10, 0);
display(temp, 1);
}
if (input(PIN_A3))
{
temp_10 = input2/10;
temp = input2-(temp_10*10);
display(temp_10, 0);
display(temp, 1);
}
}
}
THX for helping me out here gys... It needs to me fast! - have deadline tomorrow!