Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;
- ; book scanner za kiber pipu 15.11.12.
- ;
- ; ____ ____
- ; MCLR | \__/ | B7 PGD
- ; LM in A0 | | B6 PGC
- ; tranz out A1 | | B5 out cw/ccw
- ; out A2 | | B4 out -Full Power
- ; test key in A3 | | B3 out EXP0
- ; in A4 | | B2 in KEY
- ; mot clk out A5 | 2525 | B1 in HALL
- ; Vss | | B0 LM in
- ; 16 MHz Osc | | Vdd
- ; 16 MHz Osc | | Vss
- ; LED out C0 | | C7 RXD
- ; EXP2 out C1 | | C6 TXD
- ; in C2 | | C5 out EXP1
- ; in C3 |____________| C4 out
- ;
- LIST P=18F2525
- #include <P18F2525.INC>
- #define motclock lata,5
- #define cwccw latb,5
- #define motpower latb,4
- #define led lata,2
- #define click0 latc,5 ; (uostravanje)
- #define click1 latc,5 ; (camera 1)
- #define click2 latc,1 ; (camera 2)
- #define hilite2 latc,0
- #define key porta,3
- #define extkey portb,2
- #define hall portb,1
- config osc = HS
- config fcmen = off
- config ieso = off
- config pwrt = on
- config borv = 1
- config wdt = off
- config mclre = on
- config lpt1osc = off
- config pbaden = off
- config stvren = on
- config lvp = off
- config xinst = off
- config debug = off
- config cp0 = off
- config cp1 = off
- config cp2 = off
- config cpb = off
- config cpd = off
- config wrt0 = on
- config wrt1 = on
- config wrt2 = on
- config wrtb = on
- config wrtc = on
- config wrtd = off
- config ebtr0 = off
- config ebtr1 = off
- config ebtr2 = off
- config ebtrb = off
- CBLOCK 0
- inner
- outer
- keyrotor
- stepcount
- liftcount
- speedbyte
- ENDC
- ;____________________________________________________MACROS
- gore macro
- bcf cwccw
- endm
- dole macro
- bsf cwccw
- endm
- weak macro
- bsf motpower ; low power
- endm
- strong macro
- bcf motpower ; high power
- endm
- ifhallon macro
- btfss hall
- endm
- ifhalloff macro
- btfsc hall
- endm
- defspeed macro
- movlw .56
- movwf speedbyte
- endm
- speed macro speedvalue
- movlw speedvalue
- movwf speedbyte
- endm
- ifz macro
- btfsc status,z
- endm
- ifnz macro
- btfss status,z
- endm
- ifc macro
- btfsc status,c
- endm
- ifnc macro
- btfss status,c
- endm
- ;*********************************************************************************
- ;*********************************************************************************
- ;**************** *****************
- ;**************** M A I N *****************
- ;**************** *****************
- ;*********************************************************************************
- ;*********************************************************************************
- org 0
- movlw 0fh
- movwf adcon1
- movlw 7
- movwf cmcon
- movlw b'00000000'
- movwf porta
- movlw b'00000000'
- movwf portb
- movlw b'00000000'
- movwf portc
- movlw B'011001'
- movwf trisa
- movlw B'00000111'
- movwf trisb
- movlw B'10001100'
- movwf trisc
- ; ___ clear ram bank 0-3
- lfsr fsr0,0
- goclr1k
- clrf postinc0
- btfss fsr0h,2
- goto goclr1k
- ;******************************************************************************
- ;******************************************************************************
- ;** **
- ;** F A R M **
- ;** **
- ;******************************************************************************
- ;******************************************************************************
- ; jedan step motora je 0,153 mm
- bcf led
- call home
- ifc
- goto goerror
- farm
- defspeed
- bcf led
- weak
- dole
- call waitkey
- strong
- call slowstart
- movlw .123
- movwf liftcount
- move_down ; \ u ovoj petlji ide nadole
- call mm2
- decfsz liftcount,f
- bra move_down ; / u ovoj petlji ide nadole
- btfsc extkey
- bra otp1
- ; still down mode
- waitjust
- call timing0
- weak
- gore
- bsf hilite2
- bcf status,c
- btfsc extkey
- bsf status,c
- rlcf keyrotor
- movf keyrotor,w
- xorlw b'11111110'
- bnz waitjust
- bra goup
- otp1
- call timing2
- weak
- gore
- bsf hilite2
- movlw 0
- call timing3
- bsf click0
- bsf click1
- call timing3
- bsf click2
- call timing3
- call timing3
- call timing3
- call timing3
- call timing3
- call timing3
- call timing3
- call timing3
- bcf click0
- bcf click1
- call timing3
- bcf click2
- call timing3
- call timing3
- call timing3
- call timing3
- call timing3
- call timing3
- call timing3
- goup
- bcf hilite2
- call home ; ide nagore
- ifc
- goto goerror
- call timing2
- bra farm
- ;-------------------------------
- showhall
- ifhallon
- bsf led
- ifhalloff
- bcf led
- return
- ;-------
- mm2 ; napravi 13 koraka (2 mm)
- movlw .13 ; za 2 mm
- movwf stepcount
- gost20
- btg motclock
- call timing
- btg motclock
- call timing
- decfsz stepcount,f
- bra gost20
- return
- ;-------
- timing0
- movlw .5
- movwf outer
- bra gostep
- timing2
- movlw .200
- movwf outer
- bra gostep
- timing
- movf speedbyte,w
- movwf outer
- gostep2
- movlw .6
- movwf inner
- gostep
- decfsz inner,f
- bra gostep
- decfsz outer,f
- bra gostep2
- return
- ;-------
- timing3 ; dugi tajming, period w
- movwf outer
- gostep3
- nop
- nop
- nop
- nop
- nop
- decfsz inner,f
- bra gostep3
- decfsz outer,f
- bra gostep3
- return
- ;-------
- waitkey
- btfss extkey
- return
- btfss key
- return
- bra waitkey
- ;-------------------------------
- home
- strong
- defspeed
- ifhalloff
- bra samogore
- ; prvo ide dole da se otkaci od halla
- dole
- call slowstart
- movlw .3 ; za 20 mm
- call gosteps2
- call slowstop
- ifhallon
- goto errhome
- movlw .200
- call timing3
- samogore ; ide gore do halla, error ako ga nije nasao
- gore
- call slowstart_long
- defspeed
- movlw .150 ; za 300 mm max posle kojih prijavljuje gresku
- call gosteps
- bc errhome
- slowstop ; sad ide jos usporeno
- speed 90
- movlw 1 ; jos 2 mm
- call gosteps2
- speed 160
- movlw 1 ; jos 2 mm
- call gosteps2
- speed 200
- movlw 1 ; jos 2 mm
- call gosteps2
- bcf status,c ; NC = no error
- return
- errhome
- bsf status,c ; C = error
- return
- ;-------
- slowstart
- speed 200
- movlw 1 ; jos 2 mm
- call gosteps2
- speed 160
- movlw 2 ; jos 2 mm
- call gosteps2
- speed 90
- movlw 3 ; jos 2 mm
- call gosteps2
- defspeed
- return
- slowstart_long
- speed 160
- movlw 8 ; x 2 mm
- call gosteps2
- speed 120
- movlw 1 ; x 2 mm
- call gosteps2
- speed 90
- movlw 1 ; x 2 mm
- call gosteps2
- defspeed
- return
- ;-------
- gosteps ; napravi w*2mm, stop and clr C if hall low
- strong
- movwf liftcount
- godns
- call mm2
- ifhallon
- bra foundhall
- decfsz liftcount,f
- bra godns
- bsf status,c ; set C, error (nije nasao hall)
- return
- foundhall
- bcf status,c ; clr C, nasao hall
- return
- ;-------
- gosteps2 ; samo napravi w*2mm bezuslovno
- strong
- movwf liftcount
- godns2
- call mm2
- decfsz liftcount,f
- bra godns2
- return
- ;------------------------------
- goerror ; samo blinka led do beskraja
- weak
- btg led
- clrf wreg
- call timing3
- bra goerror
- ;------------------------------
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement