Elektronica Stynus
 

Lichteffecten vlieger stroboscoop code.

Terug naar het project

De code van de stroboscoop(pic-baisc)

'****************************************************************
'*  Author  : Coenen Stijn [Stynus]                             *
'*  Notice  : Copyright (c) 2007 [www.elektronicastynus.be]     *
'*          : All Rights Reserved                               *
'*  Date    : 14/01/2008                                        *
'*  Version : 4.1                                               *
'*  Notes   : Programma stroboscoop looplicht zippist           *
'*          :                                                   *
'****************************************************************
'Pin configuraties
'Rechts                         Links
'   00 --> D01 --> PORTA.0          00 --> D30 --> PORTB.7  
'   01 --> D02 --> PORTA.1          01 --> D29 --> PORTB.6
'   02 --> D03 --> PORTA.2          02 --> D28 --> PORTB.5
'   03 --> D04 --> PORTA.3          03 --> D27 --> PORTB.4
'   04 --> D05 --> PORTD.7          04 --> D26 --> PORTB.3
'   05 --> D06 --> PORTA.5          05 --> D25 --> PORTB.2
'   06 --> D07 --> PORTE.0          06 --> D24 --> PORTB.1
'   07 --> D08 --> PORTE.1          07 --> D23 --> PORTB.0
'   10 --> D09 --> PORTE.2          10 --> D22 --> PORTD.6 
'   11 --> D10 --> PORTC.0          11 --> D21 --> PORTD.5
'   12 --> D11 --> PORTC.1          12 --> D20 --> PORTD.4
'   13 --> D12 --> PORTC.2          13 --> D19 --> PORTD.7
'   14 --> D13 --> PORTD.0          14 --> D18 --> PORTC.6
'   15 --> D14 --> PORTD.1          15 --> D17 --> PORTC.5
'   16 --> D15 --> PORTD.2          16 --> D16 --> PORTD.3
'LDR   --> RA4 --> Bij licht hoog
'Eeprom
'   RCK = RC3
'   SDA = RC4
'Config
        Device          16F877A
        Config          WDT_Off, PWRTE_ON, XT_OSC , PWRTE_ON, lvp_off
        ALL_DIGITAL     TRUE    
        XTAL            = 4
        Dim     w       As Byte

'In en uitgangen aanduiden
    'Rechts
        Dim    ledRL    As Byte
        Symbol LED01R   = PORTA.0 'D01
        Symbol LED02R   = PORTA.1 'D02
        Symbol LED03R   = PORTA.2 'D03
        Symbol LED04R   = PORTA.3 'D04
        Symbol LED05R   = PORTD.7 'D05
        Symbol LED06R   = PORTA.5 'D06
        Symbol LED07R   = PORTE.0 'D07
        Symbol LED08R   = PORTE.1 'D08
    '
        Dim    ledRH    As Byte        
        Symbol LED09R   = PORTE.2 'D09
        Symbol LED10R   = PORTC.0 'D10
        Symbol LED11R   = PORTC.1 'D11
        Symbol LED12R   = PORTC.2 'D12
        Symbol LED13R   = PORTD.0 'D13
        Symbol LED14R   = PORTD.1 'D14
        Symbol LED15R   = PORTD.2 'D15
    'links
        Dim    ledLL    As Byte
        Symbol LED01L   = PORTB.7 'D30
        Symbol LED02L   = PORTB.6 'D29
        Symbol LED03L   = PORTB.5 'D28
        Symbol LED04L   = PORTB.4 'D27
        Symbol LED05L   = PORTB.3 'D26
        Symbol LED06L   = PORTB.2 'D25
        Symbol LED07L   = PORTB.1 'D24
        Symbol LED08L   = PORTB.0 'D23
    '
        Dim    ledLH    As Byte
        Symbol LED09L   = PORTD.6 'D22
        Symbol LED10L   = PORTD.5 'D21
        Symbol LED11L   = PORTD.4 'D20
        Symbol LED12L   = PORTC.7 'D19
        Symbol LED13L   = PORTC.6 'D18
        Symbol LED14L   = PORTC.5 'D17
        Symbol LED15L   = PORTD.3 'D16
    'Ldr
        Symbol LDR      = PORTA.4 'LDR
    'Eeprom
        Symbol  SCL         =   PORTC.3
        Symbol  SDA         =   PORTC.4
        Declare I2C_SLOW    On

'Variabelen declareren
    'Variabelen EEProm
        Dim    Address   As Word     '16-bit address required
    'Variabelen Diversen
        Dim tijd        As Byte
        Dim hAdress     As Word
        Dim hAdress1    As Byte
        Dim hAdress2    As Byte
        Clear
        DelayMS 100
'****************************************************************
'Hoogste adres uitlezen  
        Address     = 0
        I2Cin SDA, SCL, $A1 , Address, [hAdress1]       '0
        Inc Address 
        I2Cin SDA, SCL, $A1 , Address, [hAdress2]       '1
        Inc Address                                     '2
    'Twee bytes samenvoegen in woord
        hAdress.LowByte   = hAdress2   
        hAdress.HighByte  = hAdress1 

'****************************************************************
'Hoofdprogramma  
Main:
    'Kijken of ldr hoog is
    GoSub   ldrHoog
    'Eeprom inlezen uitgangen
    GoSub   EEUitgangen
    'Vertragingstijd inlezen
    GoSub   EEvertragingstijd    
    'Uitgangen aansturen
    GoSub RL
    GoSub RH
    GoSub LL
    GoSub LH 
    'Wachten
    GoSub   Wachten
    'Kijken of het max adres niet berijkt is
    GoSub   adrescheck

