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
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
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.
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
"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
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
>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.
Bookmarks