Society of Robots - Robot Forum
Software => Software => Topic started by: winnie66 on January 23, 2010, 09:22:36 PM
-
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
-
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 (http://www.gooligum.com.au/tut_baseline.html)
-
Thank you very much. It is very helpful.
-
You are welcome and have fun with your PIC.