View previous topic :: View next topic |
Author |
Message |
filjoa
Joined: 04 May 2008 Posts: 260
|
General question about 12F510 |
Posted: Mon Feb 20, 2017 6:27 pm |
|
|
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
|
|
Posted: Mon Feb 20, 2017 6:57 pm |
|
|
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
|
|
Posted: Mon Feb 20, 2017 9:53 pm |
|
|
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. |
|
|
|