CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

help please to write code

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
r3stles



Joined: 11 Jun 2010
Posts: 6
Location: Suceava, Romania

View user's profile Send private message

help please to write code
PostPosted: Fri Jun 11, 2010 7:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 8:39 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 9:47 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 11, 2010 3:37 pm     Reply with quote

Post a link to the webpage and the data sheet for your smoke detector.
r3stles



Joined: 11 Jun 2010
Posts: 6
Location: Suceava, Romania

View user's profile Send private message

PostPosted: Sat Jun 12, 2010 3:46 am     Reply with quote

http://electronica.mozolici.com/100_3958.JPG
http://electronica.mozolici.com/100_3957.JPG

This is sensor, I did not find any datasheet.

When it senses smoke, LED lights, and the terminal voltage is 100mV.

LED when receiving blood, I want to send via RS232
pdl



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

PostPosted: Sat Jun 12, 2010 9:03 am     Reply with quote

What hex code do you want to send.

Pete
r3stles



Joined: 11 Jun 2010
Posts: 6
Location: Suceava, Romania

View user's profile Send private message

PostPosted: Sat Jun 12, 2010 9:32 am     Reply with quote

for example: 53 4D 4F 4B 45 .
pdl



Joined: 01 Jun 2005
Posts: 45
Location: UK

View user's profile Send private message

PostPosted: Sat Jun 12, 2010 11:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 12:15 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 3:35 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 4:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 9:22 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Jun 13, 2010 10:03 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group