MrDEB
Well-Known Member
still won't compile It hangs on
Sub Fade(bright As Word, dimmer As Word, stop As Word, A As Byte, B As Byte, C As Byte, D As Byte)
Dim dir As Boolean
Sub Fade(bright As Word, dimmer As Word, stop As Word, A As Byte, B As Byte, C As Byte, D As Byte)
Dim dir As Boolean
Code:
{
*****************************************************************************
* Name : UNTITLED.BAS *
* Author : [select VIEW...EDITOR OPTIONS] *
* Notice : Copyright (c) 2022 [select VIEW...EDITOR OPTIONS] *
* : All Rights Reserved *
* Date : 6/1/2022 *
* Version : 1.0 *
* Notes : *
* : *
*****************************************************************************
}
Device = 18F43K22
Clock = 8
// int osc and IO pin libraries
Include "intosc.bas"
#option DIGITALIO_INIT = true // automatically call setalldigital
Include "setdigitalio.bas"
// hardware
Dim INDEX As LongWord //4294967295
Dim Counter As Word
Dim Counter_up As Word
Dim Counter_down As Word
Dim m As Byte
Dim w As Byte
Dim x As Byte
Dim y As Byte
Dim z As Byte
Dim Bright_1 As LongWord // a wider range of settings FOR A SMOOTHER TRANSITION
Dim Dimmer_1 As LongWord
Dim Bright_2 As LongWord // a wider range of settings
Dim Dimmer_2 As LongWord
main:
// init hdw
// bright is initial ON time
// dimmer is initial OFF time
// stop is end value (loop until bright = stop)
// A, B, C, and D are port values
Sub Fade(bright As Word, dimmer As Word, stop As Word, A As Byte, B As Byte, C As Byte, D As Byte)
Dim dir As Boolean
// figure out direction and account for 'repeat-until' end
If (bright < dimmer) Then
dir = true // increase ON time
stop = stop + 1
Else
dir = false // increase OFF time
stop = stop - 1
EndIf
Repeat
PORTA = A // ON time
PORTB = B
PORTC = C
PORTD = D
DelayUS(bright)
PORTA = 0 // OFF time
PORTB = 0
PORTC = 0
PORTD = 0
DelayUS(dimmer)
If (dir) Then
bright = bright + 1 // increase ON time
dimmer = dimmer - 1 // decrease OFF time
Else
bright = bright - 1 // decrease ON time
dimmer = dimmer + 1 // increase OFF time
EndIf
Until (bright = stop)
End Sub
// LED port - all outputs 2 LEDs per port in parallel 330 ohm resistor
TRISA = 0
TRISB = 0
TRISC = 0
TRISD = 0
TRISE = 0
PORTE=%000
PORTD=%00000000
PORTC=%00000000
PORTA=%00000000
PORTB=%00000000
// bright is initial ON time
// dimmer is initial OFF time
// stop is end value (loop until bright = stop)
// A, B, C, and D are port values
main:
While (true)
// fade brightness up
Fade(1, 5000, 3000, %11001111, %00000111, %00010001, %10001110)
// fade brightness down
Fade(5000, 1, 1, %11001111, %00000111, %00010001, %10001110)
End While