View previous topic :: View next topic |
Author |
Message |
SteveTroy
Joined: 25 Jun 2011 Posts: 7
|
Is that limitation problem CCS compiler at MPLab or ? |
Posted: Tue Jun 28, 2011 12:46 am |
|
|
Hello everyone,
I'm a student who is doing PIC base Control project. I'm not expert at PIC but I read about PIC and C programming. For source code, I couldn't build success at MPlab plugin CCS compiler. I think, I need to buy PCW compiler but I can't effort to buy. So, please point out code error or software limitation and any others ways. All i need it to generate hex code, I know sound like I'm stupid person looking the easiest way to solve problem without my own. I hope forum members can help me probably, plz kindly help me. Thanks for time.
Code: |
/******************************************************************************\
* *
* P R E P R O C E S S O R D I R E C T I V E S *
* *
\******************************************************************************/
#include <16F877A.h>
#device *=16 ADC=10
#use delay(clock=20000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
int16 photoTRIGGER = 635; // <310mV preset value for light switch
int16 minTEMP = 1372; // 670mV preset min sample value for T (30C)
int16 maxTEMP = 1597; // 780mV preset max sample value for T (38C)
int16 minHUMID = 614; // 350mV preset min value for H (30%RH)
int16 maxHUMID = 1065; // 520mV preset max value for H (52%RH)
int8 photoCOND;
int8 minTempCOND;
int8 maxTempCOND;
int8 minHumidCOND;
int8 maxHumidCOND;
// End Preprocessor Directives
#include "Include\Compiler.h"
#include "Include\Globals.h"
#include "Include\Misc.c"
/******************************************************************************\
* *
* F U N C T I O N P R O T O T Y P E S *
* *
\******************************************************************************/
void initTimers( void);
void initADC( void);
void timer1ISR( void);
void timer2ISR( void); // ISR does not stand for Illinois Street Residence
/******************************************************************************\
* *
* M A I N R O U T I N E *
* *
\******************************************************************************/
#pragma zero_ram // Interesting command ....
void main( void)
{
disable_interrupts(GLOBAL); // We don't want to be interrupted yet
delay_ms(500); // wait for voltages to stablize
Set_Tris_A(MY_TRISA); // Port A's I/O
Set_Tris_B(MY_TRISB); // Port B's I/O
delay_ms(50);
initTimers();
initADC();
delay_ms(50);
while(FOREVER)
{
readADC_1();
readADC_2();
readADC_3();
}
}
// End Main Routine
/******************************************************************************\
* *
* S U B - R O U T I N E I M P L E N T A T I O N S *
* *
\******************************************************************************/
// Purpose: Initializes timer interrupts
// Precondition: None
// Postcondition: Timers and interrupts are enabled
void initTimers(void)
{
setup_timer_1( T1_INTERNAL | T1_DIV_BY_8 ); // confusing?
setup_timer_2( T2_DIV_BY_4, 0x20, 2); // even more so!
enable_interrupts(INT_TIMER1);
enable_interrupts(INT_TIMER2);
enable_interrupts(GLOBAL);
timer1Count = 0;
timer2Count = 0;
timer3Count = 0;
timer4Count = 0;
timer5Count = 0;
}
// Purpose: Initializes ADC
// Precondition: None
// Postcondition: ADC is configured
void initADC(void)
{
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel( 0 );
delay_us(10);
}
//End Sub-Routine Implementions
/******************************************************************************\
* *
* I N T E R R U P T S E R V I C E R O U T I N E S *
* *
\******************************************************************************/
// Purpose: Timer1 ISR
// Precondition: initTimers called
// Postcondition: Timer1 counter updated
#INT_TIMER1
void Timer1ISR(void)
{
timer1Count++;
timer2Count++;
timer3Count++;
timer4Count++;
timer5Count++;
}
#INT_TIMER2
void Timer2ISR(void)
{
if (timer1Count == 0)
{
if ((ADC_1 * 10) < photoTRIGGER)
{
output_low(photo_switch);
photoCOND = 0;
}
else if ((ADC_1 * 10) > photoTRIGGER)
{
output_high(photo_switch);
photoCOND = 1;
}
}
else if ((timer1Count > 0) && (timer1Count < 300))
{
if (photoCOND == 1)
{
output_high(photo_switch);
}
else if (photoCOND == 0)
{
output_low(photo_switch);
}
}
else if (timer1Count == 300)
{
if (photoCOND == 1)
{
output_high(photo_switch);
}
else if (photoCOND == 0)
{
output_low(photo_switch);
}
timer1Count = 0;
}
if (timer2Count == 0)
{
if ((ADC_2 * 10) > maxTEMP)
{
output_high(fan_switch);
maxTempCOND = 1;
}
else if ((ADC_2 * 10) < maxTEMP)
{
output_low(fan_switch);
maxTempCOND = 0;
}
}
else if ((timer2Count > 0) && (timer2Count < 300))
{
if (maxTempCOND == 1)
{
output_high(fan_switch);
}
else if (maxTempCOND == 0)
{
output_low(fan_switch);
}
}
else if (timer2Count == 300)
{
if (maxTempCOND == 1)
{
output_high(fan_switch);
}
else if (maxTempCOND == 0)
{
output_low(fan_switch);
}
timer2Count = 0;
}
if (timer3Count == 0)
{
if ((ADC_2 * 10) < minTEMP)
{
output_high(heater_switch);
minTempCOND = 1;
}
else if ((ADC_2 * 10) > minTEMP)
{
output_low(heater_switch);
minTempCOND = 0;
}
}
else if ((timer3Count > 0) && (timer3Count < 300))
{
if (minTempCOND == 1)
{
output_high(heater_switch);
}
else if (minTempCOND == 0)
{
output_low(heater_switch);
}
}
else if (timer3Count == 300)
{
if (minTempCOND == 1)
{
output_high(heater_switch);
}
else if (minTempCOND == 0)
{
output_low(heater_switch);
}
timer3Count = 0;
}
if (timer4Count == 0)
{
if ((ADC_3 * 10) < minHUMID)
{
output_high(mister_switch);
minHumidCOND = 1;
}
else if ((ADC_3 * 10) > minHUMID)
{
output_low(mister_switch);
minHumidCOND = 0;
}
}
else if ((timer4Count > 0) && (timer4Count < 300))
{
if (minHumidCOND == 1)
{
output_high(mister_switch);
}
else if (minHumidCOND == 0)
{
output_low(mister_switch);
}
}
else if (timer4Count == 300)
{
if (minHumidCOND == 1)
{
output_high(mister_switch);
}
else if (minHumidCOND == 0)
{
output_low(mister_switch);
}
timer4Count = 0;
}
if (timer5Count == 0)
{
if ((ADC_3 * 10) > maxHUMID)
{
output_high(dehumid_switch);
maxHumidCOND = 1;
}
else if ((ADC_3 * 10) < maxHUMID)
{
output_low(dehumid_switch);
maxHumidCOND = 0;
}
}
else if ((timer5Count > 0) && (timer5Count < 300))
{
if (maxHumidCOND == 1)
{
output_high(dehumid_switch);
}
else if (maxHumidCOND == 0)
{
output_low(dehumid_switch);
}
}
else if (timer5Count == 300)
{
if (maxHumidCOND == 1)
{
output_high(dehumid_switch);
}
else if (maxHumidCOND == 0)
{
output_low(dehumid_switch);
}
timer5Count = 0;
}
}
|
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Tue Jun 28, 2011 5:28 am |
|
|
Do you get some sort of error message saying some limit is exceeded?
Are you using the free demo version of the CCS compiler?
You have a huge amount of code in your timer2 interrupt. Try to avoid that, but it should not generate an error. It is usually best to have the interrupt set a flag, and do the real work in the main code. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
SteveTroy
Joined: 25 Jun 2011 Posts: 7
|
|
Posted: Tue Jun 28, 2011 7:53 am |
|
|
Thanks for your reply. My problem showed
Code: | #include "Include\Compiler.h"
#include "Include\Globals.h"
#include "Include\Misc.c" |
does not found those headers & .c. Where can I get or how to built those headers files please? Thanks in advance. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19509
|
|
Posted: Tue Jun 28, 2011 9:37 am |
|
|
None of those are 'standard' files. They come from the same source you got your code. They are not part of the CCS compiler.
A couple look like ones that are normally part of the C's used as part of Unix. I'd strongly suspect the code you have has been 'ported' from something like a Linux version, to CCS, and these files were also converted.
You need to get the versions for the code you have. Only 'standard' files, like stdio.h, are meant to provide reasonably portable functions, these could contain _anything_. I's guess, the first has some settings meant to relate to the compiler in use. The second has global variable defintions, and the last 'miscellaneous' other stuff. You _need_ to get the originals. You can't create them. It's be faster to re-write the code completely, than to try to recreate files like this.
Best Wishes |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 28, 2011 12:26 pm |
|
|
Quote: | #include "Include\Compiler.h"
#include "Include\Globals.h"
#include "Include\Misc.c"
does not found those headers & .c. Where can I get or how to built those
headers files please? Thanks in advance.
|
The fact that you're asking for this shows that you got this code from
somewhere on the internet but you didn't tell us.
To do a little detective work using Google, I searched for two of these
variables which look fairly unique:
Quote: |
photoTRIGGER minTEMP
|
That quickly shows me the code is from this website:
http://courses.engr.illinois.edu/ece445/projects/spring2008/
This allows me to do a site search for those files using Google again:
Quote: |
site:courses.engr.illinois.edu/ece445/projects/spring2008/ compiler.h |
Then I quickly find an MS Word .doc file which says:
Quote: |
Figure E.2 contains the Globals.h file, which creates global structures and
variables. Figure E.3 contains the Compiler.h file, etc.
|
Looking near the end of the .doc file shows all the files are there.
http://courses.engr.illinois.edu/ece445/projects/spring2008/project9_final_paper.doc |
|
|
SteveTroy
Joined: 25 Jun 2011 Posts: 7
|
|
Posted: Tue Jun 28, 2011 2:31 pm |
|
|
Thanks you so much brothers. I found two headers files and Misc.c file from the sample test source codes but it's still fail. Maybe they are different from the source code that i took. Thanks for your help brothers.
These are two headers & Misc.c
Code: | http://www.mediafire.com/?dq44mszi2336b |
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 28, 2011 5:35 pm |
|
|
The project is a mess. It contains parts of files from different versions of
code. The definitions are changed in different versions. I tried to make it
work for a while, but I don't want to work on it anymore. It's a waste of
time. |
|
|
SteveTroy
Joined: 25 Jun 2011 Posts: 7
|
|
Posted: Tue Jun 28, 2011 9:51 pm |
|
|
Thanks bro, my bad |
|
|
|