[PIC] problem in temp data logging

Status
Not open for further replies.

Deexith Hasan

Advanced Member level 4
Joined
Oct 24, 2014
Messages
111
Helped
4
Reputation
8
Reaction score
3
Trophy points
18
Visit site
Activity points
740
my code

Code:
#include <htc.h>


unsigned char temp2;
unsigned char temp3;
unsigned char lsb;
unsigned char msb;
unsigned char mmb;


void dataconv(unsigned char);
void dataconv(unsigned char data)
{
lsb=data%10;
lsb=48|lsb;
data=data/10;
mmb=data%10;
mmb=48|mmb;
msb=data/10;
msb=48|msb;
}


void delay()
{
int i;
for(i=0;i<12275;i++);


}


void serialwrite(unsigned char data)
{
TXREG=data;
while(TXIF==0);
}

void interrupt ISR(void)
{
if(RCIF==1)
{
RC0=1;

if(RCREG=='a'){
serialwrite('b');
dataconv(temp2);
serialwrite(msb);
delay();
serialwrite(mmb);
delay();
serialwrite(lsb);

dataconv(temp3);
serialwrite(msb);
delay();
serialwrite(mmb);
delay();
serialwrite(lsb);
}


}
}



void main()
{
TXSTA=0X20;
RCSTA=0X90;
SPBRG=129;
BRGH=1;
TRISC7=1;
TRISC6=0;
TRISA=0XFF;
TRISD=0X00;
TRISB=0X00;
ADCON0=0X01;
ADCON1=0X0C;
ADCON2=0X2D;
PEIE=1;
GIE=1;
RCIE=1;
serialwrite('a');
delay();
serialwrite('b');
while(1)
{

delay();
ADCON0=0X05;
GODONE=1;
while(GODONE==1);
PORTD=ADRESH;
temp2=ADRESH;
delay();
ADCON0=0X09;
GODONE=1;
while(GODONE==1);
temp3=ADRESH;

}

}

PIC18f4520
20Mhz crystal
9600 baud rate
Hi-Tech compiler

simulated in proteus and working well but in development board received a000000 y?
but ADC working checked portd pins
 

dataconv(); function is not posted in your code and which adc you are using.Check your real sensor is working or not.ADC channel selection is done properly and correctly.
 

dataconv(); fun is there in the code......inbuilt adc and its working good...
PORTD=ADRESH;
and connected PORTD with led array and its changes as pot changed....
something wrong in serial communication
 

sorry my mistake I didn't see that function.

Code:
void dataconv(unsigned char data)
{
lsb=data%10;
lsb=48|lsb;

data=data/10;
mmb=data%10;
mmb=48|mmb;
msb=data/10;
msb=48|msb;

serialwrite(msb);

serialwrite(mmb);

serialwrite(lsb);
}

void interrupt ISR(void)
{
if(RCIF==1)
{
RC0=1;

if(RCREG=='a'){
serialwrite('b');
dataconv(temp2);

dataconv(temp3);

}


}
}


try this code
 

worked in proteus but not in development board received b000000

Check your serial code part by sending and receiving the simple char first if serial communication is done ok then there is something wrong with the adc connection or hardware or AdC it self. show your real schematic.
 

i have send "ABCD" through serial and received correctly...
made a joystick using same development board.. using serial communication and vb application worked perfectly......only this adc value through serial sucks......
 

hello

i don't know HTC, but with C18
Code:
unsigned char temp2;
unsigned char temp3;
unsigned char lsb;
unsigned char msb;
unsigned char mmb;

must be declared as volatile ..
because used inside Interrupt


your
Code:
void dataconv(unsigned char data)
; ...is OK
 

nope it didnt worked out..problem is not solved and again received the same a000000
 

Code:
ADCON1=0Xc0;

try this for enabling all the pin as analog input.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…