View previous topic :: View next topic |
Author |
Message |
Sid2286
Joined: 12 Aug 2010 Posts: 119
|
problem programming 12F510 |
Posted: Wed Aug 31, 2016 5:04 am |
|
|
Hello,
I am trying to write a very basic code using for 12F510.
the code is as follows:
Code: |
#include <12F510.h>
#fuses INTRC,NOWDT,MCLR //,PROTECT
#use delay(clock=8M)
void main()
{
while(True)
{
if ( input(PIN_B2) == 0)
{
while(True)
{
output_toggle(Pin_B0);
delay_ms(500);
if( input(Pin_B1) == 0)
break;
}
}
output_low(Pin_B0);
if(input(Pin_B1) == 0 && delay_ms(3000))
{
output_high(Pin_B0);
delay_ms(100);
output_low(Pin_B0);
delay_ms(100);
output_high(Pin_B0);
delay_ms(100);
output_low(Pin_B0);
delay_ms(100);
output_high(Pin_B0);
delay_ms(100);
output_low(Pin_B0);
delay_ms(100);
}
}
} |
I am using pickit 3 for programming, using its stand alone software http://ww1.microchip.com/downloads/en/DeviceDoc/PICkit3%20Programmer%20Application%20v3.10.zip
it gives me programming successful though there is an error for OSSCAL.
so basically 12F510 isnt getting programmed, I tried the similar code for 18F4520 and it works same arrangements.
Request you to help me with this.
Thanks,
Sid |
|
|
RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
|
Posted: Wed Aug 31, 2016 5:26 am |
|
|
Code: | if(input(Pin_B1) == 0 && delay_ms(3000)) |
delay_ms() is not a normal C function. It is implemented by inline code and calls to compiler-supplied machine code routines. The manual states its return value is undefined. So this condition may never be true. This is not good programming practice. I am surprised that it worked at all, and not surprised that it doesn't now.
In the same vein, but not so bad, C takes zero as false and any other value as true (there originally was no boolean type), so there is no need to compare the result of input() with anything. Doing so wastes time, though I suspect the compiler may well optimise the comparison away. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Wed Aug 31, 2016 5:42 am |
|
|
I was thinking he wants a 'timed' input. IE wait for xx ms and IF 'something' didn't occur... then do something else.
There's is a 'timed' example (waiting xx ms for data from the serial port) in the CCS manual FAQ section. He could use that 'method' if he wants.
Jay |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 01, 2016 8:06 pm |
|
|
Quote: | I am using pickit 3 for programming, using its standalone software.
It gives me programming successful though there is an error for OSCCAL. |
If the OSCCAL value is accidentally erased, you can set a nominal value
manually. In the Pickit3 Standalone application, go to the Tools/Osccal
menu and select "Set manually". For the 12F510, you can type in: 0C00
This puts a "MOVLW 0x00" instruction in the last program memory location.
The 0x00 value is the center frequency value for OSCCAL. Program the
PIC and it should then run OK. |
|
|
|