Sorry if this is a dup, I checked the archive. I forgot to add the PIC header in the subject so I'm re-emailing this. Hello, I obviously don't know what super-simple thing I missed in the documentation but for whatever reason I can not get my delay loops to work. I can get a simple TMR0 loop to work no problem but a delay loop pulled right off the "calculator" that's worked tons of times for F628s etc.. will not work. Here is the code... delay1 works no problem I test it out with my scope and the LED blinking slows down from about 128khz to 400hz (with delay added/removed). If I call delay2 the PIC never returns out of the call. (Proven by turning on the LED after a call to delay 2 before the loop). The device is a PIC 16F1509 on solid development board. Thanks for any insight.
__CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _CLKOUTEN_OF= F __CONFIG _CONFIG2, _LVP_OFF & _STVREN_ON ;**************************************************************************= ***** ; ; Variable Definitions ; ;**************************************************************************= ***** cblock int_delay1 int_delay2 endc ;**************************************************************************= ***** ; Reset Vector ;**************************************************************************= ***** RES_VECT CODE 0x0000 ; processor reset vector GOTO START ; go to beginning of program ;**************************************************************************= ***** ; TODO INSERT ISR HERE ;**************************************************************************= ***** ; MAIN PROGRAM ;**************************************************************************= ***** MAIN_PROG CODE ; let linker place main program INIT: ;RC5 =3D PWM1 BANKSEL LATA ;Data Latch CLRF LATA ; BANKSEL ANSELC ; CLRF ANSELC ;Digital IO BANKSEL PORTC ; BCF PORTC,5 ;Clear PWM1 BANKSEL TRISC ;Set all PORTC to outputs CLRF TRISC BANKSEL OSCCON MOVLW 0x78 ;16MHZ Clock MOVWF OSCCON RETURN cfg_tmr0: movlw b'11000111' BANKSEL OPTION_REG movwf OPTION_REG RETURN reset_tmr0: BANKSEL TMR0 CLRF TMR0 BANKSEL INTCON CLRF INTCON RETURN delay1 NOP NOP CALL reset_tmr0 BANKSEL OPTION_REG ; Bank1 MOVLW 0xC3 ; PortB pull-ups are disabled, MOVWF OPTION_REG ; Interrupt on rising edge of RB0 ; Timer0 increment from internal clock ; with a prescaler of 1:16. ; The TMR0 interrupt is disabled, do polling on the overflow bit T0_OVFL_WAIT BTFSS INTCON, T0IF GOTO T0_OVFL_WAIT NOP ;option_reg 11000111 1:256 prescaler= .. RETURN delay2 BANKSEL int_delay1 MOVLW 0x01 MOVWF int_delay1 OLOOP call delay1 BANKSEL int_delay1 DECFSZ int_delay1,F GOTO OLOOP NOP ;... else RETURN START CALL INIT CALL cfg_tmr0 ;CALL DRIVE_INIT ; CALL DRIVE_STOP ; call DELAY ;CALL DRIVE_R_50PCT NOP LOOP: BANKSEL PORTC BCF PORTC,2 ;LED OFF TEST NOP CALL delay1 ;movlw 0x55 BANKSEL PORTC BSF PORTC,2 ;LED ON TEST CALL delay2 NOP NOP GOTO LOOP ;loop forever END Thank you, Charles --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .