Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.
0 Members and 1 Guest are viewing this topic.
;*****Set up the Constants**** STATUS equ 03h ;Address of the STATUS registerTRISA equ 85h ;Address of the tristate register for port APORTA equ 05h ;Address of Port ACOUNT1 equ 08h ;First counter for our delay loopsCOUNT2 equ 09h ;Second counter for our delay loops ;****Set up the port**** bsf STATUS,5 ;Switch to Bank 1 movlw 00h ;Set the Port A pins movwf TRISA ;to output. bcf STATUS,5 ;Switch back to Bank 0 ;****Turn the LED on**** Start movlw 02h ;Turn the LED on by first putting movwf PORTA ;it into the w register and then ;on the port ;****Start of the delay loop 1**** Loop1 decfsz COUNT1,1 ;Subtract 1 from 255 goto Loop1 ;If COUNT is zero, carry on. decfsz COUNT2,1 ;Subtract 1 from 255 goto Loop1 ;Go back to the start of our loop. ;This delay counts down from ;255 to zero, 255 times;****Delay finished, now turn the LED off**** movlw 00h ;Turn the LED off by first putting movwf PORTA ;it into the w register and then on ;the port ;****Add another delay**** Loop2 decfsz COUNT1,1 ;This second loop keeps the goto Loop2 ;LED turned off long enough for decfsz COUNT2,1 ;us to see it turned off goto Loop2 ; ;****Now go back to the start of the program goto Start ;go back to Start and turn LED ;on again ;****End of the program**** end ;Needed by some compilers, ;and also just in case we miss ;the goto instruction.
;*****Set up the Constants**** LIST P=16F628, R=DEC ; Use the PIC16F628 and decimal system#include "P16F628.INC" ; Include header file__config _INTRC_OSC_NOCLKOUT & _LVP_OFF & _WDT_OFF & _PWRTE_ON & _BODEN_ONCBLOCK 0x20 ; Declare variable addresses starting at 0x20 COUNT1,COUNT2 ENDC ;****Set up the port**** MOVLW 0x07 MOVWF CMCONBSF STATUS,RP0 ;Switch to Bank 1MOVLW 0x1F MOVWF TRISAMOVLW 00h ;Set the Port B pinsMOVWF TRISB ;to output.BCF STATUS,RP0 ;Switch back to Bank 0 ;****Main**** Start BTFSC PORTA,0 FALSE RLF PORTB CALL delay GOTO Start TRUE RRF PORTB CALL delay GOTO Start ;****50ms delay****delay MOVLW 50 MOVWF COUNT1Outer MOVLW 200 MOVWF COUNT2Inner NOP NOP DECFSZ COUNT2,F GOTO Inner ; Inner Loop = 5uS DECFSZ COUNT1,F GOTO Outer RETURNEND
CORE-W0014: Halted due to PC incrementing over the Maximum PC address and wrapping back to Zero
fadeinMOVLW 0x01 MOVWF CCPR1L ; Put 1 into CCPR1L so it's not skipped straight awayINCFSZ CCPR1L ; Increase CCPR1LCALL pauseGOTO fadein ; skipped if CCPR1L is 0GOTO fadeout ; goes to fadeout if CCPR1L is = 0 fadeoutMOVLW 0xFF MOVWF CCPR1L ;Put 255 into CCPR1L so it's not skipped straight awayDECFSZ CCPR1L ; decrease CCPR1LCALL pause GOTO fadeout ; skipped if CCPR1L is 0GOTO fadein ; goes to fadein if CCPR1L is = 0
fadeinMOVLW 0x01 MOVWF CCPR1L ; Put 1 into CCPR1L so it's not skipped straight awayINCFSZ CCPR1L ; Increase CCPR1LCALL pauseGOTO fadein ; skipped if CCPR1L is 0GOTO fadeout ; goes to fadeout if CCPR1L is = 0
fadeinMOVLW 0x01 MOVWF CCPR1L ; Put 1 into CCPR1L so it's not skipped straight away fadein2 INCFSZ CCPR1L ; Increase CCPR1LGOTO fadein2 ; skipped if CCPR1L is 0GOTO fadeout ; goes to fadeout if CCPR1L is 0 fadeoutMOVLW 0xFF MOVWF CCPR1L ;Put 255 into CCPR1L so it's not skipped straight awayfadeout2 DECFSZ CCPR1L ; decrease CCPR1LGOTO fadeout2 ; skipped if CCPR1L is 0GOTO fadein ; goes to fadein if CCPR1L is 0
How are you determining that it is not decrementing when run on the PIC?
fadeinMOVLW 0x01 MOVWF CCPR1L ; Put 1 into CCPR1L so it's not skipped straight away fadein2 CALL pause ;20msINCFSZ CCPR1L ; Increase CCPR1LGOTO fadein2 ; skipped if CCPR1L is 0GOTO fadeout ; goes to fadeout if CCPR1L is 0 fadeoutMOVLW 0xFF MOVWF CCPR1L ;Put 255 into CCPR1L so it's not skipped straight awayfadeout2CALL pause ;20ms DECFSZ CCPR1L ; decrease CCPR1LGOTO fadeout2 ; skipped if CCPR1L is 0GOTO fadein
Loop INCF CCPR1L ;Increase duty cycle MOVF REG1,F ;Move CCPR1L value to REG1 for mathsLoop1 call pause ; pause... MOVLW 255 ;Move 255 to W SUBWF REG1,F ;Subtract W(255) with F BTFSC REG1,F ;if CCPR1L is 255, subtracting 255 will give us 0, so it skips, and goes to fadeout. GOTO Loop1 GOTO fadeoutfadeout CALL pause DECF CCPR1L GOTO fadeout GOTO Loop
Do you understand why?
fadein2 CALL pause ;20msINCFSZ CCPR1L ; Increase CCPR1LGOTO fadein2 ; skipped if CCPR1L is 0GOTO fadeout ; goes to fadeout if CCPR1L is 0
These are the most confusing instructions in the PIC
QuoteDo you understand why?each instruction takes very little time, 200ns in this case if i'm not mistaken, so 200ns+255 = 51 micro seconds, the human eye can't see it happening.
#include <pic.h> #include <HTC.h> __CONFIG(0x3FF0); void delay(void); void main(void) { TRISB = 0x00; while (1) { PORTB++; delay(); } } void delay(void) { unsigned int i;for (i=0; i<10000; i++); }