Continue to Site

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 while sending ADC value through serial port

Status
Not open for further replies.

Deexith Hasan

Advanced Member level 4
Full Member level 1
Joined
Oct 24, 2014
Messages
111
Helped
4
Reputation
8
Reaction score
3
Trophy points
18
Visit site
Activity points
740
i have done a temp datalogger using pic..... got perfect result in proteus but not in my development board.....
PIC18F4520
20Mhz crystal
lm35 temp sensor....
HI tech compiler
i want to send ADRESH value to serial.....it will send ascii char like $?!~ ........in proteus its working...bu ton development board i got 00 first....but now not even 00
Code:
#include <htc.h>

unsigned char temp1=0;
unsigned char temp2=0;
unsigned char temp3=0;
unsigned char n=0;


void delay()
{
unsigned char i;
for(i=0;i<255;i++);
}

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

void interrupt ISR(void)
{
if(RCIF==1)
{
RC0=1;
n=RCREG;
if(n=='a'){
serialwrite(temp1);
serialwrite(temp2);
serialwrite(temp3);
}
RCIF=0;

}
}


void main()
{
TXSTA=0X20;
RCSTA=0X90;
SPBRG=129;
BRGH=1;
TRISC7=1;
TRISC6=0;
TRISC0=0;
TRISA=0XFF;
TRISD=0X00;
TRISB=0X00;
ADCON0=0X01;
ADCON1=0X0C;
ADCON2=0X2D;
PEIE=1;
GIE=1;
RCIE=1;
serialwrite('a');
while(1)
{
delay();
ADCON0=0X01;
GODONE=1;
while(GODONE==1);
PORTD=ADRESH;
temp1=ADRESH;
delay();
ADCON0=0X05;
GODONE=1;
while(GODONE==1);
temp2=ADRESH;
delay();
ADCON0=0X09;
GODONE=1;
while(GODONE==1);
temp3=ADRESH;
}
}

ADC working checked PORTD pins ....
 

There is nothing in your code to send the ADC result as it is read so you may have trouble synchronizing the ADC measurement with the bytes you are sending. Your other problem is you are sending the data in binary but appear to be reading it in ASCII. If you want the ADC results to be readable on your terminal, you have to convert from binary to ASCII first.

Brian
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top