Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[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
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
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
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.
 

Deexith Hasan

Advanced Member level 4
Joined
Oct 24, 2014
Messages
111
Helped
4
Reputation
8
Reaction score
3
Trophy points
18
Activity points
740
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
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
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
 

Deexith Hasan

Advanced Member level 4
Joined
Oct 24, 2014
Messages
111
Helped
4
Reputation
8
Reaction score
3
Trophy points
18
Activity points
740
worked in proteus but not in development board received b000000
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
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.
 

Deexith Hasan

Advanced Member level 4
Joined
Oct 24, 2014
Messages
111
Helped
4
Reputation
8
Reaction score
3
Trophy points
18
Activity points
740
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......
 

paulfjujo

Advanced Member level 4
Joined
Jun 9, 2008
Messages
1,429
Helped
290
Reputation
580
Reaction score
275
Trophy points
1,363
Location
France 01800
Activity points
10,025
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
 

Deexith Hasan

Advanced Member level 4
Joined
Oct 24, 2014
Messages
111
Helped
4
Reputation
8
Reaction score
3
Trophy points
18
Activity points
740
nope it didnt worked out..problem is not solved and again received the same a000000
 

ud23

Advanced Member level 3
Joined
Apr 20, 2011
Messages
926
Helped
184
Reputation
368
Reaction score
180
Trophy points
1,323
Activity points
6,138
Code:
ADCON1=0Xc0;

try this for enabling all the pin as analog input.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top