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

    Question 16F877 Programming (newbie)

    OK, let me admit something right up front. I'm an analog cat in a room full of digital rocking chairs. I've been doing stuff from audio through microwave all my engineering and teaching career, but this is my first foray into microcontroller programming ever. Please be gentle with my stupid questions.

    I also admit to having a moderate command of Dartmouth Basic, but have absolutely no experience with my brand new PicBasic Pro Compiler, programmer, Lab X1, assembler, or machine language. None whatsoever.

    However, I have a project that will lend itself nicely to a uC solution I believe. It is a simple audio switching panel that accepts audio from/to up to three transceivers, a couple more receivers, four analog microphone inputs and all that stuff ... more later, but if you want to see it, please click www.rstengineering.com/picpro

    The basic question is this...all those pushbutton switches you see control the leds you see (and by extension the audio channel they represent) in a simple sequence of blue, green, blue & green, all off. The logic to do this in PBasic is quite simple. However, I have just about 40 inputs/outputs and that is a bit much for a through-hole uC, especially as most of the time they will not be doing anything. The device generally goes at least ten minutes and sometimes up to an hour without any of the buttons being pushed.

    So, given that the inputs/outputs are MOSTLY binary (on or off) and fairly stable, I want to store the data in the onboard flash memory for a couple of reasons. One is that I want to refresh all of the outputs once per program cycle on the off chance that something burps and turns off an on or on an off. Two is that I want the device to come up in the same manner that it was turned off. (Turn on and turn off are from another power switch in the vehicle.)

    So it comes down as to how to "read" a digital 8 bit byte bit by bit or "write" a digital byte bit by bit. That is, if I have eight variables and each bit of the byte represents the condition of one of the 8 variables, how do I assign the value of the variables as a function of the associated bit being high or low? How do I rewrite the byte if one or more of the bits changes?

    Before I go making wrong assumptions, I have sort of deduced from the ops manual for PBP (not exactly a literary gem) that (a) you have to define each variable before you use it and (b) a BIT is binary, a BYTE is octal, and a WORD is two bytes in hexadecimal. Yes?

    There must be a common name for this sort of process, and if I knew what the name was I could have searched this message board for the name. Sorry to have rambled on so long.

    Later questions will address external storage/output of the data, voice recording, and all the rest of the stuff. However, I want to get a basic loop programmed before I do anything else.

    Thanks for reading all this drivel.

    Jim

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

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

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

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

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

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