Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Author = Arvids Dzintarnieks, Yonatan Dawit
- ; University = Coventry University
- ; Title = Final Project
- ; Date = 13/12/2019
- ;******************************************************************************
- LIST P=18F4520 ; directive to define processor
- #include <P18F4520.INC> ; processor specific variable definitions
- ;******************************************************************************
- ; CONFIGURATION BITS
- ; (Microchip has changed the format for defining the configuration bits, please
- ; see the .inc file for further details on notation). Below are a few examples.
- ;
- ;
- ;
- ; Oscillator Selection and other fuse settings:
- CONFIG OSC = HS ;High Speed clock
- CONFIG MCLRE = ON ;MCLR enabled
- CONFIG DEBUG = OFF ;Background debugger disabled, RB6 and RB7 configured as general IO
- CONFIG LVP = OFF ; Low Voltage Programming OFF
- CONFIG WDT = OFF ; WDT disabled
- ;******************************************************************************
- ; RESET VECTOR
- ; This code will start executing when a reset occurs.
- ORG 0x0000 ; ORG
- goto Main
- DELVAL1 EQU 0XFF
- DELVAL2 EQU 0X20
- DELVAL3 EQU 0X05
- Main: MOVLW 0x00 ; configure portd as output
- MOVWF TRISD
- MOVLW b'00000011' ; configure portc as input
- MOVWF TRISC
- BCF PORTC,2 ;clear the pins because otherwise the LED's shine
- BCF PORTC,3 ;
- goto Start
- Start: BTFSC PORTC,0 ; test if bit is 0
- goto Start ; if its not 0 repeat test
- CALL DELAY ; if it is 0 call HOLD-start and go to second check
- goto Check1
- Check1: BTFSC PORTC,1 ;test if bit is 0, skip next line if its 0
- goto Red ;if its not, the pepper is red
- goto Green ;if its 0, the pepper is green
- Green: INCF PORTD
- BTFSC PORTD,0 ;check if number COULD be 9 (check if first bit is 1)
- CALL GCheck ;skip this line if its not
- goto GRelay
- GCheck: BTFSC PORTD,3 ;check if bit is 0, skip next line if its 0
- CALL GFull
- RETURN
- GFull: BSF PORTC,2 ;turn on green box full LED
- CALL DELAY ;call delay twice, otherwise the counter jumps from 8 to 0
- CALL DELAY
- BCF PORTD,0 ;clear the bits for binary 9 (1001)
- BCF PORTD,3
- CALL DELAY ;call delay twice before turning off green box full LED
- CALL DELAY
- BCF PORTC,2 ;turn off green box full LED
- RETURN
- GRelay: BSF PORTC,4 ;turn on green relay LED
- CALL DELAY ;call delay twice
- CALL DELAY
- CALL Check2 ;wait for pepper to pass
- BCF PORTC,4 ;turn off green relay LED
- goto Start ;go back to start
- Red: MOVLW 0x10 ;moves the number 10 into W
- ADDWF PORTD ;add 10 to the counter
- BTFSC PORTD,4 ;checks if the counter could be 9
- CALL RCheck ;if it could, check if it is 9
- goto RRelay ;open the red relay
- RCheck: BTFSC PORTD,7 ;check if bit is 0, skip next line if its 0
- CALL RFull ;if it is 9 (binary 1001) call the Red Full routine
- RETURN
- RFull: BSF PORTC,3 ;turn on red box full LED
- CALL DELAY ; call delay twice, otherwise the counter jumps from 8 to 0
- CALL DELAY
- BCF PORTD,4 ;clear the bits for BINARY 9 (1001)
- BCF PORTD,7
- CALL DELAY ;call delay twice before turning off red bux full LED
- CALL DELAY
- BCF PORTC,3 ;turn off red box full LED
- RETURN
- RRelay: BSF PORTC,5 ;turn on red relay LED
- CALL DELAY ;call delay twice
- CALL DELAY
- CALL Check2 ;wait for pepper to pass
- BCF PORTC,5 ;turn off red relay LED
- goto Start ;go back to start of code
- Check2: BTFSS PORTC,0 ; test if bit is 0 (wait for pepper to go past LDR before checking for next one)
- goto Check2 ; if its not 0 repeat test
- CALL DELAY ; call the delay before returningD
- RETURN
- ; DELAY ROUTINE
- DELAY MOVLW 0XFF ; Move Literal value 0xFF into W (first delay value)
- MOVWF DELVAL1 ; Store this value in location DELVAL1
- MOVLW 0X03 ; Move Literal value 0x03into W (Delay value 3)
- MOVWF DELVAL3 ; Store into DELVAL3 location
- REPEAT MOVLW 0XFF ; Move Literal value 0xFF into W
- MOVWF DELVAL2 ; Move contents of W (FF) into DELVAL2
- HERE NOP ; No Operation
- DECF DELVAL2,F ; Decrement contents of DELVAL2
- BNZ HERE ; If has not reached zero branch to location HERE
- DECF DELVAL1,F ; Decrement contents of DELVAL1
- BNZ REPEAT ; If not zero branch to location REPEAT
- DECF DELVAL3 ; Decrement contents of DELVAL3
- BNZ HERE ; If not zero go to location HERE
- RETURN
- ;******************************************************************************
- ; End of program
- END ; End Directive
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement