IF THEN statements and the 7 Segment display:
Draw your seven segment display and identify which pin goes to which segment. If you have the datasheet this is easy. If not, experiment. There are two types of 7 segment displays. Some are common cathode (ground) and some are common anode (positive). Many 7 segment LED displays have the common pin in the middle so try tying that to ground and then use a resistor from +5V to test the other pins. If that doesn't work try tying the middle pin to +5V and test the other pins with a resistor from ground. Once you know which pins do what, draw it out and save it. You'll want it next time you mess around with the display. Decide on a logical connection scheme and diagram which pins on the pic will be connected to which pins on the display and which segment that will light up.
Binary numbers: In the code below, you'll see a byte written out the long way( 0b_0000_0000 ). This is an easy way to control individual pins on the port. The leading charachter is a zero not the letter O. The 0b in front of the number tells the compiler that it is a binary number. The binary number starts at the most significant bit, so the first zero is pin 7 and the last zero is pin 0. So when you figure out which pins you want to be on, just put a 1 in that spot.
IF THEN statements:
An IF THEN statement executes a different set of code for each test case. Notice the double equals sign in the IF THEN statement. This is how Jal distinguishes inputs. Since x is being queried like an input, you use a double equals sign instead of one equals sign. When setting a port equal to another number, just use one equals sign.
Example: To decode the first 2 numbers on a seven segment display
portb_direction = all_output
forever loop
IF x == 0 THEN -- remember to declare x as a byte variable before hand
portb = 0b_1111_0111 -- turn on pins b7, b6, b5, b4, b2, b1, and b0 to display a 0
ELSIF x ==1 THEN
portb = 0b_0000_0011 -- turn on pins b1, and b0 to display a 1
-- keep making ELSIF statements untill you have put in the patterns for all the numbers you are going to use.
ELSIF x == 9 THEN
portb = 0b_1110_1111
x = 0 -- you can use this to reset x without needing a FOR loop
ELSE -- just in case x is something other than 0-9
portb = 0b_0000_0000
END IF
x = x + 1 -- Once you decode x then count to the next number
end loop
Decode the numbers 0-9 and make your chip count up 0-9 and then start over.
Try adding in the hex letters to your IF THEN decoder and make it count in hex (0-f)
Extra Credit: Can your display flash a message? What letters can you form on a 7 segment display?
Next up Jal 5 Inputs and WHILE loops