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.

I Need Your Ideas and look through my code

Status
Not open for further replies.

kapalterbang

Newbie level 3
Joined
Nov 27, 2009
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,311
I Need Your Ideas...

hye and good day...

currently i am doing my project which is detecting the surrounding temperature and then send it to the receiver...

the main components that i used is PIC16F877A LM35 temperature sensor and two XBee RF module...
I have already done my circuitry and i have test it before...so now i am working on the programming part...here is my code...


unsigned int cntr ;

long temp ; // Temperature in Celcius * 10

/*
* offset reference of the sensor : 0°C is 500 mV => 102.4
* since the sensor is factory calibrated, there is no need for adjustment
*/

int ref = 1024 ; // offset is multiplied by 10 to get tenth of degree

/*
* interrupt routine, called on each timer0 overflow
*/
void interrupt(void)
{
if(INTCON.T0IF) // timer 0 overflow ?
{
cntr++ ; // increment counter
INTCON.T0IF = 0 ; // done
}
}

/*
* program entry
*/
void main()
{
USART_Init(9600);
ADCON1 = 0x00 ; // set PORTA as analog input
TRISA = 0xff ; // set PORTA as inputs
TRISD = 0 ; // PORTD is output

OPTION_REG = 0x80 ; // start timer 0, no prescaler
INTCON = 0xA0 ; // allow timer 0 overflow interrupt

for(;; ) // forever
{
if(cntr >= 4000) // if enough time since last sample
{
/*
* read the sensor
*/
temp = Adc_Read(7) * 10 - ref ; // read RE2 ADC, adjust to 0°C

/*
* get the result in celcius * 10
* sensor temperature coefficient is +10mV/°C
* ADC resolution is 5000/1024 = 4.88 mV so one ADC point is 0.488°C
*/
temp *= 488 ;
temp /= 1000 ;

cntr = 0 ; // clear counter
USART_Write(temp);
}
}
}


so my question is do you think that the code is correct?

p/s: my circuit is working at 20MHz crystal

Thanx....
 

I Need Your Ideas...

Hello,
Your code looks fine.

Good Luck.
 

I Need Your Ideas...

is it?

tqvm..

but when I got the data from the sensor, it will be convert to digital right? and in order to send it to the receiver, is it necessary to convert the digital data to ascii by stating that in the program? i'm a bit confused about this..

Thanx...
 

Re: I Need Your Ideas...

hye and good day...

currently i am doing my project which is detecting the surrounding temperature and then send it to the receiver...

the main components that i used is PIC16F877A LM35 temperature sensor and two XBee RF module...
I have already done my circuitry and i have test it before...so now i am working on the programming part...here is my code...


unsigned int cntr ;

long temp ; // Temperature in Celcius * 10

/*
* offset reference of the sensor : 0°C is 500 mV => 102.4
* since the sensor is factory calibrated, there is no need for adjustment
*/

int ref = 1024 ; // offset is multiplied by 10 to get tenth of degree

/*
* interrupt routine, called on each timer0 overflow
*/
void interrupt(void)
{
if(INTCON.T0IF) // timer 0 overflow ?
{
cntr++ ; // increment counter
INTCON.T0IF = 0 ; // done
}
}

/*
* program entry
*/
void main()
{
USART_Init(9600);
ADCON1 = 0x00 ; // set PORTA as analog input
TRISA = 0xff ; // set PORTA as inputs
TRISD = 0 ; // PORTD is output

OPTION_REG = 0x80 ; // start timer 0, no prescaler
INTCON = 0xA0 ; // allow timer 0 overflow interrupt

for(;; ) // forever
{
if(cntr >= 4000) // if enough time since last sample
{
/*
* read the sensor
*/
temp = Adc_Read(7) * 10 - ref ; // read RE2 ADC, adjust to 0°C

/*
* get the result in celcius * 10
* sensor temperature coefficient is +10mV/°C
* ADC resolution is 5000/1024 = 4.88 mV so one ADC point is 0.488°C
*/
temp *= 488 ;
temp /= 1000 ;

cntr = 0 ; // clear counter
USART_Write(temp);
}
}
}


so my question is do you think that the code is correct?

p/s: my circuit is working at 20MHz crystal

Thanx....

Hello...i know I'm digging up a old thread..but wondering if you still have the circuit on you and the code possibly. Please give me a shout if you have .. I am using 16lf1939 .. your circuit will be a great help for me.

Thanks
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top