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

problem programming 12F510

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



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

problem programming 12F510
PostPosted: Wed Aug 31, 2016 5:04 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 5:26 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed Aug 31, 2016 5:42 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 01, 2016 8:06 pm     Reply with quote

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