View previous topic :: View next topic |
Author |
Message |
anilresat
Joined: 18 Jun 2009 Posts: 1 Location: ankara
|
driving leds with port a,c or d |
Posted: Fri Jul 10, 2009 2:01 am |
|
|
Hi everyone i m a little bit new to programming pics and ccs c. My poblem is i can drive leds from only portb. When i change portb words into portc or other ones the code doesn't work. What can be the reason? Is it because of an error in the fuses or something different? Thanks... |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Fri Jul 10, 2009 4:43 am |
|
|
Post your code and we can help you.
My crystal ball is broken curently. |
|
|
Guest
|
|
Posted: Fri Jul 10, 2009 5:00 am |
|
|
my code is:
Code: | #include <16f877A.h>
#fuses XT,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay(clock=4000000)
#use fast_io(c)
/*************ANA PROGRAM FONKSÄ°YONU*********************/
void main ()
{
setup_adc_ports(NO_ANALOGS);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1););
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
set_tris_c(0x00);
output_c(0x00);
basla:
output_high(pin_c0);
delay_ms(500);
output_low(pin_c0);
delay_ms(500);
goto basla;
} |
|
|
|
mkuang
Joined: 14 Dec 2007 Posts: 257
|
|
Posted: Fri Jul 10, 2009 8:28 am |
|
|
This is your code? There is an obvious typo here:
Code: |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1););
|
but that aside when you say it does't work what do you mean? Did you scope out pin C0 and see whether it toggles every 500ms?
It could just be me but I don't think "goto" statements in C are currently in favor. |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Fri Jul 10, 2009 8:37 am |
|
|
Stricktly speaking goto statements are not good C programming (old school). Some people will dissagree but I for one have NEVER had to use them in C. Too much badness can come of it
I personally hate to see them in C code. |
|
|
bungee-
Joined: 27 Jun 2007 Posts: 206
|
|
Posted: Fri Jul 10, 2009 5:02 pm |
|
|
You could write code for led blinking like this:
Code: |
while (1)
{
output_toggle(pin_c0);
delay_ms(500);
}
|
This is all that you need in main
Looking at your program, don't use #use fast_io, let CCS do that for you. So you do not need to set he TRIS register at all. If you really need speedy port changes then you need #use fast_io but in all other cases not. |
|
|
|