PIC Experimenter's Board Manual
Counting Program
To illustrate many of these concepts, I have written a simple basic program. The schematic for the program is shown in figure 3, a picture of the completed circuit is shown below. It is a binary counting program that will light eight LED's connected to Port B's eight output lines.


The counting program will light the LEDs in the sequence shown in the Binary Number Table. Each binary "1" in a number the table will be represented with a lit LED. Every 250 millisecond (1/4 second) the count increments. After reaching the binary number 255, (the maximum value of a byte.) the sequence repeats, starting from zero.
Counting in Binary by One
Enter the following program exactly as it is written into your word processor. Save is as an ASCII text file (or DOS Text) with the .bas extension.
'Program Binary Counting (PICBasic Program)
'Initialize variables
Symbol TRISB = 134
Symbol PortB = 6
'Initialize Port(s)
poke TRISB,0
loop:
for B0 = 0 to 255
poke PortB, B0
pause 250
next B0
goto loop
'end
'Assign TRISB for Port B to decimal value of 134
'Assign Variable PortB to decimal value 6
'set port B pins to output
'Place B0 value at port to light LED's
'pause count or its too fast to see
'Next B0 value
Program Binary Count (PICBasic Pro Program)
B0 var byte
TRISB = 0
loop:
for B0 = 0 to 255
PortB = B0
pause 250
next B0
goto loop
end