Stap 2: Code
Om de batterij laatst moest zo lang mogelijk, het circuit gebruiken de minste hoeveelheid macht die ik konden postuur, terwijl het idee levend te houden. Dus, heb ik besloten om de eerste activiteit tot een gemiddelde van 1 LED-flitser of motor verplaatsen elke 6 seconden.
De code heeft 12 willekeurige "activiteiten", variërend van 1 LED inschakelen, de motor draaien op voor verschillende perioden of routebeschrijving, een willekeurige wachten staat. Evenementen variëren van 3 seconden uit elkaar op meer dan 40 seconden uit elkaar, op basis van de willekeurige gebeurtenis gegenereerd.
CODE
;===============================================================================
Schijf-Controller
;
; -----------
; VCC-|1 8| > <-Vss
; M <> - GPIO5 |2 7| GPIO0---> LED1
; M <> - GPIO4 |3 6| GPIO1---> LED2
; GPIO3 -> |4 5| GPIO2---> LED3
; -----------
;
;===============================================================================
; Revisiegeschiedenis & nota's:
; V1.0 de oorspronkelijke Header, Code 5/19/09
;
;
; (C) 5/2009
; Deze code kan worden gebruikt voor persoonlijke leren / / wijzigingen in de toepassing.
; Elk gebruik van deze code in commerciële producten in strijd is met deze versie van de freeware.
; Voor vragen/opmerkingen, circuit dot mage op yahoo dot com te contacteren.
;-------------------------------------------------------------------------------
#include P12C672. INC
;===============================================================================
; Definieert
;-------------------------------------------------------------------------------
;===============================================================================
; Gegevens
;-------------------------------------------------------------------------------
; Tijd bijhouden variabelen
count1 equ 20
count2 equ 21
vertraging equ 22
Randlo equ 23
Randhi equ 24
Wtemp equ 25
Temp2 equ 26
rand equ 27
count3 equ 28
;===============================================================================
; Reset vectoren
;
; SELECTIEVAKJE CONFIG. BITS VOORDAT HET BRANDEN!
; INTOSC
; PICSSOFTWARE: INGESCHAKELD
; PWRUP: INGESCHAKELD
; ALLE ANDEREN: UITSCHAKELEN!!
;
;-------------------------------------------------------------------------------
RESET_ADDR EQU 0X00
org RESET_ADDR
goto start
;===============================================================================
; Start hier!
;-------------------------------------------------------------------------------
Start
; Config i/o-poorten
BCF STATUS, RP1
BSF STATUS, RP0
movlw h '08'; RA < 0-7 > uitgangen, PGIO3 altijd input
Tris GPIO
movlw h '07'; Set GPIO naar de digitale modus
movwf ADCON1
; Instellen interne timer
movlw h'CF'; Tmr0 interne bron, prescale TMR0 1:256
movwf OPTION_REG
movlw h '00'
movwf INTCON; TMR0 interrupts, uitschakelen
BCF STATUS, RP0
; Initialiseren van de Registers
clrf GPIO
clrf count1
clrf count2
movlw 045h
movwf Randlo
movlw 030h
movwf Randhi
; 1 sec wachten.
oproep ontdendering; 0.2 sec
oproep ontdendering
oproep ontdendering
oproep ontdendering
oproep ontdendering
;===============================================================================
; Main
;-------------------------------------------------------------------------------
belangrijkste
oproep twosec; 2 secs min tussen elke actie
SRF Randhi, W
xorwf Randlo, W
movwf Wtemp
swapf Wtemp
RLF Randhi, W
xorwf Randhi, W; LSB = xorwf(Q12,Q3)
xorwf Wtemp
RLF Wtemp
RLF Randlo
RLF Randhi
movfw Wtemp, strip willekeurige 16 tot 7
andlw 0x0F
movwf rand
; willekeurige routine selectie
xorlw 0x00; 0?
btfsc STATUS, Z
goto flash1; Ja. Bel 0de
movfw rand
xorlw 0x01; 1?
btfsc STATUS, Z
goto flash2; Ja. Bel 1ste
movfw rand
xorlw 0x02; 2?
btfsc STATUS, Z
goto flash3; Ja. Bel 2e
movfw rand
xorlw 0x03; 3?
btfsc STATUS, Z
goto flashall; Ja. Bel 3e
movfw rand
xorlw 0x04; 4?
btfsc STATUS, Z
goto movels; Ja. Bel 4e
movfw rand
xorlw 0x05; 5?
btfsc STATUS, Z
goto movell; Ja. Bel 5e
movfw rand
xorlw 0x06; 6?
btfsc STATUS, Z
goto verhuizers; Ja. Bel 6e
movfw rand
xorlw 0x07; 7?
btfsc STATUS, Z
goto moverl; Ja. Bel 7de
movfw rand
xorlw 0x08; 8?
btfsc STATUS, Z
goto moveburst; Ja. Bel 8
movfw rand
xorlw 0x09; 9?
btfsc STATUS, Z
goto Wait1; Ja. Bel 9
movfw rand
xorlw 0x0A; A?
btfsc STATUS, Z
goto Wait2; Ja. Oproep Ath
movfw rand
xorlw 0x0B; B?
btfsc STATUS, Z
goto Wait3; Ja. Oproep Bth
goto niets; 1/4 de tijd, doen niets voor 10 seconden.
flash1
BSF GPIO, 0
oproep ontdendering
BCF GPIO, 0
goto belangrijkste
flash2
BSF GPIO, 1
oproep ontdendering
BCF GPIO, 1
goto belangrijkste
flash3
BSF GPIO, 2
oproep ontdendering
BCF GPIO, 2
goto belangrijkste
flashall
BSF GPIO, 0
BSF GPIO, 1
BSF GPIO, 2
oproep ontdendering
oproep ontdendering
BCF GPIO, 0
BCF GPIO, 1
BCF GPIO, 2
goto belangrijkste
movels
BSF GPIO, 4
BCF GPIO, 5
oproep ontdendering
BCF GPIO, 4
goto belangrijkste
movell
BSF GPIO, 4
BCF GPIO, 5
oproep ontdendering
oproep ontdendering
BCF GPIO, 4
goto belangrijkste
verhuizers
BCF GPIO, 4
BSF GPIO, 5
oproep ontdendering
BCF GPIO, 5
goto belangrijkste
moverl
BCF GPIO, 4
BSF GPIO, 5
oproep ontdendering
oproep ontdendering
BCF GPIO, 5
goto belangrijkste
moveburst
BCF GPIO, 4
BSF GPIO, 5
oproep ontdendering; bewegen recht 3 keer, korte uitbarstingen.
BCF GPIO, 5
oproep ontdendering
oproep ontdendering
BSF GPIO, 5
oproep ontdendering
oproep ontdendering
BCF GPIO, 5
oproep ontdendering
oproep ontdendering
BSF GPIO, 5
oproep ontdendering
BCF GPIO, 5
oproep ontdendering
oproep ontdendering
oproep ontdendering
oproep ontdendering
BSF GPIO, 4; links 3 keer, korte uitbarstingen verplaatsen
BCF GPIO, 5
oproep ontdendering
oproep ontdendering
BCF GPIO, 4
oproep ontdendering
oproep ontdendering
BSF GPIO, 4
oproep ontdendering
oproep ontdendering
BCF GPIO, 4
oproep ontdendering
oproep ontdendering
BSF GPIO, 4
oproep ontdendering
oproep ontdendering
BCF GPIO, 4
oproep ontdendering
oproep ontdendering
goto belangrijkste
Wait1; Wacht 1 seconden
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
goto belangrijkste
Wait2; 0.6 seconden
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
goto belangrijkste
Wait3; 4 seconden
oproep twosec
oproep twosec
goto belangrijkste
niets
movlw.50; Vertraging gedurende 10 seconden totaal
movwf count3
nothing_loop
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
decfsz count3, F
goto nothing_loop
goto belangrijkste
;===============================================================================
; 2 seconden wachten
;-------------------------------------------------------------------------------
twosec
movlw.10; Vertraging gedurende 2 seconden totaal
movwf count3
twosec_loop
movlw.255; De wachttijd voor debounce van 2/10 seconde.
movwf count2
oproep pon_wait
decfsz count3, F
goto twosec_loop
terugkeer
;===============================================================================
; Ontdendering signaal
; 4 cycli te laden en te roepen, 2 cycli om terug te keren.
; 4 Mhz Tc:: count2 = 255 -> 0.2 sec
;-------------------------------------------------------------------------------
ontdendering
movlw.127; De wachttijd voor 1/10 seconde debounce.
movwf count2
oproep pon_wait
terugkeer
;-------------------------------------------------------------------------------
; count1 = 255 d:: 775 cycli aan 0, + 3 cycli om terug te keren.
;-------------------------------------------------------------------------------
pon_wait
big_loopS
movlw.255
movwf count1
short_loopS
decfsz count1, F
goto short_loopS
decfsz count2, F
goto big_loopS
terugkeer
einde