go_away

Author Topic: This simple program keeps looping. There is no loop instruction.  (Read 1055 times)

0 Members and 1 Guest are viewing this topic.

Offline winnie66Topic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
chips: 16f684. Program is as following:

 list      r=dec
    include   "p16f684.inc"
    include    "asmDelay.inc"
    ; set configuration word.
   __CONFIG   _FCMEN_OFF & _IESO_OFF & _BOD_OFF & _CPD_OFF & _CP_OFF & _MCLRE_OFF & _PWRTE_OFF  & _WDT_OFF & _INTOSCIO

    CBLOCK  0x020
  
    ENDC
    
    PAGE
    

   org   0
    movlw 7                  ; turn off comparators
    movwf CMCON0

    bsf   STATUS,RP0            ; enter bank 1
    clrf ANSEL ^ 0x080      ; all ports are digital
    clrf TRISC ^ 0x080      ; teach all of PORTC to be outputs
    movlw b'11111111'
    movwf TRISA ^ 0x080
    bcf STATUS, RP0         ; enter bank0
  
    
    nop
    movlw b'100000'          ;turn motor forword
    movwf PORTC
    Dlay 60000          ;Delay 0.06seconds
    clrf PORTC
    Dlay 3000000
    
    nop
    movlw b'010000'          ;turn arm motor reversed
    movwf PORTC
    Dlay 100000          ;Delay 0.1seconds
    clrf PORTC
    Dlay 3000000


 end


thanks

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,938
  • Helpful? 98
Re: This simple program keeps looping. There is no loop instruction.
« Reply #1 on: January 23, 2010, 11:44:37 PM »
Yep, that's exactly what I would expect.

The 'end' statement is only for the compiler to know there is no more code in the file to look at and does nothing for the code running in the PIC. After the last Dlay 30000000 line the PIC executes the next instruction in memory and since the program code space was erased this means that the next instruction is a 'nop'. So is the instruction after that and after that until the program counter gets to the end of the code space. The program counter then wraps from the highest address to zero and starts executing the code from the beginning. Thus it keeps looping.

Add these lines before the 'end' statement:

wait_here
    goto wait_here     ; loop forever

Or this line

    goto $                ; loop forever

Both will keep looping to the same line and thus appear to have halted.

Here is a good tutorial on PIC code:
http://www.gooligum.com.au/tut_baseline.html
« Last Edit: January 24, 2010, 09:52:52 AM by waltr »

Offline winnie66Topic starter

  • Beginner
  • *
  • Posts: 3
  • Helpful? 0
Re: This simple program keeps looping. There is no loop instruction.
« Reply #2 on: January 24, 2010, 08:38:48 PM »

Thank you very much. It is very helpful.

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,938
  • Helpful? 98
Re: This simple program keeps looping. There is no loop instruction.
« Reply #3 on: January 24, 2010, 09:12:08 PM »
You are welcome and have fun with your PIC.

 


Get Your Ad Here