PIC kit 2 start-up problems

Discussion in 'Embedded Systems and Microcontrollers' started by poriet, Feb 26, 2010.

  1. poriet

    Thread Starter New Member

    Feb 26, 2010
    22
    2
    Hi,
    I've just bought the PIC kit 2 and started to go through the 'lessons' for the 16F690. I did some stuff on the 16F84 years ago, so I'm not a total newbie, but I cannot even get beyond lesson 2 as I cannot make sense of the syntax. It must be right, but it looks all wrong to me. Specifically:

    The program wants delay so it makes a loop using a file it names DELAY.
    This is a counter, the idea being to count down from 256. The instruction is DECFSZ. Now there are 2 things that baffle me ( only 2? ).

    1. Arent you supposed to put binary 1111 1111 into the file before you decrement it? The program doesnt.

    2. The DECFSZ syntax ( when I did the F84 ) was DECFSZ, file, d. The actual the instruction is DECFSZ, DELAY, f. What on Earth is 'f'? I cant see any mention of it on the datasheet; in any case, isnt it supposed to be either 0 or 1?

    Hope somebody can help me here as I'm well and truly stuck.
    If you want to send a private email as well, please feel free; I dont get to this URL often.

    Bruce
     
  2. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    1. You can, if you do not either "clear" it (DELAY = 0), or set it (DELAY=255) then the DELAY value could be anything...... but normally if it starts out at zero, then the DECFSZ will change the value to 255 anyways...

    2. w, and f are already declared as variables in some of the include files, w stands for 0 or working register, f stands for 1 or file register so in the line of code :

    Code ( (Unknown Language)):
    1. DECFSZ, DELAY, f
    it means to decrement DELAY and store the new value back into DELAY (f), skip the next instruction if new value = 0. You do not want to store new value in w, since then the DELAY will never decrement or change value, and your code will be stuck there....


    My .02
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Hi Bruce
    If you download the data sheet you will find all instructions described in section 15, I belive it is. Also here is the Pickit 2 site with firmware updates etc. http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en023805
    On this page you will also find the Low Pin Count User's Guide It will explain all the lessons. Then you are stuck like now. It is always a good idea to start the software debugger. Goto debugger in the toolbar. Then select tool->MPLAB sim. With this tool you can single step through your code and see how the registers change
     
  4. BMorse

    Senior Member

    Sep 26, 2009
    2,675
    234
    His problem is not the actual pickit 2, he doesnt understand the syntax used in the code for decrementing a count in a delay loop....
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I know but the Low Pin Count User's Guide go through the lessons and do some explaining, also about the code syntax used. Besides the link is useful for every PICKIT 2 user. :)
     
  6. poriet

    Thread Starter New Member

    Feb 26, 2010
    22
    2
    Hi,
    Thanks for the replies: I think I have it now, although I do think the syntax the programmer used was daft. I'm sure it's all very clever to do it his way, but surely the point is that he's dealing with newbies.
    Could you do it this way: MOVLW 256
    MOVWF Delay
    DECFSZ Delay,1
    etc

    If so, then I reckon it would be more understandable when youre learning.

    Bruce
     
  7. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    If the working register is only 8 bits, the largest number it can hold is 255.
    So, if you started off trying to move in 256, which is 1 0000 0000, you'd wind up with zero in there anyway...
     
  8. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    A far better way to do it would be
    Code ( (Unknown Language)):
    1.  
    2. CLRF Delay
    3. ....
    4. DECFSZ Delay, f
    5. ....
    6.  
    This code functions in exactly the same way as the original program but does not rely any default register conditions and clearly shows what the program does. It also conforms to the good programming practice of initialising any variable before you use it.

    By the way have you sorted out your issues DECFSZ destination field?
    The first statement in the program is "#include <p16F690.inc>". If you look at the file p16F690.inc you will find it is full of EQU statements telling the compiler where various registers and register bits are located. The first two line of that file define "w" as 0 and "f" as 1 so that instead of using the somewhat cryptic command "DECFSZ Delay, 1" you can write "DECFSZ Delay, f" and immediately see where the decremented value will be stored.
     
  9. poriet

    Thread Starter New Member

    Feb 26, 2010
    22
    2
    Hello Alex ( and others )
    This has all been a terrific help.
    I am now OK with the syntax of the DECFSZ instruction. The header file was a bit of a mystery, but I think I see now. Well, I looked at the 16F690.inc file, anyway. It's bewildering. Many of the registers I cant even see on the datasheet (is this header intended to cover other chips, or are all these registers on the 690? ).

    This forum is rather splendid. I think it's very decent of experienced programmers to spend time answering questions from beginners; it makes you proud to be human. Well, until you watch the 6 o'clock news, that is.

    One more question: the 690 has 4 banks of registers. When I did the 16F84 there were 2. One of the banks/pages had PORT A, as an example. The 690 has got PORT A on 2 different pages. Is something going on I dont know about?

    Bruce
     
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It is only one PORTA register in the 16f690. But you can accsess it via bank 0 and 2
     
    Last edited: Mar 1, 2010
  11. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    The PIC16F690 has much more RAM than the the old PICF84 so it needs to organise it into more bank to be able to address it all. Now you have 4 banks of registers instead of 2, and 2 bits (RP0 and RP1) in the STATUS register to control bank selection. To reduce some bank switching all the port and tris registers are duplicated across pairs of banks so it does not matter what RP1 is set to and you only have to worry about RP0 to select the correct port register.
     
  12. poriet

    Thread Starter New Member

    Feb 26, 2010
    22
    2
    Thanks again, guys.
    BTW, somebody put me on to Gooligum, an Australian site which looks jolly interesting. They have some tutorials just like the 'lessons' for the 690, except that he's opted for using the 12F509.
    The choice of the 690 for these beginner lessons is, in the opinion of some of us, less than fortunate. An astonishing device, the 690 is, nevertheless, sufficiently complicated to make life difficult for us beginners. It's sort of 'not seeing the wood for the trees'.
    I expect I'll be back soon to bother you with more damn silly questions, but, until then, au revoir.
    Bruce
     
Loading...