^13 - The Counter Port
The counter port ^13,0 is a read only value of the low byte of the internal counter for the device. As this value is constantly changing it is useful as a random number generator for light chases etc.
It updates around once every 300ms.
| As this is counting up at a predictable rate it isn’t truly random and may create a repetitive pattern. |
Examples
Example task where counter port recalls a random colour.
Task1()
{
LDA ^13,0 // Get the counter port
CMP #25 // Compare to 25
BCC Colour1 // If less than branch
CMP #50 // Compare
BRZ Colour2 // if less than branch
CMP #50 // Compare
BRZ Colour3 // if less than branch
CMP #70 // Compare
BRZ Colour4 // if less than branch
CMP #90 // Compare
BRZ Colour5 // if less than branch
CMP #110 // Compare
BRZ Colour6 // if less than branch
CMP #130 // Compare
BRZ Colour7 // if less than branch
CMP #150 // Compare
BRZ Colour8 // if less than branch
...
}