View previous topic :: View next topic |
Author |
Message |
aldina
Joined: 09 Oct 2009 Posts: 26
|
16F526 |
Posted: Mon Dec 14, 2015 10:16 am |
|
|
Hi,
I'm using a 16F526 to make a simple flashing LED. My code:
Code: |
#include <16F526.h>
#fuses INTRC, MCLR, NOPROTECT, NOWDT
#use delay(clock=8000000)
//#use fast_io(B)
//#use fast_io(C)
void main()
{
set_tris_c(0x00);
//SETUP_ADC(ADC_OFF);
//SETUP_ADC_PORTS(NO_ANALOGS);
while(true)
{
output_c(0x00);
delay_ms(2000);
output_c(0x01); // C0 - ON
delay_ms(2000);
}
}
|
My version is 5.049
I have compiled and it has no errors.
I've programmed but LED is not flashing. I have no C0 output variation.
Maybe the fuses are wrong. Please help me.
BR |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9224 Location: Greensville,Ontario
|
|
Posted: Mon Dec 14, 2015 12:15 pm |
|
|
though I don't use that PIC
1) have you a pullup on MCLR pin ?
2) any other peripherals on C0 ? Those MUST be disabled to let it work as a simple I/O port....
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Dec 14, 2015 5:16 pm |
|
|
The comparators in the 16F526 are on by default. In my old version 4.73
of the PCB compiler, it doesn't turn them off at the start of the program.
That old version doesn't even support the setup_comparator() function
correctly. I don't know if your vs. 5.049 has fixed all of this.
You can check the .LST file at the start of main to see if the compiler
inserts code to write 0x00 to the CM1CON0 and CM2CON0 registers.
If not, you should add code to the start of main() to turn off the
comparators.
The following line should work, but I don't have your version of the
compiler to test it:
Code: | setup_comparator(NC_NC_NC_NC); |
|
|
|
aldina
Joined: 09 Oct 2009 Posts: 26
|
|
Posted: Tue Dec 15, 2015 4:14 am |
|
|
Thank you PCM :-)
That's it. It is working now.
Now I have a new doubt about this PIC. I'm trying to save some data on EEPROM memory. I have made it with PIC16F688 and it's working but the same logic isn't working with 16F526. Can you tell me something about?
My code:
Code: |
#include <16f526.h>
#fuses INTRC,NOWDT,NOMCLR,PROTECT
#use delay(clock=8000000)
int flag_system = 0;
void System_A(){
flag_system=0;
write_eeprom(0,0);
}
void System_B(){
flag_system=1;
write_eeprom(0,1);
}
void SelectSystem(){
int8 flag=0;
flag=read_eeprom(0);
if(flag==0)
System_A();
else
if(flag==1)
System_B();
delay_ms(10);
while(true){
if(input(PIN_B2)){
delay_ms(20);
if(input(PIN_B2)){
if(flag_system==0){
delay_ms(50);
Ststem_B();
break;
}
else
if(flag_system==1){
delay_ms(50);
System_A();
break;
}
}
}
break;
}
delay_ms(10);
}
void main() {
set_tris_c(0x00);
SETUP_ADC(ADC_OFF);
SETUP_ADC_PORTS(NO_ANALOGS);
setup_comparator(NC_NC_NC_NC);
while(true)
{
SelectSystem();
if(flag_system==0){ // Sistema A
output_high(PIN_C0); // Leds on 30ms
delay_ms(50); // Ton
output_low(PIN_C0);
delay_ms(50);
output_high(PIN_C0); // Leds on
delay_ms(50); // Ton
output_low(PIN_C0);
delay_ms(50);
output_high(PIN_C0); // Leds on
delay_ms(150); // Ton
output_low(PIN_C0);
delay_ms(450);
}
else
if(flag_system==1){
output_high(PIN_C0); // Leds on 30ms
delay_ms(50); // Ton
output_low(PIN_C0);
delay_ms(50);
output_high(PIN_C0); // Leds on
delay_ms(150); // Ton
output_low(PIN_C0);
delay_ms(450);
}
}
} |
|
|
|
Mike Walne
Joined: 19 Feb 2004 Posts: 1785 Location: Boston Spa UK
|
|
Posted: Tue Dec 15, 2015 11:33 am |
|
|
Work on the KISS principle.
Get rid of most of the code, test reading & writing to EEPROM only.
Mike |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Dec 15, 2015 12:24 pm |
|
|
Ask yourself this:
What happens if the value in EEPROM is something other than 1 or 0 ??
When you program , unless otherwise handled by your program fixture - it is likely going to be set to 0xFF or some other integer you are not expecting.
you need to add an ELSE statement to your system_test() to handle that. |
|
|
|