So far the programs haven't dealt with any
variable data. It's been very simple stuff but we need to
introduce some variable data to make programs useful.
Expanding on the simple 4 LED program, let's introduce a
variable x and change it in the while
loop and write it to the LEDs.
In line 9 we introduce a variable called x that is assigned
the type of unsigned char.
This makes it an 8 bit variable ranging from 0 to 255.
A good habit to get into is to make sure you initialize
variables at the start of the program. Variable x is
initialized to 0 just before the while loop in the program
shown on the right.
In the while loop we write the value stored in x to PORTB,
delay 50 millisecond, and then change the value in x by adding
0x10 to it. The 0x10 is hexidecimal notation and allows the
program to increment through the upper 4 bits of PORTB without
any pauses.