;**********************************************************************
; This file is a basic code template for assembly code generation *
; on the PIC16F877A. This file contains the basic code *
; building blocks to build upon. *
; *
; Refer to the MPASM User's Guide for additional information on *
; features of the assembler (Document DS33014). *
; *
; Refer to the respective PIC data sheet for additional *
; information on the instruction set. *
; *
;**********************************************************************
; *
; Filename: xxx.asm *
; Date: *
; File Version: *
; *
; Author: *
; Company: *
; *
; *
;**********************************************************************
; *
; Files Required: P16F877A.INC *
; *
;**********************************************************************
; *
; Notes: *
; *
;**********************************************************************
list p=16f877A ; list directive to define processor
#include <p16f877A.inc> ; processor specific variable definitions
#DEFINE BANK0 BCF STATUS,RP0
#DEFINE BANK1 BSF STATUS,RP0
__CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_OFF & _RC_OSC & _WRT_OFF & _LVP_OFF & _CPD_OFF
ERRORLEVEL -302 ; Eliminate bank warning
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
CBLOCK 0x20
W_TEMP ; variable used for context saving
STATUS_TEMP ; variable used for context saving
PCLATH_TEMP ; variable used for context saving
TEMP1 ; For delay routine
TEMP2 ; For delay routine
TEMP3 ; For delay routine
TEMP4 ; For delay routine
ENDC
;**********************************************************************
ORG 0x000 ; processor reset vector
NOP ; nop required for icd
GOTO MAIN ; go to beginning of program
ORG 0x004 ; interrupt vector location
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,W ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF PCLATH,W ; move pclath register into w register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
; isr code can go here or be located as a call subroutine elsewhere
MOVF PCLATH_TEMP,W ; retrieve copy of PCLATH register
MOVWF PCLATH ; restore pre-isr PCLATH register contents
MOVF STATUS_TEMP,W ; retrieve copy of STATUS register
MOVWF STATUS ; restore pre-isr STATUS register contents
SWAPF W_TEMP,F
SWAPF W_TEMP,W ; restore pre-isr W register contents
RETFIE ; return from interrupt
;**********************************************************************
MAIN
BANK0
CLRF PORTA
CLRF PORTB
CLRF PORTC
CLRF PORTD
CLRF PORTE
BANK1
; 76543210 bit control
MOVLW B'00000000' ; All Output
MOVWF TRISA
; 76543210
MOVLW B'00000011' ; B0 and B1 as Input the rest is Output
MOVWF TRISB
; 76543210
MOVLW B'00000000' ; All Output
MOVWF TRISC
; 76543210
MOVLW B'00000000' ; All Output
MOVWF TRISD
; 76543210
MOVLW B'00000000' ; All Output
MOVWF TRISE
; 76543210
MOVLW B'10000000' ; PORTB pull-ups are disabled
MOVWF INTCON
BANK0
;**********************************************************************
LOOPING
; 76543210 bit control
MOVLW B'00000000' ; 0 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000001' ; 1 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000010' ; 2 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000011' ; 3 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000100' ; 4 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000101' ; 5 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000110' ; 6 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000111' ; 7 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00001000' ; 8 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00001001' ; 9 in BCD
MOVWF PORTD
CALL DELAY100M ; Call 100m delay
MOVLW B'00000000' ; 0 in BCD
MOVWF PORTD
; 76543210 bit control
MOVLW B'00000001'
MOVWF PORTA
MOVLW B'10000000'
MOVWF PORTB
CALL DELAY1S ; Call 1S delay
MOVLW B'00000010'
MOVWF PORTA
MOVLW B'01000000'
MOVWF PORTB
CALL DELAY1S ; Call 1S delay
MOVLW B'00000100'
MOVWF PORTA
MOVLW B'00100000'
MOVWF PORTB
CALL DELAY1S ; Call 1S delay
MOVLW B'00000000'
MOVWF PORTA
MOVLW B'00000000'
MOVWF PORTB
CALL DELAY1S ; Call 1S delay
BTFSC PORTB,0 ; Read Key in PORTB RB0
CALL FUNCTIONA
CALL FUNCTIONB
BTFSC PORTB,1 ; Read Key in PORTB RB1
CALL FUNCTIONC
CALL FUNCTIOND
GOTO LOOPING
;**********************************************************************
FUNCTIONA ; Make here your code
RETURN
;**********************************************************************
FUNCTIONB ; Make here your code
RETURN
;**********************************************************************
FUNCTIONC ; Make here your code
RETURN
;**********************************************************************
FUNCTIOND ; Make here your code
RETURN
;**********************************************************************
; Delay 100 mili routine
DELAY100M
MOVLW 0x1E
MOVWF TEMP1
MOVLW 0x4F
MOVWF TEMP2
DELAYLOOP
DECFSZ TEMP1, F
GOTO $+2
DECFSZ TEMP2, F
GOTO DELAYLOOP
GOTO $+1
NOP
RETURN
;**********************************************************************
DELAY1S
MOVLW 0X07
MOVWF TEMP1
MOVLW 0X2F
MOVWF TEMP2
MOVLW 0X03
MOVWF TEMP3
DELAY1SLOOP
DECFSZ TEMP1, F
GOTO $+2
DECFSZ TEMP2, F
GOTO $+2
DECFSZ TEMP3, F
GOTO DELAY1SLOOP
GOTO $+1
GOTO $+1
GOTO $+1
RETURN
;**********************************************************************
END ; directive 'end of program'
;**********************************************************************