View previous topic :: View next topic |
Author |
Message |
atai21
Joined: 30 Dec 2010 Posts: 31
|
Detecting temperature and control the fan |
Posted: Mon Jan 24, 2011 12:09 am |
|
|
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
|
|
Posted: Mon Jan 24, 2011 2:59 am |
|
|
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
|
|
Posted: Mon Jan 24, 2011 3:05 am |
|
|
tq Ttelmah. You've been a great help. |
|
|
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Tue Jan 25, 2011 7:54 pm |
|
|
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
|
|
Posted: Tue Jan 25, 2011 9:05 pm |
|
|
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
|
|
Posted: Tue Jan 25, 2011 9:16 pm |
|
|
I see...TQ for your advice. |
|
|
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Sun Feb 06, 2011 6:06 pm |
|
|
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
|
|
Posted: Sun Feb 06, 2011 6:20 pm |
|
|
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
|
|
Posted: Thu Feb 24, 2011 11:18 pm |
|
|
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
|
|
Posted: Mon Feb 28, 2011 8:51 am |
|
|
Look at the datasheet for the SHT75 chip.
Is it RS-232 compatible ? |
|
|
atai21
Joined: 30 Dec 2010 Posts: 31
|
|
Posted: Mon Feb 28, 2011 7:14 pm |
|
|
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
|
|
Posted: Mon Feb 28, 2011 8:08 pm |
|
|
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
|
|
Posted: Mon Feb 28, 2011 9:58 pm |
|
|
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
|
|
Posted: Mon Feb 28, 2011 10:14 pm |
|
|
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
|
|
Posted: Tue Mar 01, 2011 12:46 am |
|
|
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 |
|
|
|