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 CCS Technical Support

Detecting temperature and control the fan
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

Detecting temperature and control the fan
PostPosted: Mon Jan 24, 2011 12:09 am     Reply with quote

Code:

#include <18F4550.h>

#fuses HS,NOWDT,PUT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#include<lcd.c>
#include<sht75.c>

#byte PORTB = 0xf81
#byte PORTC = 0xf82

#define      fanA      PIN_C4
#define      fanB      PIN_C5
#define      buzzer    PIN_C6

void main()
{
 float restemp, truehumid;
 lcd_init();
 sht_init();

 while(1)
 {
  sht_rd (restemp, truehumid);
  lcd_gotoxy(1,1);
  printf(lcd_putc, "Temp : %3.1f %cC   ", restemp, 223);
  printf(lcd_putc, "\nRH   : %3.1f %%   ", truehumid);
  delay_ms(500);        //delay 500 ms between reading to prevent self heating of sensor
 }

if (restemp<20)
{
fanA ON;
}

 else if (restemp>30)
{
fanA ON;
fanB ON;
}
else if (restemp>45 && truehumid<=50)
{
fanA ON;
fanB ON;

}
}

Hi...this is my code for detecting temperature and control the fan but when I try to compile it I'll get an error like this:

*** Error 76 "main.c" Line 33(6,8): Expect ;
*** Error 76 "main.c" Line 38(6,8): Expect ;
*** Error 76 "main.c" Line 39(6,8): Expect ;
*** Error 76 "main.c" Line 43(6,8): Expect ;
*** Error 76 "main.c" Line 44(6,8): Expect ;
5 Errors, 4 Warnings.

May I have someone to help me? TQ
Ttelmah



Joined: 11 Mar 2010
Posts: 19513

View user's profile Send private message

PostPosted: Mon Jan 24, 2011 2:59 am     Reply with quote

1) What makes you think you can have two words one after another as legal C syntax?. In C, you can assign values to things, or call functions. fanA ON (or any similar syntax), is not allowed. Command is (assuming high for 'ON'):

output_high(fanA);

or 'output_low' to turn it off.

2) Look carefully at your brackets. The close bracket after the 500mSec delay. How is the code after this point _ever_ to be reached?.

Best Wishes
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Mon Jan 24, 2011 3:05 am     Reply with quote

tq Ttelmah. You've been a great help.
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 7:54 pm     Reply with quote

Code:

#include <18F4550.h>

#fuses HS,NOWDT,PUT,NOPROTECT,NOLVP
#use delay(clock=20000000)

#include<lcd.c>
#include<sht75.c>

#byte PORTB = 0xf81
#byte PORTC = 0xf82

#define      fanA      PIN_C4
#define      fanB      PIN_C5
#define      buzzer    PIN_C6
#define      nozzle    PIN_C7

void main()
{
 float restemp, truehumid;
 lcd_init();
 sht_init();
printf(lcd_putc, "\b~WELCOME~ ",);
printf(lcd_putc, "\bTEMP&RH READER  ",);

 while(1)
 {
  sht_rd (restemp, truehumid);
  lcd_gotoxy(1,1);
  printf(lcd_putc, "Temp : %3.1f %cC   ", restemp, 223);
  printf(lcd_putc, "\nRH   : %3.1f %%   ", truehumid);
}
 

if (restemp<20)
{
output_high(fanA);
}

 else if (restemp>30)
{
output_high(fanA);
output_high(fanB);
}
else if (restemp>45 && truehumid<=50)
{
output_high(fanA);
output_high(fanB);
}

else if (restemp>98 && truehumid<=15)
{

output_high(fanA);
output_high(fanB);
output_high(nozzle);
output_high(buzzer);
printf(lcd_putc, "WARNING!!! ",);
}

delay_ms(500);        //delay 500 ms between reading to prevent self heating of sensor
}

Can someone help me...when I burn my code into Proteus simulation, the LCD just on but it didn't show the value.
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 9:05 pm     Reply with quote

I suggest you burn a real PIC and wire up the hardware and test.

Proteus is NOT the real world and full of BUGS !!

Too many to list
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Tue Jan 25, 2011 9:16 pm     Reply with quote

I see...TQ for your advice.
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Sun Feb 06, 2011 6:06 pm     Reply with quote

Can someone suggest me what other software (similar to Proteus) that can be use to burn my code? I really need to do the simulation first. TQ
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Feb 06, 2011 6:20 pm     Reply with quote

Burning your code refers to programming a PIC.
For me that's using MPLAB to transfer the code to a PICSTART Plus programmer which then 'burns' the PIC.
I then insert the PIC into my test board and see what happens.

Obviously there are other ways of doing it but it's been rock steady for the better part of 20 years of using PICs.
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Thu Feb 24, 2011 11:18 pm     Reply with quote

hai again,

Can someone help or give advice to me about this project.

In order to display data from SHT75 to LCD, I also need to display the data on PC (GUI netbeans IDE). I will connect sht75 to max232 and max232 to rs232 and connect it to PC. Do I need to code the PIC (18F4550) to make sht75 send data to PC?
TQ
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 8:51 am     Reply with quote

Look at the datasheet for the SHT75 chip.
Is it RS-232 compatible ?
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 7:14 pm     Reply with quote

hai all,
I already burn the code into PIC but the LCD still didn't show any value or words. Did I do it wrong?
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 8:08 pm     Reply with quote

I suggest you just test the LCD by printing 'welcome', pause a second, clear the display and loop forever.

This way you can verify the LCD-PIC wiring is correct without worrying about the temperature sensor.

Can't tell if you burned the PIC right,don't know how you wired up the LCD, do you have a stable 5 volt power supply ?Proper load capacitors for the xtal pins, etc?
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 9:58 pm     Reply with quote

http://www.2shared.com/photo/3UjQ7TOE/sht75.html

This is my connection for sht75, max232 and rs232,.can someone give me an advice about it?is my connection right?in order to send data from sht75 to PC (through rs232) i always see a code like this:

#use rs232(baud=9600,xmit=PIN_B1,rcv=PIN_B4,bits=8,stop=1,stream=ser)

so i alter into this since i have 2 data to transmit:

#use rs232(baud=9600,xmit=PIN_B1,xmit1=PIN_B0,bits=8,stop=1,stream=ser)

but i get this error says:

Error 100 "main.c" Line 5(5,74): USE parameter value is out of range "XMIT1"

i would really appreciate your help.TQ
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Feb 28, 2011 10:14 pm     Reply with quote

You cant have two xmit (or two recv parameters for that matter) in the same RS232 statement.

Make a second RS232 statement having XMIT= and RECV= using different
pins and change the stream name to ser1
_________________
Google and Forum Search are some of your best tools!!!!
atai21



Joined: 30 Dec 2010
Posts: 31

View user's profile Send private message

PostPosted: Tue Mar 01, 2011 12:46 am     Reply with quote

tq dyeatman...it helps...but i'm still confuse what is the different between

#use rs232(baud=9600, xmit=PIN_B2, rcv=PIN_B1, stream=PC)

and


#use rs232(baud=9600,xmit=PIN_B1,xmit1=PIN_B0,bits=8,stop=1,stream=ser)

TQ
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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