View previous topic :: View next topic |
Author |
Message |
r3stles
Joined: 11 Jun 2010 Posts: 6 Location: Suceava, Romania
|
help please to write code |
Posted: Fri Jun 11, 2010 7:17 am |
|
|
please help me.
how to write code for a microcontroller, which have a voltage input and output to give me a code 232. |
|
|
jacqueskleynhans
Joined: 10 Apr 2008 Posts: 109 Location: Cape Town, South Africa
|
|
Posted: Fri Jun 11, 2010 8:39 am |
|
|
You are going to have to explain yourself better otherwise no one is going to help you _________________ "THE ONLY EASY DAY WAS YESTERDAY" |
|
|
r3stles
Joined: 11 Jun 2010 Posts: 6 Location: Suceava, Romania
|
|
Posted: Fri Jun 11, 2010 9:47 am |
|
|
when lights a LED to send a hex code via RS232.
i have a sensor smoke, when smoke in room to light a LED. I want to connect the sensor to the microcontroller, and send a code via RS232 to know when smoke in the room |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jun 11, 2010 3:37 pm |
|
|
Post a link to the webpage and the data sheet for your smoke detector. |
|
|
r3stles
Joined: 11 Jun 2010 Posts: 6 Location: Suceava, Romania
|
|
|
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
|
Posted: Sat Jun 12, 2010 9:03 am |
|
|
What hex code do you want to send.
Pete |
|
|
r3stles
Joined: 11 Jun 2010 Posts: 6 Location: Suceava, Romania
|
|
Posted: Sat Jun 12, 2010 9:32 am |
|
|
for example: 53 4D 4F 4B 45 . |
|
|
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
|
Posted: Sat Jun 12, 2010 11:29 am |
|
|
I think you could do it like this
Code: |
#include <12C508A.h>
#FUSES NOWDT, INTRC, NOPROTECT, NOMCLR
#use delay(clock=4000000)
#use rs232(baud=9600,parity=N,xmit=PIN_B0,rcv=PIN_B1,bits=8)
void main()
{
while(true)
{
if (input(PIN_B3))
printf("53 4D 4F 4B 45");
}}
|
If you connect one side of the led to pin 4 of a pic12c508A and out of pin 7 you will get your hex value via RS232
If its wrong I am only trying to help as I have had lots of help from people on here.
thanks
Pete |
|
|
r3stles
Joined: 11 Jun 2010 Posts: 6 Location: Suceava, Romania
|
|
Posted: Sun Jun 13, 2010 12:15 am |
|
|
http://electronica.mozolici.com/test.bmp
This is schematic. To PIN_A1 is connect to sensor LM35, and to PIN_A2 is connect to smoke detector. When light a voltage is x mV to send code "53 4D 4F 4B 45" or "smoke".
The code for LM35 is :
Code: |
#include <16F877A.h>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232 (baud=9600,rcv=PIN_C7, xmit=PIN_C6,ERRORS, BRGH1OK)
float valoare;
float temperatura;
float tensiune;
void main()
{
setup_adc_ports( ALL_ANALOG );
setup_adc(ADC_CLOCK_INTERNAL );
set_adc_channel( 1 );
while(1)
{
//3 secunde Delay
delay_ms(1000);
//Citirea valorii ADC
valoare = read_adc();
//Convertirea valorii in Tensiune
tensiune = (valoare / 1023) * 5;
//Convertirea valorii in Temperatura
temperatura = tensiune * 100;
//Trimiterea datelor la EB501 prin Rx si Tx
printf("%.1f\n\r",temperatura);
}
}
|
How can writing code to pass both sensors.
The input is analogic. |
|
|
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
|
Posted: Sun Jun 13, 2010 3:35 am |
|
|
First of all thats not what you ask for.
Take a look at the " if " statment
Its 2 more lines of code to get it to work.
Also the LM35 does not detect smoke only Heat.
thanks
Pete |
|
|
r3stles
Joined: 11 Jun 2010 Posts: 6 Location: Suceava, Romania
|
|
Posted: Sun Jun 13, 2010 4:03 am |
|
|
OK.
how can I send the two temperature sensors are on different ports.
I use a temperature sensor and a smoke sensor. Both sensors are analog, and have an output voltage. |
|
|
pdl
Joined: 01 Jun 2005 Posts: 45 Location: UK
|
|
Posted: Sun Jun 13, 2010 9:22 am |
|
|
Ok you need to look at the if statement and else if statement.
if the ad is greater then the value you set do printf
else if the input is high then printf
go do it all again
If you convert this in to code I think its what you are looking for.
If I did it for you, you won't learn anything.
Pete |
|
|
P51D
Joined: 25 Jan 2010 Posts: 36
|
|
Posted: Sun Jun 13, 2010 10:03 am |
|
|
r3stles wrote: | OK.
how can I send the two temperature sensors are on different ports.
I use a temperature sensor and a smoke sensor. Both sensors are analog, and have an output voltage. |
you should to use two different adc-ports, then convert the value with a calculation in a useful value and send it via rs232
look at the printf statement
http://en.wikipedia.org/wiki/Printf:
Code: |
printf("hello world");
printf("%x",value);
printf("%d",value);
printf("Smoke:\t%d\n",smoke_val);
printf("Temperatur:\t%d\n",temp_val);
....
|
what erver you want.
I think your code shoud be something like that:
1) read smoke_sensor -> store in a variable
2) read temp_sensor -> store in a variable
3) calc smoke_val
4) calc temp_val
5) sending bothe values
It seems that you don't know the basics about c-programming-> look at this:
http://www.cprogramming.com/tutorial.html
good luck
P51D |
|
|
|