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.

LM35 wif PIC18F458 and send to zigbee

Status
Not open for further replies.

shuzhe

Newbie level 4
Joined
Aug 29, 2010
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,326
can someone help me with the code?
i am connect temprature sensor LM35 to pic18f458 and i need the code to convert the voltage to temperature from the temperature sensor...
 
Last edited:

can i ask that, if i connect the lm35 to port RA0, then ZIgbee to RD0, still need adc??
can someone provide the code?
 

Why do u need to use PIC18F458? i think, its a waste. You can use more cheaper PIC such as PIC16F877A or PIC16F628A or any other PIC which has a build in ADC module and serial UART module (for serial communication with ZigBee).
 

does Zigbee chip need to be programmed before using UART ports in it?
 

does Zigbee chip need to be programmed before using UART ports in it?

No need to program the ZigBee. Just a minor setup (destination address, source address, baudrate) will be OK to connect them both.
 

connect both zigbee modules to 2pc and try to transfer data from one pc to other,, if you are successful then no need to do anything or else you need to set up and configure it... after that you dont need any configuration......
 

float TEMP;
unsigned int temp_res;

void main()
{

ADCON1 = 0x00;
TRISA = 0xFF;
TRISD = 0X00;
Usart_Init (9600);

while (1)
{
temp_res = ADC_Read(0) >>2 ;
TEMP= temp_res *(500/255);
PORTD = TEMP;
Usart_Write(TEMP); //sends signal
delay_ms (1000);

}
}

this is my code. but i wonder why some code got the ADRESH=0 and
ADRESL=0. what is the purpose of adding this 2 code??
 

to understand the function of ADRESH and ADRESL read section 20 of the PIC18F458 data sheet
https://ww1.microchip.com/downloads/en/DeviceDoc/41159e.pdf

also
Code:
temp_res = ADC_Read(0) >>2 ;
TEMP= temp_res *(500/255);
PORTD = TEMP;
Usart_Write(TEMP); //sends signal
appears to transmit the binary value of the temperature, is that what you require or should you convert it to text before thransmission?
 

to understand the function of ADRESH and ADRESL read section 20 of the PIC18F458 data sheet
https://ww1.microchip.com/downloads/en/DeviceDoc/41159e.pdf

also
Code:
temp_res = ADC_Read(0) >>2 ;
TEMP= temp_res *(500/255);
PORTD = TEMP;
Usart_Write(TEMP); //sends signal
appears to transmit the binary value of the temperature, is that what you require or should you convert it to text before thransmission?

yup...i wan to convert to text before transmission...so is it correct??
 

no you are sending a binary value, to covert it to text you need something like
Code:
         char text[50];  
         sprintf(text, "temperature = %d degrees C", TEMP);
if the value of TEMP was 76 the array text[] would contain "temperature = 76 degrees C"
you then need to send the contents of the array to the Zigbee
 

but i using mikroc, the code you give can use in mikroc?? sorry for asking too much question as i just start to learn the code
 

I cannot help here! I use MPLAB with the C18 compiler not mikroc

Looking at my PIC18 code I appear to use vsprintf()
vsprintf - C++ Reference

rather than sprintf. For example, I use the following to print data onto an LCD
Code:
// similar to printf but prints to line on LCD
//    remember to cast parameters to match the formatstring
//     GLCDprintf(3, "Remote IP %d.%u.%u.%u", (int) node->IPAddr.v[0], (int)node->IPAddr.v[1],(int) node->IPAddr.v[2], (int)node->IPAddr.v[3]);
int GLCDprintf(const int line,  auto const far rom char  *formatstring, ...)
{
    char text[100]={0};
    va_list args;
    va_start(args, formatstring);
    vsprintf(text, formatstring, args);
    GLCDclearLine(line);
    GLCDstring(line, 1, text, 0); 
    return 0;
}
 

unsigned int temp_res;
unsigned int h;
void NumtoChar(char a)
{
unsigned char digit[3];
digit[0]=a/100;
digit[0]+=0x30;
a=a%100 ;
digit[1]=a/10;
digit[1]+=0x30;
digit[2]=a%1;
digit[2]+=0x30;
Usart_Write(digit[0]);
Usart_Write(digit[1]);
Usart_Write('.') ;
Usart_Write(digit[2]);
}
void main()
{
Usart_init(9600);
ADCON1 = 0x00;
TRISA = 0xFF;
TRISB = 0X00;
TRISC = 0X00;
TRISD = 0X00;
while(1){
temp_res = ADC_Read(0)>>2;
PORTB = temp_res;
h = (5000*temp_res/255) + 10;
NumtoChar(h);
Usart_Write(h);
delay_ms(3000);
}

this is my code, and it successful show the temperature. but it wonder me when the temperature show in the terminal is like 24.5J, 25.4J and other symbol like >#. how i can cancel off this extra figure and just show 3 digit only?
thx for the help
≥≥»≥»
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top