pic16f84a, security access control

Thread Starter

Pooja Goel

Joined Apr 26, 2010
6
Hi
i m new to this site and dont know where to post my questions.
could u please help me with the debugging of a code of pic16f84a.

thanks in advance
m attaching my code
 

Attachments

Last edited:

retched

Joined Dec 5, 2009
5,207
OPs Code out of .doc file and tagged:

Rich (BB code):
************************** SECURITY ACCESS CONTROL SYSTEM BY MITESH SHAH *******************
PROCESSOR       16F84A

	ORG     RAM

DEL0    EQU     RAM+0
DEL1    EQU     RAM+1
DEL10   EQU     RAM+2
SCANLN  EQU     RAM+3
RETVAL  EQU     RAM+4
RETLN   EQU     RAM+5
KEY     EQU     RAM+6
SCANKEY EQU     RAM+7
NEWKEY  EQU     RAM+8

NCODE0  EQU     RAM+0BH
NCODE1  EQU     RAM+0CH
NCODE2  EQU     RAM+0DH
NCODE3  EQU     RAM+0EH
NCODE4  EQU     RAM+0FH
NCODE5  EQU     RAM+10H

TRIES   EQU     RAM+11H

;ARM     EQU     RAM+12H

;LAST RAM LOCATATION = RAM + 23H


RDEEPROM:
        BSF     STATUS,RP0
        BSF     EECON1,RD
        BCF     STATUS,RP0

        RETURN

WREEPROM:

        BCF     INTCON,GIE      ;DISABLE INTS
        BSF     STATUS,RP0      ;BANK 1
        
	
        ;WRITE SEQUENCE

        MOVLW   55H
        MOVWF   EECON2
        MOVLW   0AAH
        BSF     EECON1,WR        ;BEGIN WRITE

WAITWR:
        BTFSC   EECON1,WR
        GOTO    WAITWR          

        BCF     STATUS,RP0      ;BANK 0
        BSF     INTCON,GIE      ;REENABLE INTS

        RETURN

NOSIG:
        
        CLRF    EEADR
        MOVLW   1
        MOVWF   EEDATA
WRCOD:
        
       CALL    WREEPROM
        INCF    EEDATA
        INCF    EEADR
        MOVLW   6
        SUBWF   EEADR,W
        JNZ     WRCOD

        ;CODE WRITTEN, WRITE SIGNATURE

        MOVLW   0AAH
        MOVWF   EEDATA
        CALL    WREEPROM
        INCF    EEADR

        MOVLW   055H
        MOVWF   EEDATA
        CALL    WREEPROM
        INCF    EEADR

        MOVLW   0CCH
        MOVWF   EEDATA
        CALL    WREEPROM

        RETURN

;============================================
; BEEP
; BEEPS 50MS
;============================================
BEEP:
        BSF     PORTA,2

        MOVLW   .5
        MOVWF   DEL10
        CALL    DELAY10
        BCF     PORTA,2

        RETURN

;BEE:
        BSF     PORTA,3
        MOVLW   .5
        MOVWF   DEL10
        CALL    DELAY10
        BCF     PORTA,3

        RETURN



;============================================
; DELAY10
; DELAYS DEL10 X 10MS
;============================================
DELAY10:
        ;DELAYLOOP 10 MS
        MOVLW   .40
        MOVWF   DEL1
DEC250U:
        ;DELAYLOOP 250 US
        MOVLW   .83
        MOVWF   DEL0
DEC1U:
        DECFSZ  DEL0
        GOTO    DEC1U

        DECFSZ  DEL1
        GOTO    DEC250U

        DECFSZ  DEL10
        GOTO    DELAY10

        RETURN
;============================================
DELAY   MACRO   DLY00
        MOVLW   DLY00
        MOVWF   DEL10
        CALL    DELAY10
        ENDM

SCANKEYBOARD:

        

        MOVLW   0
        MOVWF   PORTB
        CLRF    SCANLN
        BSF     PORTB,0
        NOP
        MOVF    PORTB,W
        ANDLW   B'01111000'
        JNZ     RETL
        INCF    SCANLN
        BSF     PORTB,1
        NOP
        MOVF    PORTB,W
        ANDLW   B'01111000'
        BSF     PORTB,2
        NOP
        MOVF    PORTB,W
        ANDLW   B'01111000'
        JNZ     RETL
        GOTO    NOKEYP          ;NO KEYPRESS

        ;SCANLINE FOUND, FIND RETURNLINE
RETL:
        CLRF    RETLN
        MOVF    PORTB,W
        MOVWF   RETVAL
        RRF     RETVAL
        RRF     RETVAL
        RRF     RETVAL
NXTRL:
        BCF     STATUS,CARRY
        RRF     RETVAL
        JC      KEYFOUND
        INCF    RETLN
        MOVLW   4
        SUBWF   RETLN,W
        JNZ     NXTRL

        ;NO (NEW) KEY PRESSED, EXIT
NOKEYP:
        MOVLW   NOKEY
        MOVWF   SCANKEY
        RETURN


GETKEY:
        CALL    SCANKEYBOARD
        MOVF    SCANKEY,W
        MOVWF   KEY
        MOVLW   .2
        MOVWF   DEL10
        CALL    DELAY           ;DELAY 20MS
        CALL    SCANKEYBOARD
        MOVF    SCANKEY,W
        SUBWF   KEY,W
        JNZ     GETKEY

       
        MOVLW   NOKEY
        SUBWF   KEY,W
        JNZ     EXITKEY
        MOVLW   1
        MOVWF   NEWKEY          ;NEXT KEY IS NEW
        GOTO    PKEY

EXITKEY:
        MOVLW   1
        SUBWF   NEWKEY,W
        JNZ     PKEY
        CLRF    NEWKEY
        RETURN

PKEY:   ;EXIT NOKEY
        MOVLW   NOKEY
        MOVWF   KEY
        RETURN

READKEY:
        CALL    GETKEY
        MOVLW   NOKEY
        SUBWF   KEY,W
        JZ      READKEY
        CALL    BEEP

        RETURN


START:
        CALL    INIT
        CALL    BEEP

RDKEY:
        CALL    READKEY         ;WAIT FOR KEY

        ;KEY PRESSED

        MOVLW   STERRETJE
        JNZ     RDKEY

        ; '*' PRESSED

NXKEY0:
        CALL    READKEY

        ;FIND OUT IF SECOND KEY IS A NUMBER, '*' OR '#'

        MOVLW   STERRETJE
        JZ      DEACTIVATE      ;'**' PRESSED, DEACTIVATE OUPUT, RESTART INPUT

        MOVLW   HEKJE
        SUBWF   KEY,W
        JZ      GETCODE         ;'*#' GOTO NEW CODE INPUT

        

        MOVLW   6
        MOVWF   DIGIT         
        MOVLW   1
        CLRF    EEADR           
RDEE:
        CALL    RDEEPROM
        MOVF    EEDATA,W
        SUBWF   KEY,W           
        JZ      EQ00
        CLRF    MATCH
EQ00:
        DECFSZ  DIGIT
        GOTO    NXTDG00

      
        BTFSS   MATCH,0
        GOTO    NOMATCH0          

        ;CODES MATCH, SET OUTPUTS
        CLRF    TRIES
        BSF     PORTA,0         
        BCF     PORTA,3        


        ;PULSE 1 SEC
        ;BEEP 1 SEC
        BSF     PORTA,2
        BSF     PORTA,1         ;SET PULSE
       DELAY    40000
        BCF     PORTA,1
        BCF     PORTA,2

        GOTO    RDKEY

DEACTIVATE:
        BCF     PORTA,0         ;DEACTIVATE OUTPUT
        ;BSF     PORTA,3         ;LED OFF
        GOTO    NXKEY0

NXTDG00:
        CALL    READKEY         ;WAIT FOR KEY

        ;KEY PRESSED
        MOVLW   STERRETJE
        SUBWF   KEY,W
        JZ      NXKEY0         

        MOVLW   HEKJE
        SUBWF   KEY,W

        ;DIGIT PRESSED
        INCF    EEADR
        GOTO    RDEE

NOMATCH0:
        ;WRONG ACCESCODE ENTRY
        INCF    TRIES
        MOVLW   4
        JNZ     NOMATCH

        ;FOUR TIMES MISMATCH IN A ROW
        ;ALARM FOR 1 MINUTE
        MOVLW   .60
        MOVWF   DIGIT

ALARM:
        CALL    BEEP            ;50MS
        DELAY   .15            ;150MS
        CALL    BEEP            ;50
        DELAY   .15            ;150
        CALL    BEEP            ;50
        DELAY   .55            ;550MS

        DECFSZ  DIGIT
        GOTO    ALARM
        GOTO    RDKEY

GETCODE:
        ;'*#' PRESSED, GET NEW ACCESCODE
       

        OVLW   1
        MOVWF   MATCH
        MOVLW   6
        MOVWF   DIGIT
        CLRF    EEADR
 	
        ;READ DIGIT AND VERIFY
