Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #INCLUDE "P16F84A.INC"
- __CONFIG _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF
- ERRORLEVEL -302
- ;----------------------------------------------------------
- ; variable declaration
- COUNTERA EQU H'10'
- COUNTERB EQU H'11'
- COUNTER EQU H'12'
- CONFIG_ADDR EQU H'13'
- VAL EQU H'14'
- ORG 0x00
- GOTO START
- ORG 0x04
- GOTO ON_INT
- START
- ;----------------------------------------------------------
- ; register configurations
- ;----------I/O Configurations------------------------------
- BSF STATUS, RP0
- MOVLW 0x00
- MOVWF TRISA
- MOVLW B'00000001'
- MOVWF TRISB
- ;----------End of I/O Configurations-----------------------
- ;----------Counter Configurations--------------------------
- MOVLW 0x07
- MOVWF OPTION_REG
- ;----------End of Counter Configurations-------------------
- ;----------Interrupt Configurations------------------------
- BCF STATUS, RP0
- BSF INTCON, GIE
- BSF INTCON, INTE
- ;BSF STATUS, RP0
- ;----------End of Interrupt Configurations-----------------
- ;----------General Initialization--------------------------
- CLRF PORTA
- CLRF PORTB
- ;----------End of General Initialization-------------------
- RESTART ; start of the counter, initializes
- MOVLW 0x00 ; the port A to the first two values to
- MOVWF PORTA ; display
- CALL DELAY
- MOVLW 0x01
- MOVWF COUNTER
- COUNT
- ;---------------------------------------------------------
- ; loop of the program
- MOVF COUNTER, W ; the counter decrements and will be displayed
- MOVWF PORTA ; to the port A
- CALL DELAY
- INCF COUNTER, F
- MOVF COUNTER, W
- XORLW 0x0A ; once it reaches A... not 9 (since i need to display 9)
- BTFSS STATUS, Z ; skip the count and restart
- GOTO COUNT
- GOTO RESTART
- DELAY
- ;---------------------------------------------------------
- ; create a delay
- MOVLW D'1'
- MOVWF COUNTERA
- LOOPA
- CALL DELAYA
- DECFSZ COUNTERA, 1
- GOTO LOOPA
- RETLW 0x00
- DELAYA
- MOVLW D'15'
- MOVWF COUNTERB
- LOOPB
- CALL DELAYB
- DECFSZ COUNTERB, 1
- GOTO LOOPB
- RETLW 0x00
- DELAYB
- CLRF TMR0
- BCF INTCON, T0IF
- LOOPC
- BTFSS INTCON, T0IF
- GOTO LOOPC
- RETLW 0x00
- ON_INT
- BSF PORTB, 1
- BCF INTCON, INTF
- ON_STORE_DATA
- ; EEPROM initialization
- BCF STATUS, RP0
- CLRF EEADR
- CLRF EEDATA
- MOVLW 0x00
- MOVWF CONFIG_ADDR
- MOVWF EEADR
- MOVF COUNTER, W ; put the value of the counter to working register
- MOVWF EEDATA ; then put the value to the EEPROM Data
- BSF STATUS, RP0
- BCF INTCON, GIE
- BSF EECON1, WREN ; write the data to the EEPROM
- MOVLW 0x55 ; according to the data sheet
- MOVWF EECON2
- MOVLW 0xAA
- MOVWF EECON2
- BSF EECON1, WR
- BSF INTCON, GIE
- ; verify the data after storing it
- ON_VERIFY_DATA
- BCF STATUS, RP0
- MOVLW 0x00 ; initialize the address where the
- MOVWF EEADR ; EEPROM will read (address 0x00)
- BSF STATUS, RP0
- BCF EECON1, WREN
- BCF EECON1, WR
- BSF EECON1, RD
- BCF STATUS, RP0
- MOVF EEDATA, W
- MOVWF VAL
- RRF VAL, F ; rotate the value of the VAL variable
- RRF VAL, F ; 4 times to produce the output to the
- RRF VAL, F ; 4 most significant bits
- RRF VAL, F
- RRF VAL, F
- MOVF VAL, W
- MOVWF PORTB
- INT_LOOP ; stops the execution of the countdown
- MOVF COUNTER, W ; by looping until the switch is
- MOVWF PORTA ; turned on again
- BTFSC PORTB, 0
- GOTO COUNT
- GOTO ON_INT
- END
Advertisement
Add Comment
Please, Sign In to add comment