I appreaciate you both your help. Thanks Jinx an of course, you are right. I'm trying to improve my code writing:o) Anyway, my code is still not working:o) The led turns on and never turns off... CBLOCK 0x20 ; Declare variable addresses LOOP1,LOOP2,CONTADOR W_TEMP,STATUS_TEMP ENDC ORG 00h CALL INIT GOTO MAIN ; ------------------------ ; TIMER1 INTERRUPTION ; ------------------------ ORG 0x004 MOVWF W_TEMP ; save off current W register contents SWAPF STATUS,W ; move status register into W register CLRF STATUS ; select Bank 0 MOVWF STATUS_TEMP ; save off contents of STATUS register BANKSEL PIR1 BTFSS PIR1,TMR1IF GOTO EXIT RELOAD BCF PIR1, TMR1IF DECFSZ CONTADOR ; Si el Contador es cero, ya pasaron los 30 segundos GOTO EXIT BCF PORTA,0 CALL DELAY MOVLW d'25' ; Deberia ir un valor de 57 MOVWF CONTADOR EXIT MOVF STATUS_TEMP,W MOVWF STATUS SWAPF W_TEMP,F SWAPF W_TEMP,W RETFIE ; ------------------------ ; INICIALIZACION ; ------------------------ INIT BCF STATUS,RP1 BCF STATUS,RP0 CLRF PORTA ; Initialize port A CLRF PORTB ; Initialize port B CLRF PORTC ; Initialize port C BSF STATUS,RP0 ; RAM bank 1 CLRF TRISA ; All pins port A output CLRF TRISB ; All pins port B output CLRF TRISC ; All pins port C output CLRF PIE1 ; Mask all peripheral interrupts except BSF PIE1,TMR1IE ; the timer 1 interrupts. BCF STATUS, RP0 ; Bank0 CLRF PIR1 ; Clear peripheral interrupts Flags MOVLW B'00110001' ; Valor de Prescale = 8, Timer 1 Habilitado MOVWF T1CON bsf INTCON,GIE ; Global interrupt enable. CLRF TMR1L CLRF TMR1H MOVLW d'57' MOVWF CONTADOR ; ------------------------ ; FUNCTION OF PORT A PINS ; ------------------------ BSF STATUS,RP0 MOVLW d'6' MOVWF ADCON1 ; All pins digital I/O BCF STATUS,RP0 ; RAM bank 0 RETURN ; ---------- ; MAIN LOOP ; ---------- MAIN BSF PORTA,0 ; Turn on LED connected to RA0 CALL DELAY GOTO MAIN ; --------------- ; DELAY 250 MSEC ; --------------- DELAY MOVLW 250 MOVWF LOOP1 OUTER MOVLW 200 MOVWF LOOP2 INNER NOP NOP DECFSZ LOOP2,F GOTO INNER ; Inner loop = 5 usec. DECFSZ LOOP1,F GOTO OUTER RETURN END ;*************************************************************************************** Cheers (I like that!) Caro. P.S.: I know it may be difficult to read my code and I'm sorry. It's impossible to use tabs within gmail... On 8/28/07, Howard Winter wrote: > > Carol, > > I agree with Jinx on all points... starting with the beginning of the > program, put ORG 0 before the first instruction (GOTO Main) - I don't know > where it > would put it if you don't specify, and it may well be 0, but everyone puts > it in so why not keep to that? :-) > > It's unusual to use a GOTO to a routine (INIT) and then at the end GOTO > the instruction after it - you may as well use CALL and RETURN. It's not > wrong, but it does look very much what a rookie would do! :-) Why have > you put ORG h'80' at Main, by the way? > > For a more conventional structure, you may want to consider: > > ORG 0 > CALL INIT > GOTO MAIN > ORG 4 > - interrupt processing... > RETFIE > INIT > - initialisation... > RETURN > MAIN > - main loop... > GOTO MAIN > DELAY > - etc... > > I don't see anywhere that you initialise Timer1's counter registers - it > may well start at 0, but it's good practice to make sure by setting it > yourself. > > You move 57 into your Count variable during initialisation, but you don't > reload it after an interrupt, so it will only do the loop 57 times, > once! :-) > After that it will do it 256 times, since Count would start at 0 and count > down. > > You say it doesn't work, but you don't say how - how does it behave? > > Cheers, > > > Howard Winter > St.Albans, England > > > -- > http://www.piclist.com PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist > -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist