Stap 9: Programma de chip
CPU = 16F877
MHZ = 20
CONFIG 16254 =
SI con A0
SCK con A1
RCK con A2
ABIT var byte(9)
nDur var word(8)
nP var word(8)
teller var byte
WaardeInstellen (SetValue) var byte
noteDuration var woord
notePause var woord
' register adres bits verschuiven
ABIT(0) = % 10000000
ABIT(1) = % 01000000
ABIT(2) = % 00100000
ABIT(3) = % 00010000
ABIT(4) = % 00001000
ABIT(5) = % 00000100
ABIT(6) = % 00000010
ABIT(7) = % 00000001
ABIT(8) = % 00000000
' duur matrix pinnen
nDur(0) = D0
nDur(1) = D1
nDur(2) = D2
nDur(3) = D3
nDur(4) = D4
nDur(5) = D5
nDur(6) = D6
nDur(7) = D7
' onderbreken matrix pinnen
nP(0) = B0
nP(1) = B1
nP(2) = B2
nP(3) = B3
nP(4) = B4
nP(5) = B5
nP(6) = B6
nP(7) = B7
Counter = 0
WaardeInstellen (SetValue) = % 00000000
belangrijkste:
for counter = 0 tot en met 7
HOGE nDur(counter)
onderbreken van 1
RCTIME nDur (counter), 1, noteDuration
WaardeInstellen (SetValue) = abit(counter)
GOSUB out595
onderbreken van noteDuration
HOGE nP(counter)
onderbreken van 1
RCTIME nP (counter), 1, notePause
WaardeInstellen (SetValue) = abit(8)
GOSUB out595
onderbreken van de notePause * 3
volgende
Counter = 0
goto belangrijkste
out595:
SHIFTOUT SI, SCK, LSBPRE, [setValue\8]
pulsout RCK, 8
Terugkeer