1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| ;====================================================================
; Main.asm file generated by New Project wizard
;
; Created: Sat Jul 15 2017
; Processor: PIC16F84A
; Compiler: MPASM (Proteus)
;====================================================================
;====================================================================
; DEFINITIONS
;====================================================================
#include p16f84a.inc ; Include register definition file
;====================================================================
; VARIABLES
;====================================================================
CBLOCK 0x0C
d1
d2
d3
incr : 0 ; increment variable
ENDC
;====================================================================
; RESET and INTERRUPT VECTORS
;====================================================================
; Reset Vector
RST code 0x0
goto Start
;====================================================================
; CODE SEGMENT
;====================================================================
PGM code
Start
; Write your code here
bsf STATUS,5 ; go to page 1
movlw 0x00 ; W= '0000 0000'
movwf TRISB ; Makes PORTB output (connected to LEDs)
movlw 0xFF ; W= '1111 1111'
movwf TRISA ; Makes PORTA input (connected to switches)
bcf STATUS,5 ; go back to page 0
Reset clrf PORTB ; PORTB = '0000 0000' -> All LEDs off
clrf incr ; incr = 0
Loop btfss PORTA,0 ; Read RA0 (SW1), test RA0 value and skip if '1'
goto Reset ; go back to Reset
movlw 0x03 ; W= 03
movwf PCLATH ; PCLATH = 03
movf incr, W ; incr = W
call Pattern ; call Pattern
movwf PORTB ; makes PORTB
btfsc PORTA,1 ; Read RA1 (SW2), test RA1 value and skip if '0'
call Delay ; call Delay
incf incr, f ; increment incr, incr = incr + 1
goto TestSW2 ; go to TestSW2
TestSW2 btfsc PORTA,1 ; Read RA1 (SW2), test RA1 value and skip if '0'
goto Loop ;if yes, go back to Loop
LoopSW2 clrf PORTB ; PORTB = '0000 0000' -> All LEDs off
movlw 0x10 ; W= '0001 0000'
addwf incr, W ; incr = W
call Pattern ; call Pattern
movwf PORTB ; makes PORTB
call Delay ; call Delay
incf incr, f ; increment incr, incr = incr + 1
goto TestSW2 ; go back to TestSW2
Delay movlw 0x37
movwf d3
movlw 0x36
movwf d2
movlw 0x37
movwf d1
decfsz d1,f
goto $-1
decfsz d2,f
goto $-5
decfsz d3,f
goto $-9
return
ORG 0x300
Pattern
addwf PCL,F ; Add W to PCL, PCL = PCL + W
retlw 0x81
retlw 0x42
retlw 0x24
retlw 0x18
retlw 0x24
retlw 0x42
retlw 0x81
retlw 0x78
retlw 0xC3
retlw 0xE7
retlw 0xFF
retlw 0xE7
retlw 0xC3
retlw 0x81
retlw 0x00
retlw 0xFF
retlw 0x00
retlw 0xFF
retlw 0x7E
retlw 0x3C
retlw 0x18
retlw 0x3C
retlw 0x7E
;====================================================================
END |
Partager