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 Sorry, Didn't See The Attachments Option

    Rather than go to an offsite web page, I'll attach the file to this reply. Sorry for the hassle; I'll get the hang of this soon.

    Jim
    Attached Images Attached Images

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


    Did you find this post helpful? Yes | No

    Default

    Example. You have Eight Receiver Inputs, each can be on or off... so define a BYTE for the Receiver states... give it a meaningful name...

    Receive var Byte

    Now you've got eight bits in that byte called Receive... so define those...

    RxChannelA var Receive.0
    RxChannelB var Receive.1
    RxChannelC var Receive.2
    RxChannelD var Receive.3
    RxChannelE var Receive.4
    RxChannelF var Receive.5
    RxChannelG var Receive.6
    RxChannelH var Receive.7

    The nice thing is that so far, the above nine statements have cost you NOTHING, NIL, ZIPPO in program space... now use those like so...

    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.

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

    btw... You are aware that somebody's done what you're doing already?

    http://www.ncsradio.com/m_switch.html

    Now, once you've looked at the competition, you'll probably want the ability to assign each receiver channel input to more than one output, in that case BIT operations would be inappropriate and you'll probably want to assign a BYTE to each channel rather than a BIT.

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


    Did you find this post helpful? Yes | No

    Default NCS Radio

    Yes, I am aware of NCS. However ...

    1.) The device shown is not set up to the aircraft standard, nor can it be modified to do so.

    2.) The device shown has three times the volume that is allowable for a device of this type.

    3.) For the last 34 years we have been producing nothing but kits (a la Heathkit) for the owner-pilot to assemble themselves.

    4.) The price is approximately 3 dB more than our target price.

    But the tech info for manipulating bits of a byte are most appreciated.

    Jim

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

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

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

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

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