Beginner having trouble with interrupt..


Results 1 to 11 of 11

Threaded View

  1. #7
    Join Date
    Oct 2008
    Posts
    65

    Default

    Bruce I adjust the code, but it doesnt blink the led on PortB.1(only high output) When I use the serial communicator and entering 1 (5x) it turns off the led PortB.1. I was expecting that it will trigger PortB.0.
    Code:
    CLEAR 
    include "modedefs.bas" 'include serout defines
    DEFINE OSC 20	;using a 4 MHz oscillator here
    TRISC = %10000000
    OPTION_REG=%10000101	;Page 48 or data sheet
    				;Bit 7=1 disable pull ups on PORTB 
    				;Bit 5=0 selects timer mode 
    				;Bit 2=1  }
    				;Bit 1=0  } sets Timer0 pre-scaler to 64
    				;Bit 0=1  }
    				
    INTCON=%10100000	;Bit 7=1 Enables all unmasked interrupts
    				;Bit 5=1 Enables Timer0 overflow interrupt 
    				;Bit 2 flag will be set on interrupt and has to be cleared 
    				;in the interrupt routine.  It is set clear to start with.
    RX var byte ' Receive byte
    X    VAR    BYTE 	;Declare x as a variable
    i var byte
    TEMP      var BYTE 52
    Cnt       VAR BYTE 49
    symbol led1=PORTB.0
    x=20
    ALPHA		VAR  WORD	;this variable counts in the PauseUS loop
    BETA		VAR  BYTE	;this variable counts the 61 interrupt ticks
    TRISB   = %11110000	;sets the 3 output pins in the D port
    PORTB = %00000000	;sets all pins low in the D port
    				
    ON INTERRUPT GOTO INTERUPTROUTINE	;This line needs to be early in the program, before
    				;the routine is called in any case.
    				
    MAINLOOP:		
            High PORTB.1       
            For i = 0 to 10	
    	    	Pause 1   
    		Next i		
            Low PORTB.1     
            For i = 0 to 10	
    	        Pause 1   	
    		Next i 
            
       ''''''''''''''''''''''''''''''''''''''''''''''''
        IF Cnt=49 then
                led1=1-led1
                pause 100
                cnt=0
         endif   
                       
       ''''''''''''''''''''''''''''''''''''''''''''''''         	
    GOTO MAINLOOP	;end of loop
    				
    DISABLE	
    INTERUPTROUTINE:	
       serin PortC.7, T2400, RX 'Receive menu
       Cnt = Rx
       'TOGGLE PORTB.2
       'TMR0=0           ;clear Timer0 before exit
       INTCON.2 = 0   ;clears the interrupt flag.
       RESUME		;resume the main program
    ENABLE		;DISABLE and ENABLE must bracket the int routine
    END
    Do I need to change some settings to have my target output?
    _____________________
    mbox
    Last edited by mbox; - 29th April 2009 at 00:43.

Similar Threads

  1. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 03:35
  2. Very Trouble with 8722 Interrupt
    By smarino in forum mel PIC BASIC
    Replies: 4
    Last Post: - 5th March 2009, 10:48
  3. Help with Analog Interrupt
    By brid0030 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th February 2008, 19:14
  4. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 03:59
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 02:07

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts