Jal 1 Your first JAL program: Isn't this exciting! You are well on your way to blinking a small light on and off continuously. OK so maybe that doesn't sound so cool, but in reality a lot of what you will do in robotics will consist of turning pins on and off. You can do a lot of cool stuff with a blinking light. So here it is. Just bring up jaledit and copy the program below into a new window, or download the code here. There is a worksheet to go along with this activity in the downloads section.
On the hardware side you will need the max232 cable and for starters you could use a simple breadboard circuit. If you look at the picture below you'll see a simple circuit to get you up and running. The top right corner is for the 5V regulator. I use a 7805 so the top pin is the 6-12V input then gnd is middle and +5V output is bottom. On the top left corner of the board is the connection for the max232 cable to plug into. Mine is wired top to bottom gnd (from middle of 7805), 5V (from Bottom of 7805), TX, RX. You can see a couple of capacitors between + and - on either side, this helps give reliable serial communication. The little button switch is wired from gnd to pin 4 (MCLR), and the resistor on the left is tying MCLR high until the button is pressed to reset the pic. There are two yellow wires supplying power to the pic and a resistor/LED on pin b4 for the all important blinkiness. And don't forget to tie your positive rails and negative rails together (the red wires at the bottom).
The Code:
-- comments are preceded by a double dash and a space.
-- They are not part of the program. You may omit them if you want.
-- This program was compiled with the jallib libraries and Jal V2 compiler
include 16f88 -- chip definitions
pragma target clock 8_000_000 -- oscillator frequency
pragma bootloader long_start -- tells the compiler to compile for a bootloader
include delay -- standard delay procedures
pin_b4_direction = output -- tells the compiler to set pin b4 as an output pin
forever loop -- your program fits inside the forever loop and loops forever.
pin_B4 = on -- turn the pin on (+5 Volts)
delay_100ms( 2 ) -- wait for 200 ms or about 1/5 of a second.
pin_B4 = off -- turn the pin off (0 volts)
delay_100ms( 2 ) -- wait again
end loop -- loops back to the beginning of the forever loop to start over
Compiling and loading: Now hit F9 to compile and see if you got it right. If there are errors, you get to figure out why. I am assuming you have already tried compiling one of the sample programs that comes with the pack you are using. If you were able to compile the sample program but not this one, the most likely reason is library / include file issues. My code assumes you are using the Jalpack from Sunish Isaac and tinybootloader. See below for differences between the Jalpack include files and Bert's starter pack. The stuff in the forever loop will remain the same but the header will change depending on which pack you are using.
Once you have a compiled .hex file, load it up in tinybld and program the chip. Still no blinky light? You did connect an LED to pin B4 didn't you? You should probably use a 200-500 ohm resistor between the LED and ground to limit current and avoid blowing out your LED, or damaging your pic. Still nothing? Reverse the LED. It is directional. It needs to be connected with the short wire (also the side with the shaved flat area on the plastic) towards the circuit's ground. Still nothing? Make sure you have +5V connected to pin 14 (Vdd) of the PIC and ground connected to pin 5 (Vss). Also make sure you have a resistor 1k ohm to 10k ohm or so connected between +5V and pin 4 (pin a5). This keeps the pic from reseting.
Extra Credit: Try blinking your initials in morse code. Try different blink speeds. What is your limit? Can you detect 30 Hz flashes, 40 Hz? What if you blink the LED at the frequency of your guitar string, point the LED at the guitar string and pluck? What if you connect a speaker instead of an LED?
If you are ready to move on go to Jal 2 using variables.
Headers: What are the differences between the Jalpack and Bert's starter pack? See below.