Artikel: [Code] Fadende Knightrider

'****************************************************************
'* knightrider met faden *
'* *
'* Auteur : Stijn Coenen [Stynus] *
'* Notice : Copyright (c) 2008 Stijn Coenen *
'* : All Rights Reserved *
'* Datum : 29/05/2008 *
'* Version : 1.0 *
'* Website : www.elektronicastynus.be *
'****************************************************************
'Config
Device 16F628A
Config INTRC_OSC_NOCLKOUT, WDT_OFF, PWRTE_ON, LVP_OFF, MCLRE_ON
ALL_DIGITAL TRUE ;Alle ingangen digitaal
'****************************************************************
'Ingangen declareren
Symbol switch = PORTA
Symbol sw1 = PORTA.7
Symbol sw2 = PORTA.6
Symbol sw3 = PORTA.5
Symbol sw4 = PORTA.4
Symbol sw5 = PORTA.3
Symbol sw6 = PORTA.2
Symbol sw7 = PORTA.1
Symbol sw8 = PORTA.0
'TrisA register instellen (alles ingang)
TRISA = 255
'****************************************************************
'Uitgangen declareren
Symbol ledjes = PORTB
Symbol led1 = PORTB.7
Symbol led2 = PORTB.6
Symbol led3 = PORTB.5
Symbol led4 = PORTB.4
Symbol led5 = PORTB.3
Symbol led6 = PORTB.2
Symbol led7 = PORTB.1
Symbol led8 = PORTB.0
'TrisB register instellen (alles uitgang)
TRISB = 0

'****************************************************************
'Decraraties voor programma:
Dim index As Byte
Dim I As Byte
Dim Ledwaardes[9] As Byte
Symbol snelheid = 32 'Hoe groter hoe trager
'****************************************************************
Clear
Start:
For I = 1 To 8
Ledwaardes[I] = 0
Next
'X0000000
For I = 0 To snelheid
Inc Ledwaardes[1]
Inc Ledwaardes[1]
Inc Ledwaardes[2]
Next
While 1 = 1
'IX000000
For I = 0 To snelheid
Dec Ledwaardes[1]
Inc Ledwaardes[2]
GoSub PWM_lus
Next
'1IX00000
For I = 0 To snelheid
Dec Ledwaardes[1]
Dec Ledwaardes[2]
Inc Ledwaardes[3]
Inc Ledwaardes[3]
GoSub PWM_lus
Next
'01IX0000
For I = 0 To snelheid
Dec Ledwaardes[2]
Dec Ledwaardes[3]
Inc Ledwaardes[4]
Inc Ledwaardes[4]
GoSub PWM_lus
Next
'001IX000
For I = 0 To snelheid
Dec Ledwaardes[3]
Dec Ledwaardes[4]
Inc Ledwaardes[5]
Inc Ledwaardes[5]
GoSub PWM_lus
Next
'0001IX00
For I = 0 To snelheid
Dec Ledwaardes[4]
Dec Ledwaardes[5]
Inc Ledwaardes[6]
Inc Ledwaardes[6]
GoSub PWM_lus
Next
'00001IX0
For I = 0 To snelheid
Dec Ledwaardes[5]
Dec Ledwaardes[6]
Inc Ledwaardes[7]
Inc Ledwaardes[7]
GoSub PWM_lus
Next
'000001IX
For I = 0 To snelheid
Dec Ledwaardes[6]
Dec Ledwaardes[7]
Inc Ledwaardes[8]
Inc Ledwaardes[8]
GoSub PWM_lus
Next
'********************
'000000XI
For I = 0 To snelheid
Inc Ledwaardes[7]
Dec Ledwaardes[8]
GoSub PWM_lus
Next
'00000XI1
For I = 0 To snelheid
Inc Ledwaardes[6]
Inc Ledwaardes[6]
Dec Ledwaardes[7]
Dec Ledwaardes[8]
GoSub PWM_lus
Next
'0000XI10
For I = 0 To snelheid
Inc Ledwaardes[5]
Inc Ledwaardes[5]
Dec Ledwaardes[6]
Dec Ledwaardes[7]
GoSub PWM_lus
Next
'000XI100
For I = 0 To snelheid
Inc Ledwaardes[4]
Inc Ledwaardes[4]
Dec Ledwaardes[5]
Dec Ledwaardes[6]
GoSub PWM_lus
Next
'00XI1000
For I = 0 To snelheid
Inc Ledwaardes[3]
Inc Ledwaardes[3]
Dec Ledwaardes[4]
Dec Ledwaardes[5]
GoSub PWM_lus
Next
'0XI10000
For I = 0 To snelheid
Inc Ledwaardes[2]
Inc Ledwaardes[2]
Dec Ledwaardes[3]
Dec Ledwaardes[4]
GoSub PWM_lus
Next
'XI100000
For I = 0 To snelheid
Inc Ledwaardes[1]
Inc Ledwaardes[1]
Dec Ledwaardes[2]
Dec Ledwaardes[3]
GoSub PWM_lus
Next
Wend

'****************************************************************
PWM_lus:
For index = 0 To (snelheid *2)
If Ledwaardes[1] > index Then
High led1
Else
Low led1
EndIf
If Ledwaardes[2] > index Then
High led2
Else
Low led2
EndIf
If Ledwaardes[3] > index Then
High led3
Else
Low led3
EndIf
If Ledwaardes[4] > index Then
High led4
Else
Low led4
EndIf
If Ledwaardes[5] > index Then
High led5
Else
Low led5
EndIf
If Ledwaardes[6] > index Then
High led6
Else
Low led6
EndIf
If Ledwaardes[7] > index Then
High led7
Else
Low led7
EndIf
If Ledwaardes[8] > index Then
High led8
Else
Low led8
EndIf
Next
Return

'****************************************************************
End

Dit programma is getest op mijn PIC ontwikkelbordje.

Een reactie achterlaten

Your email address will not be published.