Am I being interrupted?


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2009
    Posts
    18

    Default Am I being interrupted?

    Greetings!

    I have purchased an FM transmitter that changes frequency by setting a binary value. I am adapting a PIC chip to set the binary value, and display it on an LCD. I have two buttons (up, down) to change frequency.

    It works, but each time a button is pressed, the program seems to hang a sec, then reset. I thought it was interrupts, and I "think" I disabled them, but it still occurs.

    Could someone offer a reasonable direction on where my problem might lie?

    The code is pasted below:

    Code:
    DEFINE LCD_DREG	PORTB	'Define PIC port used for LCD Data lines
    DEFINE LCD_DBIT	4		'Define first pin of portb connected to LCD DB4
    
    DEFINE LCD_RSREG PORTB	'Define PIC port used for RS line of LCD
    DEFINE LCD_RSBIT 2		'Define Portb pin used for RS connection
    DEFINE LCD_EREG	PORTB	'Define PIC prot used for E line of LCD
    DEFINE LCD_EBIT	3		'Define PortB pin used for E connection
    
    DEFINE LCD_BITS	4		'Define the 4 bit communication mode to LCD
    DEFINE LCD_LINES 2		'Define using a 2 line LCD
    
    DEFINE BUTTON_PAUSE 20
    
    UPBUTTON VAR PORTB.0
    DNBUTTON VAR PORTB.1
    
    MYFREQ var byte
    BUTTVAR var byte
    
    REM *********************************
    
    	PORTB.0 = 0
    	PORTB.1 = 0
    	PORTA.0 = 0 REM Binary Output on Port A Pins 0-3
    	PORTA.1 = 0
    	PORTA.2 = 0
    	PORTA.3 = 0
    	LCDOUT $FE, 1
    	LCDOUT $FE, 2
    	LCDOUT $FE, $80
    	LCDOUT "Test Transmitter"
    	READ $B0, MYFREQ
    	IF MYFREQ > %0111 THEN GOSUB SETDEFAULTS
    	GOSUB SETFREQ
    
    MYLOOP:
    
    	BUTTON UPBUTTON, 0, 255, 0, BUTTVAR, 1, GOUP
    	BUTTON DNBUTTON, 0, 255, 0, BUTTVAR, 1, GODN
    
    GOTO MYLOOP
    
    REM **********************************************
    'GOTO THEEND
    REM **********************************************
    REM -- END OF Main Program and Loop. Subroutines follow...
    
    GOUP:
    	IF MYFREQ >= %1110 THEN
    		MYFREQ = %1110
    	ELSE
    		MYFREQ = MYFREQ + 1
    	ENDIF
    	GOSUB SETFREQ
    RETURN
    
    GODN:
    	IF MYFREQ <= %0000 THEN
    		MYFREQ = %0000
    	ELSE
    		MYFREQ = MYFREQ - 1
    	ENDIF
    	GOSUB SETFREQ
    RETURN
    
    REM **********************************************
    SETFREQ:
    	LCDOUT $FE,$C0
    	SELECT CASE MYFREQ
    		CASE %0000
    			LCDOUT "Freq  87.7 Mhz "
    			PORTA.0 = 0
    			PORTA.1 = 0
    			PORTA.2 = 0
    			PORTA.3 = 0
    		CASE %0001
    			LCDOUT "Freq  87.9 Mhz "
    			PORTA.0 = 1
    			PORTA.1 = 0
    			PORTA.2 = 0
    			PORTA.3 = 0
    		CASE %0010
    			LCDOUT "Freq  88.1 Mhz "
    			PORTA.0 = 0
    			PORTA.1 = 1
    			PORTA.2 = 0
    			PORTA.3 = 0
    		CASE %0011
    			LCDOUT "Freq  88.3 Mhz "
    			PORTA.0 = 1
    			PORTA.1 = 1
    			PORTA.2 = 0
    			PORTA.3 = 0
    		CASE %0100
    			LCDOUT "Freq  88.5 Mhz "
    			PORTA.0 = 0
    			PORTA.1 = 0
    			PORTA.2 = 1
    			PORTA.3 = 0
    		CASE %0101
    			LCDOUT "Freq  88.7 Mhz "
    			PORTA.0 = 1
    			PORTA.1 = 0
    			PORTA.2 = 1
    			PORTA.3 = 0
    		CASE %0110
    			LCDOUT "Freq  88.9 Mhz "
    			PORTA.0 = 0
    			PORTA.1 = 1
    			PORTA.2 = 1
    			PORTA.3 = 0
    		CASE %1000
    			LCDOUT "Freq 106.7 Mhz"
    			PORTA.0 = 0
    			PORTA.1 = 0
    			PORTA.2 = 0
    			PORTA.3 = 1
    		CASE %1001
    			LCDOUT "Freq 106.9 Mhz"
    			PORTA.0 = 1
    			PORTA.1 = 0
    			PORTA.2 = 0
    			PORTA.3 = 1
    		CASE %1010
    			LCDOUT "Freq 107.1 Mhz"
    			PORTA.0 = 0
    			PORTA.1 = 1
    			PORTA.2 = 0
    			PORTA.3 = 1
    		CASE %1011
    			LCDOUT "Freq 107.3 Mhz"
    			PORTA.0 = 1
    			PORTA.1 = 1
    			PORTA.2 = 0
    			PORTA.3 = 1
    		CASE %1100
    			LCDOUT "Freq 107.5 Mhz"
    			PORTA.0 = 0
    			PORTA.1 = 0
    			PORTA.2 = 1
    			PORTA.3 = 1
    		CASE %1101
    			LCDOUT "Freq 107.7 Mhz"
    			PORTA.0 = 1
    			PORTA.1 = 0
    			PORTA.2 = 1
    			PORTA.3 = 1
    		CASE %1110
    			LCDOUT "Freq 107.9 Mhz"
    			PORTA.0 = 0
    			PORTA.1 = 1
    			PORTA.2 = 1
    			PORTA.3 = 1
    		CASE %0111,%1111
    			LCDOUT "Freq Invalid"
    			PORTA.0 = 0
    			PORTA.1 = 0
    			PORTA.2 = 0
    			PORTA.3 = 0
    		CASE ELSE
    	END SELECT
    	WRITE $B0, MYFREQ
    RETURN
    REM ********************************
    
    SETDEFAULTS:
    	MYFREQ = %0111
    	WRITE $B0, MYFREQ
    RETURN
    
    THEEND:
    END
    I am sure it is blazingly simple to some. Just not me.

    Any ideas would be appreciated!

    Cheers!

    SmugWimp

  2. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default

    I think it is as simple as GOUP and GODN should end by a 'goto MYLOOP' instead of RETURN since it is GOneTO by the BUTTON routine. See the example in the manual for the BUTTON statement.

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink Nothing abnormal ...

    Hi,

    I think you should wait for the button ( up or down ) to be released BEFORE jumping to "setfreq".
    That implies The BUTTON command to be slightly modified for an auto-repeat feature ... AND also to increase the debugging time to, say, 100-250 ms ...

    Also note you can simplify the output to PortA.0-3 ... as the 4 lower bits of "myfreq" are the same of your Output. ( just have to "catch" the invalid codes ...)

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Jan 2009
    Posts
    18


    Did you find this post helpful? Yes | No

    Default

    Jerson: That did the trick; thanks!

    Acetronics: I figured there was a way, I just dont know how yet, lol!

    Thanks to all!

    Cheers!

    SmugWimp

Similar Threads

  1. 1 line interrupted keypad reading
    By Acetronics2 in forum Schematics
    Replies: 1
    Last Post: - 7th October 2005, 14:18

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