$regfile = "m16def.dat"
$crystal = 12000000
$crystal = 12000000
$baud = 9600
' Declaratiets
Config Portc = Output
Config Portb = Output

Dta Alias Portb.0 ' data
Clk Alias Portb.1 ' clock
Rst Alias Portb.3 ' master reset
Ltc Alias Portb.2 ' latch

Dim Red As Byte , Green As Byte , Blue As Byte , Red_out As Byte 
dim Green_out As Byte , Blue_out As Byte
Dim Trm2 As Byte, x as byte
Config Timer0 = Timer , Prescale = 1

Portc.0 = 1
Waitms 500
Portc.0 = 0

On Ovf0 Tim2_isr
Enable Timer0
Enable Interrupts
Rst = 1


Do
For X = 0 To 255
Blue = X
Toggle Portc.0
Waitms 1
Next X
For X = 255 To 0 Step -1
Blue = X
Toggle Portc.0
Waitms 1
Next X
Loop
End

Tim2_isr:
Incr Trm2
If Blue > Trm2 Or Blue = Trm2 Then
   Blue_out = 255
   Else
   Blue_out = 0
End If
If Red > Trm2 Or Red = Trm2 Then
   Red_out = 255
   Else
   Red_out = 0
End If
If Green > Trm2 Or Green = Trm2 Then
   Green_out = 255
   Else
   Green_out = 0
End If

Shiftout Dta , Clk , Red_out , 1
Shiftout Dta , Clk , Green_out , 1
Shiftout Dta , Clk , Blue_out , 1
Ltc = 1
nop
Ltc = 0
nop
Return