16F877 Programming (newbie)


Closed Thread
Results 1 to 10 of 10

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Location
    Grass Valley CA
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Xor??

    "If PushButtonA=0 then RxChannelA=RxChannelA^1

    For example, the above will toggle the state of the RxChannelA BIT each time the PushButtonA is pressed."


    I'm not at all sure I understand the logic behind this program line. You appear to be XORing something with ... oh, I see now. I'm not used to negative logic yet. You have one side of the pushbutton GROUNDED and a pullup to keep it high until pushed, yes? And then the old combinational (discrete) logic trick of holding one of the pins high to do an invert of the data. Nice.

    I'm presuming that this is a way of implementing the NOT function of GeeWhiz Basic in PBP? (i.e. If x=0 then x=^1 is equivalent to x=not(x)) But wait a minnit -- page 37 says that there IS a NOT operator. Would this work also?



    "Use READ and WRITE and DATA (see manual) to save your BYTE into your pics EEPROM accordingly."

    Yes, this wasn't too difficult to understand. I'm not altogether sure that I understand the DATA "location" parameter unless "location" simply means the next chunk of space for storage. "Location" doesn't necessarily mean a defined number of bits but merely "store it in the first place you can"? I'm not at all sure how to read that, but the processor is probably smarter than I am.

    Jim

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    The XOR simply toggles the BIT in that example. If it was a 0 it becomes a 1, and vice-versa. What you do with that BIT thereafter depends on you and your schematic.

    As for the DATA statement, it presets the state of the on-board EEPROM at program time. The EEPROM is not usually all zero's when you get it from Microchip... actually, I wouldn't trust what state it's in. After erasing, it'll probably full of $FF which may not be what you want... after all, on power-up, your device will look in EEPROM to determine the state of your various I/O's, so when you design your device, when it's powered ON for the very first time, you will want it to come-up with the various I/O's and options in a default state, so in that instance you will use the DATA statements to preset the PICs EEPROM accordingly. Thereafter, their state can be altered by the equipments operation, but initially you will want your device to initialise a certain way. The DATA statements will ensure the EEROM is pre-set to those values at program-time and not to some random value.

    You buy a brand-new TV set and plug it in the wall, you don't expect it to switch-on for the very first time with the factory default volume set to maximum.

    LOCATION is the address in EEPROM space.

    For example, the volume setting can be located at address 5 in EEPROM. It can be a value from 0 (minimum) to 255 (maximum) the default (brand-new, untampered out-of-the-box) setting is 75. You would ensure in your program that...

    DATA @5,75

  3. #3
    Join Date
    Jul 2007
    Location
    Grass Valley CA
    Posts
    16


    Did you find this post helpful? Yes | No

    Default Good Information

    Quote Originally Posted by Melanie View Post
    The XOR simply toggles the BIT in that example. If it was a 0 it becomes a 1, and vice-versa. What you do with that BIT thereafter depends on you and your schematic.

    That's what I meant by the trick using discrete XOR logic in the analog world. It is the way we get a 180° phase shift without a lot of folderol.



    As for the DATA statement, it presets the state of the on-board EEPROM at program time. The EEPROM is not usually all zero's when you get it from Microchip... actually, I wouldn't trust what state it's in. After erasing, it'll probably full of $FF which may not be what you want... after all, on power-up, your device will look in EEPROM to determine the state of your various I/O's, so when you design your device, when it's powered ON for the very first time, you will want it to come-up with the various I/O's and options in a default state, so in that instance you will use the DATA statements to preset the PICs EEPROM accordingly. Thereafter, their state can be altered by the equipments operation, but initially you will want your device to initialise a certain way. The DATA statements will ensure the EEROM is pre-set to those values at program-time and not to some random value.

    Ah, that's something I missed. I missed the "first programmed" part of the DATA command reference description. Normal execution of the program thereafter disregards the DATA line??



    You buy a brand-new TV set and plug it in the wall, you don't expect it to switch-on for the very first time with the factory default volume set to maximum.

    It might get your attention {;-)

    LOCATION is the address in EEPROM space.

    So is each LOCATION one 8-bit byte long? If so, how can you store 16 bit words??



    For example, the volume setting can be located at address 5 in EEPROM. It can be a value from 0 (minimum) to 255 (maximum) the default (brand-new, untampered out-of-the-box) setting is 75. You would ensure in your program that...

    DATA @5,75

    Got it. Thanks.
    Jim ..........

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    >Normal execution of the program thereafter disregards the DATA line??

    Yes. The DATA statement simply presets the content of EEPROM at PROGRAM TIME - ie when you burn the PIC in your programmer. The DATA statement is not actually an 'executable' piece of code. It carries no program overhead. It is simply a directive to place values into EEPROM when the PIC is programmed. Thereafter, the content of EEPROM can be read (with the READ command) and altered (with the WRITE command) as often as you want during program execution. So to recap, DATA presets the EEPROM to an initial value at PROGRAM TIME - and at no other time thereafter (unless you reprogram the PIC in your programmer when the value will revert back to that specified by the DATA statement - unless of course you have a clever programmer in which you can specify if the EEPROM contents are to be programmed or not).

    >>So is each LOCATION one 8-bit byte long?

    Yes.

    >>If so, how can you store 16 bit words??

    You split the word into highbyte and lowbyte and use two EEPROM locations.

  5. #5
    Join Date
    Jul 2007
    Location
    Grass Valley CA
    Posts
    16


    Did you find this post helpful? Yes | No

    Default

    Many thanks fer yer help. The derivative of the learning curve is a large positive number today.

    Two last questions and I'm pretty sure that I know the answers ... which is generally how I get bit on the hiney from time to time ...

    1.) If I am in a particular section of the main program and I call out a subroutine called, for example getthis: and in getthis: it calculates a variable called rxp2 and gives it a value of 7 (i.e. somehow rxp2=7 is generated), when I RETURN to the main program and use rxp2, does it still have the value 7 if it otherwise hasn't been modified? I think the term for this is global variable, where it matters not where in the program something is calculated, it carries that value everywhere in the program until modified somewhere else.

    2.) Does it take up any more program space to call a variable s2 or supercalafragialisticexpialidotious2 ??? And are we limited in length on variable names?

    (Or is there a place online where I can go to look up information like this rather than bugging you all afternoon?)

    Jim

  6. #6
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Actually, where I am now is pretty much midnight...

    1. All variables in PICBasic are global.

    2. Labels or variable names do not take up program space... make them meaningful, but if you go crazy with them, it makes your program look stupid (but then again, who cares, you're the one that's probably only going to read it and it's unlikely you're going to publish it for a wider audience to riddicule)...
    Code:
    If (PrimaryStallAlarmWarningFlag=1 and PrimaryWheelsUpFlag=1 and WheelsNotDownAndLockedFlag=0) then goto YoureGoingToBendYourPropellerVoiceMessageWarning
    Try to make things fit on one line - it makes printouts and debugging so much easier.

    With PBP - it's all in the manual and in the Datasheet for the PIC you're using.

Similar Threads

  1. Blink.Bas on 18f45k20 Newbie seeks working example.
    By DiscoEd in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 29th December 2009, 03:36
  2. Data Programming Error at 0000
    By cpatnoi in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 22nd May 2009, 03:37
  3. Problems programming
    By Lionheart in forum General
    Replies: 4
    Last Post: - 7th December 2008, 16:51
  4. Replies: 6
    Last Post: - 1st February 2008, 03:35
  5. PIC 16F877 programming help
    By the_piculiar in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th July 2005, 22:39

Members who have read this thread : 0

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