User manual

DSM tutorials
while (1)
{
par
{
/*
* Increment up to 15, then wrap round to 0
*/
Count++;
/*
* Write Count and Count[2:1] to display
*/
PalSevenSegWriteDigit (PalSevenSegCT (0), Count, 0);
PalSevenSegWriteDigit (PalSevenSegCT (1), adju( (Count[2:1]), 4), 0);
}
}
The
[m:n] operator returns bits m to n from its operand.
The value of
Count is shown on the first 7-segment display, while the second display shows the value
of the middle two bits of
Count. The adju() macro is used to adjust the width of the modified value of
count to four bits, as this is the width required to be passed to
PalSevenSegWriteDigit(). The
example uses
Count[2:1] to select the middle two of four bits, so while the first display counts once
from 0 to 0xF, the second counts twice from 0 to 3 at half the rate, as shown in the table below.
Count 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Display 1
0 1 2 3 4 5 6 7 8 9 A B C D E F
Count[2:1] 00 00 01 01 10 10 11 11 00 00 01 01 10 10 11 11
Display 2
0 0 1 1 2 2 3 3 0 0 1 1 2 2 3 3
SELECT EXAMPLE DISPLAY VALUES
Concatenatation operator
The catexample project in the TutorialHCBasics workspace shows how to use the concatenate bits @
operator. The source code is shown below:
www.celoxica.com
Page 51