6

Click here to load reader

Micro Assignment Coding (y)

Embed Size (px)

DESCRIPTION

coding

Citation preview

Page 1: Micro Assignment Coding (y)

; ***** Program Header *********************************************** LIST P=16F877a, #include <p16f877a.inc> __CONFIG 0x3D72 ; HS MODE,WDT OFF, BOREN; ***** Definitions **************************************************BANK_0 EQU 0x00BANK_1 EQU 0x80BANK_2 EQU 0x100BANK_3 EQU 0x180PortB equ 0x06 ; Port BSTATUS equ 0x03 ; Status RegisterCount equ 0x20; ***** Main Program *********************************************

Org 0movlw B'00011111' ; prepare data for TRISB

; (Pin5 to Pin7) is output while Pin0 to Pin4 is the input

BANKSEL BANK_1 ; "activate" Bank 1movwf TRISB ; copy W to TRISB

clrf PortB ;LEDforward movlw B'00100000' ;

BankSelBANK_0 ;movwf PortB ;

Delay_1 movlw D'255' ;movwf Count ;

Delay1 movlw D'255' ;Delay2 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay2 ;decfsz Count,F ;goto Delay1 ;

Delay_3 movlw D'255' ;movwf Count ;

Delay3 movlw D'255' ;Delay4 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay4 ;decfsz Count,F ;goto Delay3 ;

Delay_5 movlw D'255' ;

Page 2: Micro Assignment Coding (y)

movwf Count ;Delay5 movlw D'255' ;Delay6 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay6 ;decfsz Count,F ;goto Delay5 ;

movlw B'01000000' ;BankSelBANK_0movwf PortB ;

Delay_7 movlw D'255' ;movwf Count ;

Delay7 movlw D'255' ;Delay8 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay8 ;decfsz Count,F ;goto Delay7 ;

Delay_9 movlw D'255' ;movwf Count ;

Delay9 movlw D'255' ;Delay10 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay10 ;decfsz Count,F ;goto Delay9 ;

Delay_11 movlw D'255' ;movwf Count ;

Delay11 movlw D'255' ;Delay12 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay12 ;movlw B'10000000' ;BankSel BANK_0movwf PortB ;

Delay_13 movlw D'255' ;movwf Count ;

Page 3: Micro Assignment Coding (y)

Delay13 movlw D'255' ;Delay14 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay14 ;decfsz Count,F ;goto Delay13 ;

Delay_15 movlw D'255' ;movwf Count ;

Delay15 movlw D'255' ;Delay16 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay16 ;decfsz Count,F ;goto Delay15 ;

Delay_17 movlw D'255' ;movwf Count ;

Delay17 movlw D'255' ;Delay18 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay18 ;

btfsc PortB, 0 ; goto LEDforward ;LEDbackward movlw B'10000000' ;

BankSel BANK_0 ;movwf PortB ;

Delay_19 movlw D'255' ;movwf Count ;

Delay19 movlw D'255' ;Delay20 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay20 ;decfsz Count,F ;goto Delay19 ;

Delay_21 movlw D'255' ;movwf Count ;

Delay21 movlw D'255' ;Delay22 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay22 ;

Page 4: Micro Assignment Coding (y)

decfsz Count,F ;goto Delay21 ;

Delay_23 movlw D'255' ;movwf Count ;

Delay23 movlw D'255' ;Delay24 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay24 ;decfsz Count,F ;goto Delay23 ;

movlw B'01000000' ;BankSelBANK_0 ;movwf PortB ;

Delay_25 movlw D'255' ;movwf Count ;

Delay25 movlw D'255' ;Delay26 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay26 ;decfsz Count,F ;goto Delay25 ;

Delay_27 movlw D'255' ;movwf Count ;

Delay27 movlw D'255' ;Delay28 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay28 ;decfsz Count,F ;goto Delay27 ;

Delay_29 movlw D'255' ;movwf Count ;

Delay29 movlw D'255' ;Delay30 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay30 ;movlw B'00100000' ;BankSelBANK_0movwf PortB ;

Page 5: Micro Assignment Coding (y)

Delay_31 movlw D'255' ;movwf Count ;

Delay31 movlw D'255' ;Delay32 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay32 ;decfsz Count,F ;goto Delay31 ;

Delay_33 movlw D'255' ;movwf Count ;

Delay33 movlw D'255' ;Delay34 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay34 ;decfsz Count,F ;goto Delay33 ;

Delay_35 movlw D'255' ;movwf Count ;

Delay35 movlw D'255' ;Delay36 nop ;

addlw -1 ;btfss STATUS,Z ;goto Delay36 ;

goto LEDbackward ;

End