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

K150 USB PIC programmer

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



Joined: 03 Dec 2013
Posts: 4
Location: Greece

View user's profile Send private message

K150 USB PIC programmer
PostPosted: Mon Feb 24, 2014 5:02 pm     Reply with quote

Hello,
Has anybody tried the K150 USB PIC programmer?
I wrote a code in CCS and I simulated it in Proteus. Then, I tried to program the PIC16F877A (it is the first time that I am programming a PIC) but an error was occurred: ''fuse error 0x2007, Good 0x3F71, Bad 0x3FFF ''. After that I performed the following actions: Read- Verify- Blank, successfully. Then, I changed the ''fuse edit''. I turned all fuse to disabled, except the WRT and I programmed the PIC again without errors this time. I placed the PIC on the breadboard but it is not working correctly.

https://imageshack.com/i/16i1wrj

Code:

#include "16f877a.h"
#fuses XT
#use delay (clock=4M)

int1 flag =0;
int1 flag2 =0;
void main()
{
 
while(TRUE)
{
   IF((input(pin_a0)==1)&&(flag==0))
      {
      output_high(PIN_b0);
      delay_ms(14000);
      output_low(PIN_b0);
      loop:
      IF(input(pin_a0)==1)
         {
         flag=1;
         goto  loop;
         }
      flag=0;
      } 

   IF((input(pin_a1)==1)&&(flag2==0))
      {
      output_high(PIN_b0);
      delay_ms(18000);
      output_low(PIN_b0);
      loop2:
      IF(input(pin_a1)==1)
         {
         flag2=1;
         goto  loop2;
         }
      flag2=0;
      } 

}
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Tue Feb 25, 2014 1:28 am     Reply with quote

Lets step through things in order:

First the programming.

Now the error is saying that that it can't program the configuration word. If you look at the bit pattern it is trying to write, this has 'LVP' (low voltage programming) turned 'on'. This must normally always be off. Add the fuse NOLVP to your code. When you manually cleared all the fuses, this one was one of the ones you turned off.

Then the code.
Ugh!....

Seriously, never use jumps, unless you are a 'technical' programmer, and know what the state of the stack is. There are occasions where 'goto' may be used, but generally in reasonably modern languages (anything written in the last 30+ years), goto should be treated as if it carried bird flu...

Your 'loop' codes, can be done with:
Code:

      while (input(pin_a0)==1)
         flag=1;
      flag=0;


However you need to think about what you are trying to do. This can only exit with 'flag==0', so flag is always going to be zero in the external loop, so effectively does nothing.....

Now, first thing to do, is to verify that your chip is actually running. Do a search here for the simple 'flash an LED' test. This should be the starting point. 'All fuses disabled', may have switched you to LP or RC oscillator, and in which case nothing will happen.

Use:
Code:

include "16f877a.h"
#fuses XT,NOLVP,PUT,NOWDT,NOWRT,NODEBUG,NOCPD
#use delay (clock=4M)

as your header, and just loop flashing an LED at 1 second intervals.
Verify it does flash at one second intervals, before proceeding.

You also see one of the big problems with Proteus (look at the post near the top of the forum). The first problem is that it will 'believe' what you tell it, even if this is impossible. So fuse combinations that can't run will be accepted, even if the real chip can't work with them...
Worse though, the simulation of more complex peripherals is deeply flawed in many cases, and it'll tell you things don't work, that do, while other things that can't work, are happily accepted. You can waste a lot of time with Isis (the actual simulator used by Proteus)...
nick...7



Joined: 03 Dec 2013
Posts: 4
Location: Greece

View user's profile Send private message

PostPosted: Tue Feb 25, 2014 4:43 pm     Reply with quote

Thank you Ttelmah,
I will try to follow your instructions!

I wrote this code because I want to operate an electromagnetic solenoid. I entered a switch between the pins A0 and A1 in order to be able to use two different timers. I also wrote the loop with 'goto' in case that something goes wrong and button1 stack. Without this the solenoid electromagnetic may be destroyed.


[img]https://imageshack.com/i/go57vfj[/img]

green Led (proteus) ----> electromagnetic solenoid
Ttelmah



Joined: 11 Mar 2010
Posts: 19552

View user's profile Send private message

PostPosted: Wed Feb 26, 2014 1:34 am     Reply with quote

That is exactly the reason _not_ to use goto:.....

Problem is that there is no guarantee that the stack on a processor is maintained if you use goto. This then can lead to program crashes.

The basic logic is wrong in the code, so get it right before attaching anything.
Currently, if either button stays 'high', it'll loop for ever, and as I pointed out, it can only ever exit the loop with each flag set to '0', so they are doing nothing...
Code:

      loop2:
      IF(input(pin_a1)==1) //if pin is high
         {
         flag2=1;
         goto  loop2; //go back to loop2 if pin high forever.....
         }
      flag2=0; //only ever get here when pin is low


Remember also that anything electro-magnetic, will involve spikes being generated when it switches 'on', and flyback generation (which needs to go somewhere), when it switches 'off'. Be careful with snubbing, and ground layout, or you endanger the PIC...
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