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

General question about 12F510

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



Joined: 04 May 2008
Posts: 260

View user's profile Send private message

General question about 12F510
PostPosted: Mon Feb 20, 2017 6:27 pm     Reply with quote

Hi

I try make a little program with an old pic "12F510", but without success.

First I try make turn on an LED on the pins:
Code:

output_high(PIN_B0);
delay_ms(1000);
output_high(PIN_B1);
delay_ms(1000);
output_high(PIN_B2);
delay_ms(1000);
output_high(PIN_B3);
delay_ms(1000);
output_high(PIN_B4);
delay_ms(1000);
output_high(PIN_B5);
delay_ms(1000);

output_low(PIN_B0);
delay_ms(1000);
output_low(PIN_B1);
delay_ms(1000);
output_low(PIN_B2);
delay_ms(1000);
output_low(PIN_B3);
delay_ms(1000);
output_low(PIN_B4);
delay_ms(1000);
output_low(PIN_B5);
delay_ms(1000);

When I try this program only blink LED on B5 and B4.... someone know why?

Other test:
Code:

if (input(PIN_B4)==1)
{
output_high(PIN_B5);
delay_ms(1000);
output_low(PIN_B5);
delay_ms(1000);
}



Is possible the .h have problems?

best regards,
Filipe Abrantes
shson



Joined: 12 Feb 2016
Posts: 11

View user's profile Send private message

PostPosted: Mon Feb 20, 2017 6:57 pm     Reply with quote

First off, B3 is an input-only pin as per PIC12F510 datasheet so you cannot use output_high nor output_low with B3.

Also the datasheet says on reset, all I/Os are configured as input. So use FIXED_IO to configure the pins as outputs:

Code:

#use FIXED_IO( B_outputs=PIN_B1, PIN_B2)


If the LED still doesn't blink, then it maybe because:

* incorrect clock/delay setting
* broken IO pin
* broken LED

Hope that helped
Eric
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 20, 2017 9:53 pm     Reply with quote

The following code shows how to configure the pins for digital i/o.
Code:
#include <12F510.h>
#fuses INTRC,NOWDT,IOSC4
#use delay(clock=4M)

// This macro is used to set the OPTION register.
#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}

//============================
void main()
{
// The following code will setup the pins for digital i/o.
setup_adc_ports(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);
set_options(0xC0);   // Allow use of GP2 for i/o

while(TRUE);
}



shson wrote:

Also the datasheet says on reset, all I/Os are configured as input. So use FIXED_IO to configure the pins as outputs.

You don't need to do that. CCS uses "standard i/o" mode as the default.
The compiler will automatically add TRIS statements to set the pins to be
outputs when you use the output_low() or output_high() functions.

@Ttelmah:
I didn't use the setup_rtcc() or setup_counters() method to set the OPTION
register, because it either didn't setup all the OPTION bits exactly as I
wanted, or it required a lengthy source code line, and produced tons of
ASM code. The set_options() method gave me exactly what I wanted
and in only two lines of ASM code. Also, I only have the older free (but
complete) vs. 4.073 of PCB. The above comments are true for that version.
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