Groetjes
Robin
Code: Selecteer alles
DEVICE 16F628A ;We gebruiken een 16F628A type
CONFIG INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, LVP_OFF, MCLRE_OFF ;Fuses instellen
ALL_DIGITAL TRUE ;Alle info is digitaal
Dim Duty as byte
Dim Keuzeschakelaar as byte
SYMBOL LED0 = PORTA.0 ;Poort A.0 heeft nu de naam LED1
SYMBOL LED1 = PORTA.1 ;Poort A.1 heeft nu de naam LED2
SYMBOL LED2 = PORTA.2
SYMBOL LED3 = PORTA.3 ;Poort A.2 heeft nu de naam LED3
SYMBOL S0 = PORTB.0 ;Poort B.0 heeft nu de naam S1
SYMBOL S1 = PORTB.1 ;Poort B.1 heeft nu de naam S2
SYMBOL S2 = PORTB.2 ;Poort B.2 heeft nu de naam S3
;76543210
PORTA = %00000000 ;Alle niveaus van PORTA laag
PORTB = %00000000 ;Alle niveaus van PORTB laag
TRISA = %00000000 ;Alles als uitgang
TRISB = %00000111 ;porten 0-2 als ingang, al de rest uitgang
PORTB_PULLUPS ON
LED3 = 1
Duty = 255
Keuzeschakelaar = 1
Loop:
While 1 = 1
Select case Keuzeschakelaar
Case 1
PWM LED0, Duty, 10
Call readaction
Case 2
PWM LED1, Duty, 10
Call readaction
Case 3
PWM LED0, Duty, 10
PWM LED1, Duty, 10
Call readaction
End Select
Wend ;Einde hoofdloop
readaction:
Select Case 0
Case S0
If Duty = 30 then
Duty = 30
else
Duty = Duty - 25
End if
while S0 = 0 : wend
Case S1
If Duty = 255 then
Duty = 255
else
Duty = Duty + 25
End if
while S1 = 0 : wend
Case S2
If Keuzeschakelaar = 3 then
Keuzeschakelaar = 1
Else
Keuzeschakelaar = Keuzeschakelaar + 1
End if
while S2 = 0 : wend
End select
return
END ;Einde programma