$regfile = "m8def.dat" 
$crystal = 8000000 
$baud = 19200 

Data_out Alias Portb.0                                      ' DAT - of the first 74HC595 
Clock_out Alias Portb.1                                     ' SRCLK - 74HC595 
Latch_out Alias Portb.3                                     ' RCLK 

Data_out_dir Alias Ddrb.0 
Clock_out_dir Alias Ddrb.1                                  ' *** define direction regs *** 
Latch_out_dir Alias Ddrb.3 

Const Shift_delay = 20                                      ' shift delay in microseconds 

Declare Sub Send_bytes()                                    ' send byte array to shift registers 

Dim Tempbyte1 As Byte 
Dim Bytes(3) As Byte                                        ' byte shift reg output buffer 
Dim I As Byte 
Reset Clock_out 
Reset Data_out 
Reset Latch_out 

' set the data direction for I/O 
Set Clock_out_dir 
Set Data_out_dir 
Set Latch_out_dir 

Bytes(1) = &HAA 
Bytes(2) = &H55 
Bytes(3) = &HFF 
Do 
Send_bytes 
 Bytes(3) = Bytes(3) + 1 
 Bytes(2) = Bytes(2) + 1 
 Bytes(1) = Bytes(1) + 1 
Wait 2 
Loop 

Sub Send_bytes() 
   For I = 3 To 1 Step -1                                   ' send byte array to shift regs 
     Tempbyte1 = Bytes(i) 
     Shiftout Data_out , Clock_out , Tempbyte1 , 0 , 8 , Shift_delay 
   Next I 
   Set Latch_out                                            ' latch the shift reg to outputs 
   Waitms 1 
   Reset Latch_out 
End Sub