Advertisement
Guest User

Arvids Dzintarnieks and Yonatan Dawit Final Project Code

a guest
Dec 13th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.59 KB | None | 0 0
  1. ; Author = Arvids Dzintarnieks, Yonatan Dawit
  2. ; University = Coventry University
  3. ; Title = Final Project
  4. ; Date = 13/12/2019
  5. ;******************************************************************************
  6.  
  7. LIST P=18F4520 ; directive to define processor
  8. #include <P18F4520.INC> ; processor specific variable definitions
  9.  
  10. ;******************************************************************************
  11. ; CONFIGURATION BITS
  12. ; (Microchip has changed the format for defining the configuration bits, please
  13. ; see the .inc file for further details on notation). Below are a few examples.
  14. ;
  15. ;
  16. ;
  17. ; Oscillator Selection and other fuse settings:
  18.  
  19. CONFIG OSC = HS ;High Speed clock
  20. CONFIG MCLRE = ON ;MCLR enabled
  21. CONFIG DEBUG = OFF ;Background debugger disabled, RB6 and RB7 configured as general IO
  22. CONFIG LVP = OFF ; Low Voltage Programming OFF
  23. CONFIG WDT = OFF ; WDT disabled
  24.  
  25. ;******************************************************************************
  26. ; RESET VECTOR
  27. ; This code will start executing when a reset occurs.
  28.  
  29. ORG 0x0000 ; ORG
  30.  
  31. goto Main
  32.  
  33. DELVAL1 EQU 0XFF
  34. DELVAL2 EQU 0X20
  35. DELVAL3 EQU 0X05
  36.  
  37. Main: MOVLW 0x00 ; configure portd as output
  38. MOVWF TRISD
  39. MOVLW b'00000011' ; configure portc as input
  40. MOVWF TRISC
  41. BCF PORTC,2 ;clear the pins because otherwise the LED's shine
  42. BCF PORTC,3 ;
  43. goto Start
  44.  
  45. Start: BTFSC PORTC,0 ; test if bit is 0
  46. goto Start ; if its not 0 repeat test
  47. CALL DELAY ; if it is 0 call HOLD-start and go to second check
  48. goto Check1
  49.  
  50. Check1: BTFSC PORTC,1 ;test if bit is 0, skip next line if its 0
  51. goto Red ;if its not, the pepper is red
  52. goto Green ;if its 0, the pepper is green
  53.  
  54. Green: INCF PORTD
  55. BTFSC PORTD,0 ;check if number COULD be 9 (check if first bit is 1)
  56. CALL GCheck ;skip this line if its not
  57. goto GRelay
  58.  
  59. GCheck: BTFSC PORTD,3 ;check if bit is 0, skip next line if its 0
  60. CALL GFull
  61. RETURN
  62.  
  63. GFull: BSF PORTC,2 ;turn on green box full LED
  64. CALL DELAY ;call delay twice, otherwise the counter jumps from 8 to 0
  65. CALL DELAY
  66. BCF PORTD,0 ;clear the bits for binary 9 (1001)
  67. BCF PORTD,3
  68. CALL DELAY ;call delay twice before turning off green box full LED
  69. CALL DELAY
  70. BCF PORTC,2 ;turn off green box full LED
  71. RETURN
  72.  
  73. GRelay: BSF PORTC,4 ;turn on green relay LED
  74. CALL DELAY ;call delay twice
  75. CALL DELAY
  76. CALL Check2 ;wait for pepper to pass
  77. BCF PORTC,4 ;turn off green relay LED
  78. goto Start ;go back to start
  79.  
  80. Red: MOVLW 0x10 ;moves the number 10 into W
  81. ADDWF PORTD ;add 10 to the counter
  82. BTFSC PORTD,4 ;checks if the counter could be 9
  83. CALL RCheck ;if it could, check if it is 9
  84. goto RRelay ;open the red relay
  85.  
  86. RCheck: BTFSC PORTD,7 ;check if bit is 0, skip next line if its 0
  87. CALL RFull ;if it is 9 (binary 1001) call the Red Full routine
  88. RETURN
  89.  
  90. RFull: BSF PORTC,3 ;turn on red box full LED
  91. CALL DELAY ; call delay twice, otherwise the counter jumps from 8 to 0
  92. CALL DELAY
  93. BCF PORTD,4 ;clear the bits for BINARY 9 (1001)
  94. BCF PORTD,7
  95. CALL DELAY ;call delay twice before turning off red bux full LED
  96. CALL DELAY
  97. BCF PORTC,3 ;turn off red box full LED
  98. RETURN
  99.  
  100. RRelay: BSF PORTC,5 ;turn on red relay LED
  101. CALL DELAY ;call delay twice
  102. CALL DELAY
  103. CALL Check2 ;wait for pepper to pass
  104. BCF PORTC,5 ;turn off red relay LED
  105. goto Start ;go back to start of code
  106.  
  107. Check2: BTFSS PORTC,0 ; test if bit is 0 (wait for pepper to go past LDR before checking for next one)
  108. goto Check2 ; if its not 0 repeat test
  109. CALL DELAY ; call the delay before returningD
  110. RETURN
  111.  
  112.  
  113.  
  114. ; DELAY ROUTINE
  115.  
  116. DELAY MOVLW 0XFF ; Move Literal value 0xFF into W (first delay value)
  117. MOVWF DELVAL1 ; Store this value in location DELVAL1
  118. MOVLW 0X03 ; Move Literal value 0x03into W (Delay value 3)
  119. MOVWF DELVAL3 ; Store into DELVAL3 location
  120. REPEAT MOVLW 0XFF ; Move Literal value 0xFF into W
  121. MOVWF DELVAL2 ; Move contents of W (FF) into DELVAL2
  122.  
  123. HERE NOP ; No Operation
  124. DECF DELVAL2,F ; Decrement contents of DELVAL2
  125. BNZ HERE ; If has not reached zero branch to location HERE
  126. DECF DELVAL1,F ; Decrement contents of DELVAL1
  127. BNZ REPEAT ; If not zero branch to location REPEAT
  128. DECF DELVAL3 ; Decrement contents of DELVAL3
  129. BNZ HERE ; If not zero go to location HERE
  130. RETURN
  131.  
  132. ;******************************************************************************
  133. ; End of program
  134.  
  135. END ; End Directive
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement