Pic Basic Pro Syntax


Closed Thread
Results 1 to 4 of 4
  1. #1
    Finn's Avatar
    Finn Guest

    Question Pic Basic Pro Syntax

    I am programming the pic16f876 and was using the sample code on the Melabs website (key.bas) for the Lab X1 kit and had a question in regards to some of the commands. I am new to pic programing so please bare with me:
    -If row != to $F
    Does anyone know what the syntax $F or $F0 means.
    I am also a little fuzzy about the "ncd,dcd" and ">>" commands. Can anyone help?

  2. #2
    Join Date
    Jan 2004
    Location
    Exeter, England
    Posts
    25


    Did you find this post helpful? Yes | No

    Default

    The $ sign indicates a hex number i.e $F would be the same as 15 in decimal and $F0 would be 240 in decimal.

    I'm afraid I'm fuzzy myself about ncd and dcd.

    >> is shifting to the right for example var>>1 would be the same as dividing var by two.
    Keep your motor running

  3. #3
    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    237


    Did you find this post helpful? Yes | No

    Lightbulb

    Hi,

    NCD will tell you which bit is set in a value(variable). If you have the binary value %00000001 NCD will return 1(dec). %00000010 will give 2, %00000100 will return 3 and so on. If there is more than one bit set NCD will return the highest. %00100001 will give you 6. if no bits are set(the value is zero) NCD will reurn 0. I don't really like the fact that it returns 1 when the LSB(Least Significant Bit) is set, in my brain that bit is bit 0. I suppose it's done that way to be able to return 0 if no bits are set. Example.......
    in = 4 '4dec = 4hex = 00000100bin
    out = NCD in 'check which bit is set
    .....out will now contain 3 since it was the third bit that was set.

    DCD will do it in reverse. You tell DCD which bit to set and it will return a value with that bit set. This command wants the bitnumber the way i like it, LSB is 0, not like NCD which wants LSB = 1. DCD 0 will give %00000001, DCD 3 gives %00001000, DCD 7 gives %10000000. Example.......
    in = 4
    out = DCD in
    .....out will now contain %00010000 since it was bit number 4 that should be set.

    The ">>" command means "shift right", this means that you move the bitpattern(one or more) steps to the right by "pushing" zeroes in from the left. How many times to shift is specified by the value following the">>" command. %10000000 >> 1 will return %01000000, %10000000 >> 3 will return %00010000, %00001111 >> 3 will return %00000001. Looking at it from a "mathematical" side we see that shifting one step right is the same as dividing a number by 2. You will divide the number by 2 each time you move it one step to the right. >> 3 will be the same as /2/2/2 = /2^3 = /8 .

    I hope this makes things a bit less fuzzy.
    /Ingvar

  4. #4
    Finn's Avatar
    Finn Guest


    Did you find this post helpful? Yes | No

    Default Pic Basic Pro Syntax

    Thank you moby & Ingvar, your help has been well recieved and my understanding of how the code works has definetly been increased. Thanks Again!!!!

Similar Threads

  1. Looking at pic basic pro symbol values in mplab 8.15a simulator
    By ukemigrant in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 16th May 2009, 13:18
  2. I want to buy PIC BASIC PRO...
    By simransingh in forum General
    Replies: 2
    Last Post: - 30th October 2007, 17:13
  3. PIC BASIC or PIC BASIC PRO
    By kirkmans in forum USB
    Replies: 3
    Last Post: - 20th April 2007, 00:52
  4. Replies: 5
    Last Post: - 17th January 2006, 19:26
  5. How to use 93C46 Type EEPROM using PIC Basic PRo
    By in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 1st April 2003, 04:07

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts