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

Can't use Functions! Inline only.

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



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Sep 03, 2009 12:09 am     Reply with quote

Quote:

void main()
{
int x;

while(1)
{
output_high(PIN_E2);
for(x=0;x<2000;x++);
output_low(PIN_E0);
for(x=0;x<20000;x++);
}
}

The main problem I see is that 'x' is declared as an 'int', but you're
comparing it to values that are larger than 255. CCS is not like other
compilers. It has different data types. In CCS, an 'int' is an 8-bit
unsigned integer. To fix it, you need to declare 'x' as an 'int16', which
is a 16-bit unsigned integer.

Also, there's no need to use for() loops for delays. CCS has built-in
delay functions such as delay_us() and delay_ms() that are much better.


Quote:

setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF|ADC_TAD_MUL_0);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);

Also, this setup code put in by the Wizard is unnecessary. These PIC
modules are disabled by default upon power-on reset. You don't need
to disable them again with code.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Sep 03, 2009 6:15 am     Reply with quote

Code:
setup_spi(SPI_SS_DISABLED);
Like PCM Programmer already mentioned this line is not required, but even worse it is wrong! Disabling the SPI is done with:
Code:
setup_spi(FALSE);
The original code will set an invalid configuration with unknown results.


Quote:
while(1)
{
output_high(PIN_E2);
for(x=0;x<2000;x++);
output_low(PIN_E0);
for(x=0;x<20000;x++);
}
My guess is you want to toggle the output pin? I suggest you use the same pin in both lines...
YendorZ



Joined: 31 Jul 2009
Posts: 3

View user's profile Send private message

PostPosted: Thu Sep 03, 2009 8:22 am     Reply with quote

Thanks for all the extremely quick responses. By doing this quick example, hacking some very wrong-headed changes, I've done a good job at demonstrating my idiocy. Guess I need to work on this stuff earlier in the day. You're seeing the end result of some stiff frustration.

About the code, I can say that:

1. It still does not work, even omitting the 'x' variable and the 'for' loops.
2. Even with both output_high and output_low using PIN_E2, it did not work. I has switched from PIN_E2 to PIN_E0 to try another output. Neither one ever responded.

The intention is indeed to toggle an output. This is usually a very quick first step in getting a project running, just to see if things are working...it usually lasts 5 minutes in this state, not hours.

I will re-post this evening with something a little more concise, and correct.

I find it interesting that the auto-generated wizard code is so incorrect. Thanks for the tip that it's not necessary.

Thanks for all the quick responses as well! This forum is the last thing keeping me from migrating to TI's MSP430 line of processors. I still have a legacy of PIC-based implementations however...
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