User manual
Tutorial: Handel-C and PSL basics
number of pixels in the Y direction. This is necessary for the display output code shown to work correctly,
as attempting to store a negative result in an unsigned number results in a large (incorrect) positive
number. The code below shows how the user interaction is performed. Two calls are made in parallel to
PalSwitchRead() to get data from the two switches, and at the same time the data from the switches
is checked and the box size updated. As Handel-C only updates variables at the end of a clock cycle,
data read from the switches will not be checked until the following cycle, but this will not have any impact
on the operation of this example.
while (1)
{
par
{
PalSwitchRead (PalSwitchCT (0), &SwitchData[0]);
PalSwitchRead (PalSwitchCT (1), &SwitchData[1]);
if (SwitchData[0] == 1)
{
if (BoxSize != (MaxY / 2))
{
BoxSize++;
Sleep (20);
}
else
delay;
}
else if (SwitchData[1] == 1)
{
if (BoxSize != 0)
{
BoxSize--;
Sleep (20);
}
else
delay;
}
else
delay;
}
}
The calls to the
Sleep() macro are required to avoid the box size changing too quickly, so that you can
observe it happening. In this case a sleep period of 20ms is used, limiting the rate of change to 50 pixels
per second. The code for the
Sleep() macro is shown below, including a notional clock rate of
10000Hz for simulation.
www.celoxica.com
Page 66