Hi,

My first time here, new PIC user, and with a few questions. I've begun using PGP PRo with a Lab-X3 board that includes the 16F628A. This board has several buttons (SW1 uses RB7 and SW2 uses !MCLR through a 100 ohm resistor), 2 onboard LEDs (LED1 uses RB4 and LED2 uses RB5), and 1 pot (on RB0).

Here's what I'm trying to do: I've attached 2 external LEDs (call them LEDX1 and LEDX2) using the bases of 2 NPN transistors attached to RB1 and RB2, respectively. A simple program to flash LEDX1 and LEDX2 works fine, and I've been able to calibrate and use the pot in a simple pgm. I've also used example pgms to use SW1 and SW2 to control the onboard LEDs.

I've been trying to write and run a pgm that monitors the pot and SW1. The main loop alternately flashes LEDX1 and LEDX2, while monitoring SW1 to see if it has been pressed. If it has, the program should then look at the pot, and use the value of the pot to change the fraction of time that LEDX1 and LEDX2 will be on. Then the program goes back to the main loop and flashes LEDX1 and LEDX2 using this updated value. I'd like to do it this way, rather than just including the pot reading in the loop, because the pot reading seems to slow the flash rate.

This hasn't yet worked. I seem to be having problems understanding the interactions of OPTION_REG.7 (RBPU bit) and the reading of SW1. From looking at some example source, I have seen that I need to use OPTION_REG.7=1 to query the pot, and OPTION_REG.7=0 to query SW1. I've tried a bunch of different ways to do this, but the result has generally been that I end up going through the pot reading routine each time I go through the main loop. Also, I've tried modifying the status of TRISB at various points in the pgm in the hope that this would override the effect of the pullup resistors on PORTB. No success here.

So, it seems, I'm foggy on the basic picture here. Can anyone give me a clue? I'd be happy to furnish source code or schematics, but am unsure of forum etiquette on this.

One other thing: Bruce Reynolds at Reynolds Electronics explained how to set up the compiler to enable/disable the reset capability of !MCLR, using an "@ DEVICE MCLR_OFF" statement in my pgm, for which I am grateful. I hadn't seen any mention of this kind of thing in the PBP Pro manual, nor in Chuck Heelybuyck's "Programming PIC Microcontrollers with PicBasic", and wonder if there is any good literature alerting to me to these kinds of considerations. WHile I have the 16F628A data sheet, I'm not sure I would (or could) discern all of the options it may discuss by reading it more carefully than I have. Any pointers for the naive new user?

Thanks.

Bill Christens-Barry