View previous topic :: View next topic |
Author |
Message |
jjude
Joined: 12 Nov 2007 Posts: 37
|
My code not work |
Posted: Thu Jun 11, 2009 2:21 am |
|
|
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
|
|
Posted: Thu Jun 11, 2009 2:48 am |
|
|
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
|
|
Posted: Thu Jun 11, 2009 3:39 am |
|
|
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
|
|
Posted: Thu Jun 11, 2009 5:56 am |
|
|
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
|
|
Posted: Thu Jun 11, 2009 6:01 am |
|
|
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
|
|
Posted: Thu Jun 11, 2009 6:07 am |
|
|
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
|
|
|
|