GTDG00:
        CALL    READKEY         ;WAIT FOR KEY
        MOVLW   STERRETJE
        SUBWF   KEY,W
        JZ      NXKEY0          ;'*' PRESSED, RESTART INPUT

        MOVLW   HEKJE
        SUBWF   KEY,W
        JZ      NOMATCH         ;ERROR IN INPUT

    
        CALL    RDEEPROM
        MOVF    KEY,W
        SUBWF   EEDATA
        JZ      MATCH00
        CLRF    MATCH           ;MISMATCH IN INPUT
MATCH00:
        INCF    EEADR
        DECFSZ  DIGIT
        GOTO    GTDG00          ;READ NEXT


        ;READ AND SAVE NEW ACCESCODE

        MOVLW   6
        MOVWF   DIGIT
        MOVLW   NCODE0
        MOVWF   FSR            
	


STORE00:
        
	MOVF    INDF,W
        MOVWF   EEDATA
        CALL    WREEPROM

        INCF    FSR
        INCF    EEADR
        GOTO    STORE00


        GOTO    RDKEY           ;NEW CODE STORED IN EEPROM, RESTART INPUT

;============================================
; EEPROM DEFINITION
;============================================
        ORG     2100H

        DE      0,0,0,0,0,0,0,0,0


        END
Pooja, What compiler are you using? Have you set your CONFIG bits, and is this the entire code?
 

Thread Starter

Pooja Goel

Joined Apr 26, 2010
6
Hello,

I moved your post to its own thread.

Can you clearify your question?

The code can be posted using the code tags.
http://forum.allaboutcircuits.com/showthread.php?t=37117

Bertus
when m compiling this code with mplab build fails
so the problem is of compiling

MPLINK 3.80.02, Linker
Copyright (c) 2004 Microchip Technology Inc.
Error - section '.org_0' can not fit the absolute section. Section '.org_0' start=0x00000000, length=0x00000036
Errors : 1
BUILD FAILED: Tue Apr 27 01:22:40 2010
 
Last edited:

bertus

Joined Apr 5, 2008
22,994
Hello,

As retched said where is the configuration line?
Also the include line for the pic is missing.

See the attached PDF for info on the config.

Bertus
 

Attachments

Thread Starter

Pooja Goel

Joined Apr 26, 2010
6
hi i used the code templates.there is problem in this code are instructions jz jnz and jc .
can i use them with pic16f84a if not what should i use them instead or what should be the subroutine for them
 

Markd77

Joined Sep 7, 2009
2,806
There are no jz, jnz in the template.

you probably want to cahnge this line :
__CONFIG _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

to :

__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _RC_OSC

and change _RC_OSC to whatever you are using.

Rich (BB code):
;**********************************************************************
;   This file is a basic code template for assembly code generation   *
;   on the PICmicro PIC16F84A. This file contains the basic code      *
;   building blocks to build upon.                                    *  
;                                                                     *
;   If interrupts are not used all code presented between the ORG     *
;   0x004 directive and the label main can be removed. In addition    *
;   the variable assignments for 'w_temp' and 'status_temp' can       *
;   be removed.                                                       *                        
;                                                                     *
;   Refer to the MPASM User's Guide for additional information on     *
;   features of the assembler (Document DS33014).                     *
;                                                                     *
;   Refer to the respective PICmicro data sheet for additional        *
;   information on the instruction set.                               *
;                                                                     *
;   Template file assembled with MPLAB V4.00.00 and MPASM V2.20.12.   *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Filename:        xxx.asm                                           *
;    Date:                                                            *
;    File Version:                                                    *
;                                                                     *
;    Author:                                                          *
;    Company:                                                         *
;                                                                     * 
;                                                                     *
;**********************************************************************
;                                                                     *
;    Files required:                                                  *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************
;                                                                     *
;    Notes:                                                           *
;                                                                     *
;                                                                     *
;                                                                     *
;                                                                     *
;**********************************************************************


    list      p=16F84A            ; list directive to define processor
    #include <p16F84A.inc>        ; processor specific variable definitions

    __CONFIG   _CP_OFF & _WDT_ON & _PWRTE_ON & _RC_OSC

; '__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
w_temp        EQU     0x0C        ; variable used for context saving 
status_temp   EQU     0x0D        ; variable used for context saving








;**********************************************************************
        ORG     0x000             ; processor reset vector
          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


; isr code can go here or be located as a call subroutine elsewhere


        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

; remaining code goes here










        END                     ; directive 'end of program'
 

rjenkins

Joined Nov 6, 2005
1,013
The instructions you mention would in practice use the PIC btfsc or btfss instructions (Bit Test Flag, Skip if Clear / Skip if Set).

The 'flag' being tested would be the appropriate bit in the status register.

Those skip instructions only skip (bypass) one instruction, so it's normal to follow them with a goto if you need to jump to a different part of the program.

(so you use the btfsx instruction that does NOT skip if you want to take the goto jump).
 
Top