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

My code not work

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



Joined: 12 Nov 2007
Posts: 37

View user's profile Send private message

My code not work
PostPosted: Thu Jun 11, 2009 2:21 am     Reply with quote

This not work, why?
Code:

#include <16F526.h>
#device adc=8
//
#FUSES WDT                      //Watch Dog Timer
#FUSES INTRC                    //Internal RC Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES MCLR                     //Master Clear pin enabled
#FUSES IOSCFS_4                 //Internal oscillator 4MHz             
#FUSES NOCPD                    //No EE protection
//
#use delay(clock=4000000)
//
#use fast_io(B)
#use fast_io(C)
//
#define kaasu_pulssi PIN_C3
#define pulssi_on output_high(kaasu_pulssi)
#define pulssi_off output_high(kaasu_pulssi)
//
void main()
{
   set_tris_b(0b000011);
   set_tris_c(0b000111);
//
   output_float(PIN_B0);
   output_float(PIN_B1);
   output_float(PIN_C0);
   output_float(PIN_C1);
   output_float(PIN_C2);
//
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_wdt(WDT_2304MS);
   setup_comparator(NC_NC_NC_NC);
   restart_wdt();
//
   pulssi_off;
//
   while(1)
   {
      pulssi_on;
      delay_ms(1000);
      pulssi_off;
      delay_ms(1000);

   }
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 2:48 am     Reply with quote

Copy-and-paste error?
Code:
#define pulssi_on output_high(kaasu_pulssi)
#define pulssi_off output_high(kaasu_pulssi)
jjude



Joined: 12 Nov 2007
Posts: 37

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 3:39 am     Reply with quote

FvM wrote:
Copy-and-paste error?
Code:
#define pulssi_on output_high(kaasu_pulssi)
#define pulssi_off output_high(kaasu_pulssi)

Ääh - yes, copy paste error, i edit this, but code not work.

Is fuses OK?
Internal oscilator OK?

Code:
#include <16F526.h>
#device adc=8
//
#FUSES NOWDT //Nowatch Dog Timer
#FUSES INTRC //Internal RC Osc
#FUSES NOPROTECT //Code not protected from reading
#FUSES MCLR //Master Clear pin enabled
#FUSES IOSCFS_4 //Internal oscillator 4MHz
#FUSES NOCPD //No EE protection
//
#use delay(clock=4000000)
//
#use fast_io(B)
#use fast_io(C)
//
#define kaasu_pulssi PIN_C3
#define pulssi_on output_high(kaasu_pulssi)
#define pulssi_off output_low(kaasu_pulssi)
//
void main()
{
set_tris_b(0b000011);
set_tris_c(0b000111);
//
output_float(PIN_B0);
output_float(PIN_B1);
output_float(PIN_C0);
output_float(PIN_C1);
output_float(PIN_C2);
//
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_wdt(WDT_2304MS);
setup_comparator(NC_NC_NC_NC);
restart_wdt();
//
pulssi_off;
//
while(1)
{
pulssi_on;
delay_ms(1000);
pulssi_off;
delay_ms(1000);

}
}
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 5:56 am     Reply with quote

In the following sequence, the set_tris_x() statement is overridden, due to an CCS internal tris-register shadow variable, that isn't updated by set-tris(). It's possibly known behaviour for this type of 16F processor, but I regard it as a PCB bug. The most simple way to avoid the problem is not to use the fast_io option.
Code:
set_tris_c(0b000111);
output_float(PIN_C0);
output_float(PIN_C1);
output_float(PIN_C2);

With fast_io in effect, you must not mix set_tris_x() and output_float() for a particular port.


Last edited by FvM on Thu Jun 11, 2009 6:01 am; edited 1 time in total
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 6:01 am     Reply with quote

You have disabled the watchdog timer in your fuses with NOWDT but you then setup the WDT to fire every 2304MS 2.304 seconds.
You kick the WDT before entering your loop.
BUT
You then turn on the pin, wait 1 sec then turn it off then wait 1 sec (2sec + overhead) the WDT will fire.
Now this will cause the PIC to restart which should repeat the above causing the pin to toggle as you expect, but this is not what you want!

Put restart_wdt() in your loop or don't enable the WDT.

Anyway, what actually happens when you try this code ?
"but code not work" doesn't really help. Does PIN_C3 go high, stay low ?

You have MCLR enabled, what do you have connected to it ?
jjude



Joined: 12 Nov 2007
Posts: 37

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 6:07 am     Reply with quote

FvM wrote:
In the following sequence, the set_tris_x() statement is overridden, due to an CCS internal tris-register shadow variable, that isn't updated by set-tris(). It's possibly known behaviour for this type of 16F processor, but I regard it as a PCB bug. The most simple way to avoid the problem is not to use the fast_io option.
Code:
set_tris_c(0b000111);
output_float(PIN_C0);
output_float(PIN_C1);
output_float(PIN_C2);

With fast_io in effect, you must not mix set_tris_x() and output_float() for a particular port.


Thanks.

I deleting FAST_IO and code run OK.

Is this bug (4.092))?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 11, 2009 3:32 pm     Reply with quote

Here is a previous thread that discusses this issue:
http://www.ccsinfo.com/forum/viewtopic.php?t=38340
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