help!stacking problem with 16f873

Discussion in 'Programmer's Corner' started by afologic, Sep 16, 2010.

  1. afologic

    Thread Starter New Member

    Sep 13, 2010
    1
    0
    hey! wiz family am a new bie in da house please i need immediate help on this sample project i wrote.am having a stacking error when i simulate using proteus please wiz kids in tha house have mercy for an humble learner needs help.you could highlight why and where the problem is and send to ma box o wiz family efizyus@yahoo.com

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

    __CONFIG _CP_OFF & _WDT_OFF & _BODEN_OFF & _PWRTE_ON & _RC_OSC & _WRT_OFF & _LVP_ON & _CPD_OFF

    ; '__CONFIG' directive is used to embed configuration data within .asm file.
    ; The labels following the directive are located in the respective .inc file.
    ; See respective data sheet for additional information on configuration word.

    ;***** VARIABLE DEFINITIONS (examples)

    ; example of using Shared Uninitialized Data Section
    INT_VAR UDATA_SHR 0x71
    w_temp RES 1 ; variable used for context saving
    status_temp RES 1 ; variable used for context saving
    pclath_temp RES 1 ; variable used for context saving


    ; creating copies of interupt context saving variables in bank1
    INT_VAR1 UDATA_SHR 0xF1
    w_temp1 RES 1 ; variable used for context saving


    ; example of using Uninitialized Data Section
    TEMP_VAR UDATA_SHR 0x20 ; explicit address specified is not required
    temp_count RES 1 ; temporary variable (example)
    CBLOCK .14
    COUNT
    VALUE_L
    VALUE_H
    ENDC

    ;**********************************************************************
    RESET_VECTOR CODE 0x0000 ; processor reset vector
    nop ; nop for icd
    pagesel start
    goto start ; go to beginning of program


    INT_VECTOR CODE 0x0004 ; interrupt vector location

    INTERRUPT

    movwf w_temp ; save off current W register contents
    movf STATUS,w ; move status register into W register
    bcf STATUS,RP0 ; select bank0
    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

    bcf STATUS,RP0 ; select bank0
    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_PROG CODE

    start
    BANKSEL TRISA
    CLRF TRISA
    MOVLW B'00000011'
    MOVWF TRISA
    CLRF TRISB
    CLRF TRISC



    PWM_INIT:
    BANKSEL CMCON
    BCF CMCON,7 ;SWITCH OFF COMPARATOR
    BANKSEL ADCON1
    MOVLW 00000110;MAKE PORTA ALL DIGITAL
    MOVWF ADCON1
    BANKSEL INTCON
    BSF INTCON,7
    BSF INTCON,6
    BANKSEL PR2
    MOVLW .249
    MOVWF PR2
    BANKSEL T2CON
    MOVLW B'00000101'
    MOVWF T2CON
    BANKSEL TRISB
    BCF TRISC,2
    BANKSEL CCP1CON
    CLRF CCP1CON
    MOVLW B'00001100'
    MOVWF CCP1CON



    READ_INPUT:
    H_INPUT
    BTFSS PORTA,0
    GOTO SPEED_H
    L_INPUT
    BTFSS PORTA,1
    GOTO SPEED_L
    GOTO READ_INPUT

    SPEED_H:
    INCF COUNT,1
    MOVF COUNT,0
    SUBLW .10
    BTFSC STATUS,2
    GOTO DISPLAY_F
    UPDATE_PWM:
    MOVF COUNT,0
    CALL TABLE
    BANKSEL CCPR1L
    MOVWF CCPR1L
    UPDATE_DISPLAY
    MOVF COUNT,0
    CALL TABLE_2
    MOVWF PORTB
    GOTO READ_INPUT

    DISPLAY_F:
    BTFSS PORTA,1
    GOTO L_INPUT
    MOVLW B'11100010'
    MOVWF PORTB
    GOTO DISPLAY_F
    SPEED_L:
    DECF COUNT,1
    MOVF COUNT,0
    SUBLW .0
    BTFSC STATUS,2
    GOTO UPDATE_DOWNDISPLAY
    MOVF COUNT,0
    UPDATE_PWM4LOWSPEED:
    CALL TABLE
    BANKSEL CCPR1L
    MOVWF CCPR1L
    UPDATE_DOWNDISPLAY
    MOVF COUNT,0
    CALL TABLE_2
    MOVWF PORTB
    GOTO READ_INPUT
    DISPLAY_N:
    BTFSC PORTA,1
    GOTO H_INPUT
    MOVLW B'11011100'
    MOVWF PORTB
    GOTO DISPLAY_N

    TABLE
    ADDWF PCL,1
    RETLW B'11100010' ;F
    RETLW B'11110010' ;1
    RETLW B'01001000' ;2
    RETLW B'01100000' ;3
    RETLW B'00110010' ;4
    RETLW B'00100100' ;5
    RETLW B'00000100' ;6
    RETLW B'11110000' ;7
    RETLW B'00000000' ;8
    RETLW B'00100000' ;9
    TABLE_2
    ADDWF PCL,1
    RETLW B'00011001' ;0
    RETLW B'00110010' ;1
    RETLW B'01001011' ;2
    RETLW B'01100100' ;3
    RETLW B'01111101' ;4
    RETLW B'10010110' ;5
    RETLW B'10101111' ;6
    RETLW B'11001000' ;7
    RETLW B'11100001' ;8
    RETLW B'11111010' ;9


    nop ; code starts here (example)

    ; remaining code goes here

    goto $

    END ; directive 'end of program'
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    I'm guessing that you are calling the tables with a value in W greater than 9. Try putting breakpoints at the addwf points and see if W is ever 10 or above.
     
Loading...