^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 color.
Task1()
{
LDA ^13,0 // Get the counter port
CMP #25 // Compare to 25
BCC Color1 // If less than branch
CMP #50 // Compare
BRZ Color2 // if less than branch
CMP #50 // Compare
BRZ Color3 // if less than branch
CMP #70 // Compare
BRZ Color4 // if less than branch
CMP #90 // Compare
BRZ Color5 // if less than branch
CMP #110 // Compare
BRZ Color6 // if less than branch
CMP #130 // Compare
BRZ Color7 // if less than branch
CMP #150 // Compare
BRZ Color8 // if less than branch
...
}