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
Bookmarks