PDA

View Full Version : PIC programming 101



N8YX
05-02-2020, 09:47 AM
Anyone with development experience, please step inside... :icon_smile:

I have a memory unit for an NRD-515. JRC made two different versions - one a 24ch and another a 96 - with the only difference between them being the bank selector (or the lack thereof). An NDH-515 has 1 bank of 24ch whereas the NDH-518 has 4 banks of 24ch. A push button selects the active bank.

PE1ABR has details of a modification to the NDH-515 which will allow 8 banks of 24ch to be selected. A rotary switch and diode matrix/pull-up resistor array is used to provide a 3-line BCD-coded output which provides for bank-select logic. This requires drilling the unit's front panel then labeling the bank numbers. If I'm going to do this I'd rather fabricate and paint a new front panel. And...since the existing channel readout is digital, I thought "Why not use a PIC, Arduino or BASIC Stamp to expand on the concept and have a digital bank indicator as well?" Doing a little digging, I found a motorcycle gear-counter circuit that uses a 16F628. The assembly code was provided. It has up-down inputs on Port A and uses Port B to drive a single 7 segment display.

Perfect. Though my assembly skills are rusty as hell. Modifying this is going to be an exercise.

What's a good, robust IDE for this family of PICs? I looked at MPLABX, and I don't need to buy their Pro compiler as I don't have a need for speed - so the freeware version should work fine. This thing is very simple in concept: Upon power-up and no previously active bank having been selected, default to Bank 0. Pull the three Port A output lines Low, then send a "0" character (defined in an array) out the Port B lines. Loop and look for a switch press (switches connected to two of the other Port A lines for up/down incrementing). Process the switch press accordingly, output the BCD control data on the Port A lines and digit display character data on Port B's lines...then wait for a period and see if no other switch press has occurred. If not in say, 2 minutes then write the Bank Number to a data location in the device's EEPROM. On subsequent loops, compare the existing bank number with the stored bank number; update if changed and keep looping if not.

Upon subsequent power-ups, look for an existing Bank Number in EEPROM. If present, output the associated control/display data then loop and look for changes as above.

I'd really like to simulate this before actually programming a physical device...and I'd like to write the code in C if possible. Suggestions, thoughts, ready-made code examples?

WØTKX
05-02-2020, 01:07 PM
https://github.com/lcgamboa/picsimlab

https://sourceforge.net/projects/picsim/reviews (https://sourceforge.net/projects/picsim/reviews)

https://raw.githubusercontent.com/lcgamboa/picsimlab/master/docs/screenshot.png

N1LAF
05-09-2020, 06:39 AM
Digikey has a wide range of socket-able development kits, some with built-in programmers. (https://www.digikey.com/products/en/development-boards-kits-programmers/evaluation-boards-embedded-mcu-dsp/786?FV=-5%7C11960%2C69%7C404675%2C-8%7C786&quantity=0&ColumnSort=1000011&page=1&pageSize=500)


Microchip Curiosity 8/14/20 pin Eval boards, with built-in programmer $26 (https://www.digikey.com/product-detail/en/microchip-technology/DM164137/DM164137-ND/5252514)


Microchip Curiosity 28/40 pin Eval boards, with built-in programmer $40 (https://www.digikey.com/product-detail/en/microchip-technology/DM164136/DM164136-ND/6192824)

For button press, I use counters. when you have your code in place, you can toggle an output line and measure its frequency when running, tells you the period of your program loop. Knowing that, you can determine the counter value that will give you a positive button press, and compensate for minor switch bounce. You will be able to quickly change banks.

N1LAF
08-31-2020, 08:18 PM
Port B display C code...

switch(banksel) {
case 0: portb = 0x7e; break;
case 1: portb = 0x30; break;
case 2: portb = 0x6d; break;
case 3: portb = 0x79; break;
case 4: portb = 0x33; break;
case 5: portb = 0x5b; break;
case 6: portb = 0x5f; break;
case 7: portb = 0x70; break;
case 8: portb = 0x7f; break;
case 9: portb = 0x7b; break;
default: break;
}

depending of pull up or pull down logic is used, may need to invert the numbers.

N1LAF
08-31-2020, 08:37 PM
https://people.zeelandnet.nl/wgeeraert/index515.htm#ndh515 (https://people.zeelandnet.nl/wgeeraert/index515.htm#ndh515)

Trying to understand what needs to be done. PIC can do this, more flexibility than using GALs.

How about using a rotory encoder rather than up/down switches?