assembly - Stack overflow in Pic16F684 Microcontroller when using Lookup tables -



task develop program blink leds d7 d0.
i have develop solution blinks them once , have stack overflow.
i suspicious on lookup tables becouse previosly have faced error on last trisa configuration(commented now) pasting code.

    ;********************************************************************************* ; filename: pic_demonstration.asm -it should be! ; author:   alexander drabek ; date:     01.05.13 ; description:  assembler program pic16f684 turns on , off leds d7 d0 ;               delay of 0.5 second ;check if trisa reaching 4th , porta 8 leds. ;to report: ;1.separate pcl in bank1 , bank0 ;2.lookup table , undaestanding of options of code. ;3.we assuming work in bank0 ;4.overflow.     list     p=16f684       ; list directive define processor     #include <p16f684.inc>  ; processor specific variable definitions     __config  _cp_off & _wdt_off & _pwrte_on & _intrc_osc_noclkout & _mclre_off & _cpd_off ;****************************** assignment statements **************************** ;delay counters     count1 equ 20h  ; store count1 @ address 20h     count2 equ 21h  ; store count2 @ address 21h     normal equ 22h  ; store normal @ address 22h - responsible general loop(4 times change trisa)     count3 equ 26h ; counter make more delay  ;loops counters     porta_internal equ 23h       ;store porta_internal @ address 21h     count_led_number equ 24h    ; store count_led_number @ address 21h     count_trisa_number equ 25h  ; store count_trisa_number @ address 21h ;****************************** "start" of program ****************************** ; initial configuration  ;errorlevel -302 ; disable bank switch warning          org     0x000       ; processor reset vector         bcf     status,rp0  ; bank 0 selected         movlw   07h         ; set ra<2:0> digital ,          movwf   cmcon0      ; comparators turned off         bsf     status,rp0  ; bank 1 selected         clrf    ansel       ; digital i/o selected         movlw   b'00111111' ; move in w - 0x3f - set i/o pins digital inputs         movwf   trisa       ; configure i/o ports                clrf    intcon      ; disable interrupts, clear flags            bcf     status,rp0  ; bank 0 selected         clrf    porta       ; clear outputs ;********************************************************************************* ; load values counters .  again;reset value          movlw   b'11101010'         ; first load value of say, f0h in w register         movwf   count2      ; move count2 register         movlw   0x03;       ; first load value of say, f0h in w register         movwf   count3      ; move count2 register         movlw   b'00000100' ; load value 4, in w register         movwf   normal      ; move normal         movlw   b'00000010' ; first load value of say, 1 in w register         movwf   porta_internal  ; move porta_internal         movlw   b'00000000'     ; first load value of say, 1 in w register         movwf   count_led_number    ; move count2 register         movlw   b'00000000'         ; first load value of say, 1 in w register         movwf   count_trisa_number  ; move count2 register         goto start_loop  ;******************************************************************************** ;*********************************************************************************  lookup_porta                  movlw  low tableporta              addwf  count_led_number,0                                 movwf  pcl                 ; jump specified entry tableporta   retlw b'00000010'  ; sending high d7 -ok              retlw b'00000100'  ; sending high d6 -ok              retlw b'00000100'  ; sending high d5 -ok              retlw b'00100000'  ; sending high d4 -ok              retlw b'00000100'  ; sending high d3 -ok              retlw b'00010000'  ; sending high d2 -ok              retlw b'00100000'  ; sending high d1 -ok              retlw b'00010000'  ; sending high d0 -ok-------- lookup_trisa                  movlw  low tabletrisa               addwf count_trisa_number,0                              movwf  pcl                             ; jump specified entry   ;     retlw b'00111001'; 57    - overflow!       tabletrisa   retlw b'00011011'; 27-decimal    ; element 0 of lookup table              retlw b'00101011'; 43-decimal  ; element 1 of lookup table              retlw b'00001111'; 15-decimal          ; element 2 of lookup table                      ;it loading first 1 of eac lookup tables! ;********************************************************************************* start_loop           ;temporary solution overflow               bsf    status,rp0      ; bank 1 selected              movlw   b'00111001'        ; trisa d6 , d7              movwf  trisa              bcf    status, rp0 ; bank 0 selected              call   delay              call   lookup_porta  ; call table. -it should obtain address next memory cell porta config              movwf  porta       ;light diod!              call   delay       ; half second                               clrf   porta       ;  clear porta               incfsz count_led_number,1 ;increase led number! save variable!              call   delay              call lookup_porta  ; call table. -it should obtain address next memory cell porta config              movwf  porta       ;light diod!              call   delay       ; half second                               clrf   porta       ;  clear porta               incfsz count_led_number,1 ;end of temporary solution iternal_trisa_loop ;change trisa after 2 diods ,do till end of lookup table              call lookup_trisa  ; call table. -it should obtain address next memory cell trisa config              bsf  status,rp0    ;bank 1              movwf trisa        ;move config trisa              bcf status, rp0    ;reset bank 0               decfsz normal,1    ;decrease number of posible configuration in iteration value of 5 -not sure --it omit las 1 (option 4)              goto internal_loop_2diods ; blink 2 diods including delays              goto again ;   internal_loop_2diods  ;develop delay ! +trisa change              bcf    status, rp0 ;               call   delay              call lookup_porta  ; call table. -it should obtain address next memory cell porta config              movwf  porta       ;light diod!              call   delay       ; half second                               clrf   porta       ;  clear porta               incfsz count_led_number,1 ;increase led number! save variable!              decfsz porta_internal,1 ; should have value of 2 xd              goto internal_loop_2diods ; 1 repeat!              incfsz count_trisa_number,1 ;increase trisa config number              movlw  b'00000010'         ; first load value of say, 1 in w register              movwf  porta_internal  ; move count2 register              goto  iternal_trisa_loop      ;- loop forever - goto again ;********************************************************************************* ; delay subroutine ;********************************************************************************* ; generate delay period delay loop1   decfsz   count1,1   ; decrement count1 , skip next instruction if 0         goto     loop1      ; else loop loop1         decfsz   count2,1   ; decrement count2 , skip next instruction if 0         goto     loop1      ; else loop loop1         decfsz   count3,1   ; decrement count1 , skip next instruction if 0         goto     loop1      ; else loop loop1         movlw    0x03       ; reload second counter next iteration         movwf    count3     ; decrement count3 , skip next instruction if 0         movlw    0xf0       ; reload second counter next iteration         movwf    count2         return              ; else loop loop1  ;*********************************************************************************         end ;********************************************************************************* 


anyone know wrong? during debuging value each counter seems ok me.
have tried quite new in assembly programming.

your goto lookup table routine made wrong! set pclath before using computed goto. like:

lookup_porta             movlw  high tableporta         movwf  pclath         movlw  low tableporta         addwf  count_led_number,0                            movwf  pcl                 ; jump specified entry tableporta            retlw b'00000010'  ; sending high d7 -ok         retlw b'00000100'  ; sending high d6 -ok         ... 

and ensure table tableporta inside 256 byte page.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -