Hi,
OK. I've attached a program (in a ZIP file) that illustrates the LED flashing method that I described earlier.
It doesn't generate any PBP code, but it will give you a better idea of what is going on so that you can do it for yourself.
The 16 checkboxes at the bottom of the program represent the 16 bits (0 to 15) of the flash pattern word.
Checking or unchecking these boxes will change the "Flash Pattern Word Value" at the top.
NOTE:
I'm only displaying the "Flash Pattern Word Value" in binary format.
The little blue circle below the check boxes and the number in the "Current Pattern Bit Selected" text box indicate at what point in the flash pattern the LED (the big red box) is getting it's status from. Checked = ON, Unchecked = OFF.
Now, neither of the top 2 text boxes accept data input. They are simply indicators. However, the bottom 2 text boxes do accept input. These are the "Loop Delay (PAUSE)" text box and the "LED Update Count" text box. Any changes in these boxes will turn the box yellow. You will need to click the "Update Values" button to enter the changes you make here.
The "Loop Delay (PAUSE)" text box indicates the delay in milliseconds between each launch (i.e. a GOSUB) of the LED's status update routine. In PBP code, look at it as the delay between loops through "Main".
The "LED Update Count" is sort of a countdown between updates of the LED's status. It gets decremented each time the LED's status update routine is launched, and when it hit's zero the LED's flash pattern bit gets advanced by one.
The reason that I use a delay and a count is because a program is often doing several things. You may only want a 10ms delay between loops to handle debounce on switches. 10 milliseconds is way too short for 16 part LED flash though. You need a longer interval like 100ms. So, you end up using a count of ten with a loop delay of 10 milliseconds. Every ten milliseconds the switches are checked and the LED status update routine is launched. Within that routine the count gets decremented. If it's reached zero, the LED pattern bit is advanced and the count is reset to 10.
NOTE:
Due to some "VB issues", you can't make the loop delay value less than 100 milliseconds in the simulation. You can make it as small as you want on an actual PIC though.
Anyway, it will make much more sense to you when you run the program. Try it out by checking and unchecking the boxes. For example, checking the first 8 boxes and unchecking the last 8 boxes will produced a slow flashing pattern.
Enjoy!




Bookmarks