Step 2The Program
I developed the program chip using MPLAB. It is Microchip Tech's free assembler/IDE. I also used my Chinese ICD2 clone (about $50 on ebay) to actually program the IC. I needed to use a lot of delay loops so I rooted around on the web and found a program called PICLoops here:
http://www.mnsi.net/~boucher/picloops.html
PICLoops automatically generates timing loop assembly code for you if you tell it what uC you are using and the clock speed. Later on I ran into a similar on-line program here:
http://www.piclist.com/techref/piclist/codegen/delay.htm
The second one will generate delays that are accurate to a single clock cycle where PICLoops isn't quite so accurate. Either is fine for this app because timing isn't critical and the uC is running on an RC oscillator anyway.
The program mainly bops back and forth between checking the mode button and checking to see if the beams are interrupted. The mode switch works by keeping a running count of the number of times the button has been pressed. Each time the button is pressed the delay between the pulses to the relay gets shortened enough to step the pulse frequency by 1 Hz. The biggest part of the code is the different delays used by the pulse modes.
When you change the pulse mode the LED flashes to indicate the new mode. You can tell what the new pulse frequency is by counting the LED flashes- 4 times means 4 Hz, etc. The LED flashes have been timed slow enough that you will be able to count them. If the unit is in 10 Hz pulse mode, pushing the button again takes you back to continuous mode.
There is a watch-dog timer that runs while the program runs. If the timer isn't reset before it overflows, the uC will reset itself. That is why holding the mode button for 2.3 seconds causes the uC to reset to continuous mode. When you push the button, the uC waits for you to release it before doing anything. One of the first things it does after you release it is reset the watch-dog timer. If you don't release the button, the watch-dog timer overflows and restarts the program in the continuous mode.
I have attached the assembly listing file for those who are curious and the .hex file for those who just want to burn the chip and be done with it. I welcome any criticism of my programming technique from any of you PIC assembly experts out there.
Note- the relay closes for 25 ms when it operates in pulse mode. Some cameras may require a longer pulse. That delay is set in line that says "call delay25" near the top of the rlypuls section of the code. If 25 ms is too short for your camera, change that line to say "call delay50", then change the line that says "call delay75" to say "call delay50". That will increase the pulse time to 50 ms and still keep all the pulse frequencies at even 1 Hz steps.
The program only occupies 173 bytes out of the available 512 bytes in the chip, so you can add all sorts of functionality to the thing if you desire, though the user-interface is going to be somewhat limiting.
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|










































