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 support@ccsinfo.com

driving leds with port a,c or d

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



Joined: 18 Jun 2009
Posts: 1
Location: ankara

View user's profile Send private message MSN Messenger

driving leds with port a,c or d
PostPosted: Fri Jul 10, 2009 2:01 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 10, 2009 4:43 am     Reply with quote

Post your code and we can help you.

My crystal ball is broken curently. Rolling Eyes
Guest








PostPosted: Fri Jul 10, 2009 5:00 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Jul 10, 2009 8:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jul 10, 2009 8:37 am     Reply with quote

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 Smile

I personally hate to see them in C code.
bungee-



Joined: 27 Jun 2007
Posts: 206

View user's profile Send private message

PostPosted: Fri Jul 10, 2009 5:02 pm     Reply with quote

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 Wink
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.
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