Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Weather Station C sample code

Status
Not open for further replies.

ecko1972

New Member
I just got a freescale project board and micrcontroller. I want to try to build an at home weather station with pressure and temp. using the microcontroller and sensors. I would like to program the project with C seeing as it is common but I am unfamiliar with the language. If anyone knows where I could find some sample code for this project I would appreciate it.

I got an LM34 temp sensor and an MPX12D pressure sensor and a MPXA611... pressure sensor. I would like to use the temp sensor as a thermometer and one of the pressure sensors as a barometer. I have located the data sheets for connections but I am unsure of how to write a code to control the sensors.
 
I'm not very familiar with any language honestly. I just got some books to try to learn C though. Any good sample code would help as long as I could figure it out with the C books i got.
 
The C compiler for your chip should have some simple sample programs in C. Maybe under getting started.

You have to walk prior to running. The weather station is not a first project sort of thing. Start by blinking an LED or two. Learn to use the ADC to read analog voltages.

Then figure out how to read each of your sensors etc.

3v0
 
I got an LM34 temp sensor and an MPX12D pressure sensor

These two are analog sensors which output a voltage relative to the current temperature/pressure. The LM34 is easily usable with a microcontroller as it outputs 10mV/C.

So you'll need to investigate how to read a voltage with your processors A/D circuitry and how to display it, probably on a computer via serial or an LCD.
 
I got a few of the LEDs to flash with different duty cycles using the microcontroller. I'm now reading the ADC section to implement the sensors, as they are analog and must be converted to digital. I'll keep working at it, but any other helpful online references would be appreciated.
 
As far as I know there is not a lot of Freescale/Motorola experiance here. A few years back I used the 68hc11 and a few other Motorala chips but have no current experiance.

Without knowing which Freescale processor and what language you are using it would be difficult to provide meaningful help at this point.

Just the same you are making good progress. Keep up the good work.

3v0
 
I'm using the MC9S12C32 with HCS12. So far this is what I've come up with for ADC for the temp. sensor. Please, help I'm stuck!



**********************************************************
#include <hidef.h> /* common defines and macros */
#include <mc9s12c32.h> /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12c32"

#define TC1MS 1996 //???????????
#define ATDCTL2_VAL 0xC0; //ATD pwr up, ffc, no et. trig., no intrpt
#define ATDCTL3_VAL 0x20; //(4) conversions / sequence
#define ATDCTL4_VAL 0x83; //8-bit res,(2) A/D clocks/sample, presclr(8)
#define ATDCTL5_VAL 0x31;

void main(void) {
char i;
volatile unsigned int atd_value;

ATDCTL2 = ATDCTL2_VAL;

for(i = 0; i < 20; ++i); //Generate a delay > 20 micro secs.

ATDCTL3 = ATDCTL3_VAL;
ATDCTL4 = ATDCTL4_VAL;

DDRT_DDRT1 = 1;
PTT_PTT1 = 1;

for( ; ; ) {

ATDCTL5 = ATDCTL5_VAL; //ADC initiated
while(ATDSTAT0_SCF == 0);
atd_value = (ATDDR0L + ATDDR1L + ATDDR2L + ATDDR3L) /4;
} /* wait forever */
}
**********************************************************
 
Which bit are you stuck with? There isn't much experience with that processor here, but perhaps people could help with specifics.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top