PDA

View Full Version : Temperature using LM35 and wind direction using 3 optointerrupters with a 16F873A PIC



gerardobe
- 21st May 2007, 10:30
Hi!

First of all I'm a newbie on all this pic programming, This thread it's cos I need some help with coding on pic basic, I'm gonna make a little explanation about my project hope anyone can help me.

I gotta make a code that senses temperature using a LM35 temperature sensor, and the optointerrupters have to read the wind direction for example im gonna use 3 kind of discs colored with many positions, and each one of the sensors is gonna sense light in many positions, each one of them is gonna represent 3 different truth tables, and this ones are gonna show many wind directions has north , south , west and many others.

disk1|disk2|disk3|decimalnumber|direction
0 0 0 0 NORTHEAST
0 0 1 1 NORTH
0 1 0 2 WEST
0 1 1 3 NORTHWEST
1 0 0 4 EAST
1 0 1 5 SOUTHEAST
1 1 0 6 SOUTHWEST
1 1 1 7 SOUTH

I'm using a PIC 16F873A and a max232

This has to be send using to a computer via serial port, I'm seriously in need, i know there's experienced people around please help with this coding, or at least give me some clues where to start.

Have to say after all this im gonna send all the data to a program in VB that shows all the data taken from the sensors :), im very skilled doing .net and java programming, but i never programmed pics before, i already have a pic programmer, please help!

T.Jackson
- 21st May 2007, 11:26
First thing you need to do is draw up a schematic of what your attempting to do. Even better yet again would also include a block diagram and software flow chart. This way you make your intentions clear to yourself and anyone else trying to help you. 16f873A is quite possibly not the best to cut your teeth on. Go for a 16f628a to begin with.

mackrackit
- 21st May 2007, 12:42
give me some clues where to start.


WELCOME

Start off blinking the LED.

Get everything working a piece at a time.

Send data to hyper terminal.

Read the temperature sensor, ADC.

Send that to the PC.

SO ON AND SO ON.

If you have experience in other programing, you know what I mean.
HELLO WORLD

gerardobe
- 21st May 2007, 15:30
hehehe yeah i know what you mean, ok lets getting started i already have mi pc connected to mi pic and i have signal from the port , know what i have to do to receive temperature readings from it ? ;)

mackrackit
- 21st May 2007, 15:39
I do not use .net, but if it is anything like VB this might help.

http://www.rentron.com/serial.htm

Write code in whatever language you are using to read the serial port or use a terminal program for testing.

If it is an ADC problem with the PIC the above site has a good example.

Show some code and it will help us to answer questions.

skimask
- 21st May 2007, 15:53
hehehe yeah i know what you mean, ok lets getting started i already have mi pc connected to mi pic and i have signal from the port , know what i have to do to receive temperature readings from it ? ;)

So does this mean that you can reliably get a PIC to blink an LED? Yes/No? Can you do basic, rudimentary communications, whether it be thru a serial port or USB, between a PIC and a PC?

gerardobe
- 24th May 2007, 08:04
I already got the whole circuit working, I already tried turn on a led and it worked, so I need some help with this code, hope anyone can help me, thanks :D


DEVICE = 16F873A
CONFIG WDT_OFF, XT_OSC, CP_OFF, PWRTE_ON, BODEN_OFF , LVP_OFF , DEBUG_OFF
XTAL = 4
SYMBOL LED = PORTA.2
'SYMBOL DIRECTION = PORTB
DIM TEMPERATURE AS BYTE
DIM READ AS BYTE
DIM DIR0 AS BIT
DIM DIR1 AS BIT
DIM DIR2 AS BIT
TRISA=%00000001 'make in porta.0
ADCON1=%00001010 'analogic porta.0 y digital porta.2

ADIN_RES = 8 'bits to take un count
ADIN_TAD = FRC 'oscilator frecuency
ADIN_STIME = 50 'capacitor's charge time


DECLARE HSERIAL_BAUD =2400
DECLARE HSERIAL_RCSTA =%10010000
DECLARE HSERIAL_TXSTA = %00100010
DECLARE HSERIAL_CLEAR = ON
'DECLARE HSERIAL_PARITY = OFF

TEMPERATURE = ADIN 0
'HSERIN [DEC READ]
DELAYMS 600
WHILE 1
'HSERIN [DEC READ]
HSEROUT ["T"]
HSEROUT [DEC TEMPERATURE]
HSEROUT ["D"]
DIR0 = PORTB.0
DIR1 = PORTB.1
DIR2 = PORTB.2
IF DIR0=0 AND DIR1=0 AND DIR2=0 THEN HSEROUT [0]
IF DIR0=0 AND DIR1=0 AND DIR2=1 THEN HSEROUT [1]
IF DIR0=0 AND DIR1=1 AND DIR2=0 THEN HSEROUT [2]
IF DIR0=0 AND DIR1=1 AND DIR2=1 THEN HSEROUT [3]
IF DIR0=1 AND DIR1=0 AND DIR2=0 THEN HSEROUT [4]
IF DIR0=1 AND DIR1=0 AND DIR2=1 THEN HSEROUT [5]
IF DIR0=1 AND DIR1=1 AND DIR2=0 THEN HSEROUT [6]
IF DIR0=1 AND DIR1=1 AND DIR2=1 THEN HSEROUT [7]
HSERIN [WAIT(","),DEC LEER]
DELAYMS 500
HSEROUT [LEER]
'IF LEER=1 THEN LED=1 GOTO NEXT
'SIG:
'IF LEER=0 THEN LED=0 GOTO NEXT2:
'SIG2:
WEND
END


I'm having some issues reading temp, can anyone give me some help i dont know what to do now :(

mackrackit
- 24th May 2007, 13:30
Did you read the articles on this site?
http://www.rentron.com/pic.htm
Are you using Pic Basic?

skimask
- 24th May 2007, 14:28
I'm having some issues reading temp, can anyone give me some help i dont know what to do now :(

I'm sure somebody at the correct forums could help.
PicBasicPro <> Proton Basic

mister_e
- 24th May 2007, 15:42
If you're using DEC in HSERIN, you want to use DEC in HSEROUT as well. You USART settings seems weird to me, this following..

DECLARE HSERIAL_TXSTA = %00100010

But HSEROUT should take care of it. You could still try...


HSERIAL_RCSTA=$90
HSERIAL_TXSTA=$20
HSERIAL_SPBRG=25 ' 2400 Bauds
HSERIAL_CLEAR=ON

This set manually the PIC USART register.

Proton forum http://www.mister-e.org/Pics/bellow

www.picbasic.org/forum

elektoro2009
- 8th April 2008, 22:07
You can make this circuit.
http://www.picbasic.co.uk/forum/showthread.php?t=8493