記事一覧

シフトレジスタ(74HC164)その2

2009.07.15


シフトレジスタで遊んでみました。

program SHIFREG

dim i, j, k as byte
const pp=50

main:

TRISIO = %00000000
'OPTION_REG.NOT_GPPU = 0
WPU = %00000100
GPIO = %00000000

do
'CLEAR
GPIO.4 = 0
for i = 0 to 8
GPIO.2 = 1
GPIO.2 = 0
delay_ms(pp)
next i
delay_ms(pp*2)

'LEFT > RIGHT
GPIO.4 = 1
for i = 0 to 8
GPIO.2 = 1
GPIO.4 = 0
GPIO.2 = 0
delay_ms(pp)
next i
delay_ms(pp*2)

'RIGHT > LEFT
for j = 0 to 8
GPIO.4 = 1
for i = j to 8
GPIO.2 = 1
GPIO.4 = 0
GPIO.2 = 0
next i
delay_ms(pp)
for i= 8-j to 8
GPIO.2 = 1
GPIO.2 = 0
next i
next j
delay_ms(pp*2)
delay_ms(pp*2)

'LEFT > RIGHT FILL
GPIO.4 = 1
for i = 0 to 7
GPIO.2 = 1
GPIO.2 = 0
delay_ms(pp)
next i
delay_ms(pp*2)
'ERASE
GPIO.4 = 0
for i = 0 to 7
GPIO.2 = 1
GPIO.2 = 0
delay_ms(pp)
next i
delay_ms(pp*2)

'LEFT > RIGHT FILL
for k = 0 to 8
for j = 0 to k
GPIO.4 = 1
GPIO.2 = 1
GPIO.2 = 0
next j
GPIO.4 = 0
for i = j to 7
GPIO.2 = 1
GPIO.2 = 0
next i
delay_ms(pp)
next k
delay_ms(pp*2)

'LEFT > RIGHT ERASE
for k = 0 to 7
for j = 0 to 7 - k
GPIO.4 = 1
GPIO.2 = 1
GPIO.2 = 0
next j
delay_ms(pp)
GPIO.4 = 0
for i = 0 to 7
GPIO.2 = 1
GPIO.2 = 0
next i
next k
delay_ms(pp*2)

'FLASH
for k = 0 to 7
for j = 0 to 7
GPIO.4 = 1
GPIO.2 = 1
GPIO.2 = 0
next j
delay_ms(pp*2)
for i = 0 to 7
GPIO.4 = 0
GPIO.2 = 1
GPIO.2 = 0
next i
delay_ms(pp*2)
next k
delay_ms(pp*2)
loop until 0 = 1
end.


Mikrobasicにてプログラミング。この手の実験的な軽い開発には便利なツールですね。
難しかったのは、右から左への点灯です。
シフトレジスタは左から右への一方向へのシフトしかできないので、反対方向に流すにはコツがいります。

タグ:74HC164 12F629 LED ロジックIC