CTC programming
;Ok, so first you need to assign your CTC hardware addresses like:
CH0 equ 0h
CH1 equ 1h
CH2 equ 2h
CH3 equ 3h
;Now you need to initialize a timer channel e.g. Ch0:
;init CH0
;CH0 divides CPU CLK by (256*16)
ld A,00100111b ; interrupts off, timer mode on
; prescaler=256, external start mode off,
; start upon loading time constant,
;loading the time constant follows later
; channel reset, this is a control command
out (CH0),A ; load configuration into channel 0
ld A,00Fh ; time constant 15d defined
out (CH0),A ; and loaded into channel 0
; timer output pin T0 outputs pulses
; of frequency f= CPU_CLK/(256*16)
;the timer should be running continously now
;--------------------------------------------------------
;now every time you read from channel 0 you get a random value into A:
in A,(CH0)
;now compare A with any other register
ld B,077h ;B loaded with 77h
cp B ;compare A with B
;the zero flag is set when A=B
;do something depending on the zero flag like:
jp z,match
; or
jp nz,mismatch
;hope this helps solving your problem. cheers, Mario