GoTo Main:
'****************************************************************
'Subroutine's
    'Eeprom inlezen:
    EEUitgangen:
            DelayMS 10
         'Rechtse laagste leds inlezen
            I2Cin SDA, SCL, $A1 , Address, [ledRL]    
            Inc Address
        'Rechtse hoogste leds inlezen
            I2Cin SDA, SCL, $A1 , Address, [ledRH] 
            Inc Address 
        'Linkse laagste leds inlezen
            I2Cin SDA, SCL, $A1 , Address, [ledLL]  
            Inc Address   
        'Linkse hoogste leds inlezen
            I2Cin SDA, SCL, $A1 , Address, [ledLH]    
            Inc Address 
    Return
    'Vertragingstijd inlezen:
    EEvertragingstijd:
        I2Cin SDA, SCL, $A1 , Address, [tijd]    
        Inc Address
    Return
    'Delay
    Wachten:
        DelayMS (tijd * 10)       
    Return
    'Kijken of het hoogste adres niet berijkt is:
    adrescheck:
        If Address >= hAdress Then
            Low LED15R
            Low LED14R
            Low LED13R
            Low LED12R
            Low LED11R
            Low LED10R
            Low LED09R
            Low LED08R
            Low LED07R
            Low LED06R
            Low LED05R
            Low LED04R
            Low LED03R
            Low LED02R
            Low LED01R
            Low LED15L
            Low LED14L
            Low LED13L
            Low LED12L
            Low LED11L
            Low LED10L
            Low LED09L
            Low LED08L
            Low LED07L
            Low LED06L
            Low LED05L
            Low LED04L
            Low LED03L
            Low LED02L
            Low LED01L
            Address = 2
        EndIf
    Return
    '************************************************************
    'Lus voor bij enable uit.
    ldrHoog:
        hoog:
            If LDR = 0 Then
                Return
            Else
                Low LED15R
                Low LED14R
                Low LED13R
                Low LED12R
                Low LED11R
                Low LED10R
                Low LED09R
                Low LED08R
                Low LED07R
                Low LED06R
                Low LED05R
                Low LED04R
                Low LED03R
                Low LED02R
                Low LED01R
                Low LED15L
                Low LED14L
                Low LED13L
                Low LED12L
                Low LED11L
                Low LED10L
                Low LED09L
                Low LED08L
                Low LED07L
                Low LED06L
                Low LED05L
                Low LED04L
                Low LED03L
                Low LED02L
                Low LED01L
                Address = 2
                GoTo hoog
            EndIf
        GoTo hoog
    Return
    '************************************************************ 
    'Rechts
    'Laagste bits
    RL:
        w = ledRL
        Low LED08R
        Low LED07R
        Low LED06R
        Low LED05R
        Low LED04R
        Low LED03R
        Low LED02R
        Low LED01R
        If w > 127 Then
            High LED08R
            w = w - 128
        EndIf
        If w > 63 Then
            High LED07R
            w = w - 64
        EndIf
        If w > 31 Then
            High LED06R
            w = w - 32
        EndIf
        If w > 15 Then
            High LED05R
            w = w - 16
        EndIf
        If w > 7 Then
            High LED04R
            w = w - 8
        EndIf
        If w > 3 Then
            High LED03R
            w = w - 4
        EndIf
        If w > 1 Then
            High LED02R
            w = w - 2
        EndIf
        If w = 1 Then
            High LED01R
        EndIf    
    Return
    'Hoogste bits:
    RH:
        w = ledRH
        Low LED15R
        Low LED14R
        Low LED13R
        Low LED12R
        Low LED11R
        Low LED10R
        Low LED09R
        If w > 63 Then
            High LED15R
            w = w - 64
        EndIf
        If w > 31 Then
            High LED14R
            w = w - 32
        EndIf
        If w > 15 Then
            High LED13R
            w = w - 16
        EndIf
        If w > 7 Then
            High LED12R
            w = w - 8
        EndIf
        If w > 3 Then
            High LED11R
            w = w - 4
        EndIf
        If w > 1 Then
            High LED10R
            w = w - 2
        EndIf
        If w = 1 Then
            High LED09R
        EndIf
    Return
    'links
    'laagste bits
    LL:
        w = ledLL 
        Low LED08L
        Low LED07L
        Low LED06L
        Low LED05L
        Low LED04L
        Low LED03L
        Low LED02L
        Low LED01L
        If w > 127 Then
            High LED08L
            w = w - 128
        EndIf
        If w > 63 Then
            High LED07L
            w = w - 64
        EndIf
        If w > 31 Then
            High LED06L
            w = w - 32
        EndIf
        If w > 15 Then
            High LED05L
            w = w - 16
        EndIf
        If w > 7 Then
            High LED04L
            w = w - 8
        EndIf
        If w > 3 Then
            High LED03L
            w = w - 4
        EndIf
        If w > 1 Then
            High LED02L
            w = w - 2
        EndIf
        If w = 1 Then
            High LED01L
        EndIf     
    Return
    'hoogste bits
    LH:
        w = ledLH
        Low LED15L
        Low LED14L
        Low LED13L
        Low LED12L
        Low LED11L
        Low LED10L
        Low LED09L
        If w > 63 Then
            High LED15L
            w = w - 64
        EndIf
        If w > 31 Then
            High LED14L
            w = w - 32
        EndIf
        If w > 15 Then
            High LED13L
            w = w - 16
        EndIf
        If w > 7 Then
            High LED12L
            w = w - 8
        EndIf
        If w > 3 Then
            High LED11L
            w = w - 4
        EndIf
        If w > 1 Then
            High LED10L
            w = w - 2
        EndIf
        If w = 1 Then
            High LED09L
        EndIf    
    Return

'****************************************************************
'Bij fout:
GoTo Main       
End

Top

Reactie's