Hi All,
I want to make a Sony remote. I wrote the attached code, and I do not see any results. The IR Led is on the colector of a npn transistor, which is controlled by PORTC.2 (for pwm).Anyhelp!.
When I connect a red led instead of the if Is see the led going on off, when the rotary is used, and in idle it goes on and of periodically with a period of ~1sec. The used pic is pic18f2550.
I think i need help now, if anyone couldhelp thanks.
DEFINE OSC 4
DEFINE BUTTON_PAUSE 20
DEFINE PULSIN_MAX 5000
INCLUDE "DT_INTS-18.bas" ' Base Interrupt System
INCLUDE "ReEnterPBP-18.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _Rot_Encoder, PBP, yes
INT_Handler INT2_INT, _but_int, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
addr CON %00011010 ' 26 = DVD address code
code CON $49 ' http://www.winpicprog.co.uk/pic_tutorial5.html
' Packet format: 7 bits on left are button number. 5 bits on right select TV.
MENU CON 0 ' MENU BUTTON
MUTE CON 20 ' MUTE BUTTON
CHUP CON 16 ' CHANNEL UP BUTTON
CHDWN CON 17 ' CHANNEL DOWN BUTTON
VOLUP CON 18 ' VOLUME UP BUTTON
VOLDWN CON 19 ' VOLUME DOWN BUTTON
ENTER CON 11 ' ENTER BUTTON
X VAR BYTE ' Data bit loop counter & bit index pointer
Duration VAR BYTE ' Duration of button press
Key VAR BYTE ' Button # to send
Y VAR BYTE ' Data bit loop counter & bit index pointer
PR2 = %00011001 ' Set PWM frequency to +/- 40kHz, set to 26 for 38kHz or 28 for 36kHz
CCP1CON = %00001100 ' Mode select = PWM
T2CON = %00000100 ' Timer2 ON + 1:1 prescale
CCPR1L = %00001101 ' PWM duty cycle 50%
TRISA = 0
TRISB = 0 ' RB0 = IRLED out
TRISB.0 = 1
TRISB.1 = 1
TRISB.2 = 1
TRISC = 0 ' RB0 = IRLED out
STATIC_CONTROL_MODE VAR BYTE
OLDBITS VAR BYTE
NEWBITS VAR BYTE
COUN VAR WORD
adraneia VAR WORD
IROUT VAR PORTC.2
led VAR PORTC.1
ENC0 VAR PORTB.0
ENC1 VAR PORTB.1
BUTT VAR PORTB.2
Duration = 3 ' Send it twice
COUN = 0
adraneia = 0
high led
pause 1000
low led
GOTO Main ' Jump over pulse routine to Main
but_int:
@ INT_DISABLE INT2_INT
adraneia = 0
IF BUTT = 0 THEN
high led
COUN = 0
WHILE BUTT = 0
COUN = COUN + 1
PAUSE 200
WEND
IF COUN > 13 THEN
Key = MUTE
COUN = 0
goto POUT_I
ENDIF
IF COUN > 40 THEN
Key = MENU
COUN = 0
goto POUT_I
ENDIF
COUN = 0
IF STATIC_CONTROL_MODE = 0 THEN
STATIC_CONTROL_MODE = 1
ELSE
STATIC_CONTROL_MODE = 0
ENDIF
Key = volup
goto POUT_I
endif
goto done_but
sendHeaderI:
TRISC.2 = 0
PauseUs 2400 ' Lead_in pulse
TRISC.2 = 1
pauseus 600
RETURN
sendZeroI:
TRISC.2 = 0
PauseUs 600 ' Lead_in pulse
TRISC.2 = 1
pauseus 600
RETURN
sendOneI:
TRISC.2 = 0
PauseUs 1200 ' Lead_in pulse
TRISC.2 = 1
pauseus 600
RETURN
POUT_I: ' send IR code
for Y = 1 to Duration ' five times
X= 0
GOSUB sendHeader
FOR X = 6 to 0 STEP-1 ' 12-bits total MSB first
IF Key.0[X] = 1 THEN '
GOSUB sendOneI
ELSE
GOSUB sendZeroI
ENDIF
NEXT X
Key = addr
X = 0
FOR X = 4 to 0 STEP-1 ' 12-bits total MSB first
IF Key.0[X] = 1 THEN '
GOSUB sendOneI
ELSE
GOSUB sendZeroI
ENDIF
NEXT X
TRISC.2 = 1
Pauseus 1000
next Y
GOTO done_but
done_but:
@ INT_ENABLE INT2_INT
@ INT_RETURN
Main:
PAUSE 5000
OLDBITS.1 = ENC1
OLDBITS.0 = ENC0
STATIC_CONTROL_MODE = 0
high led
@INT_ENABLE INT0_INT ;RB Port Change Interrupt
@INT_ENABLE INT2_INT ;RB Port Change Interrupt
loopw:
PAUSE 200
adraneia = adraneia + 1
if adraneia > 150 then
low led
adraneia = 0
sleep 36000
endif
Goto loopw ' Do it forever
'---[RBC - interrupt handler]---------------------------------------------------
Rot_Encoder:
@ INT_DISABLE INT0_INT
NEWBITS.1 = PORTB.1
NEWBITS.0 = PORTB.0
high led
adraneia = 0
IF NEWBITS.0 = 0 AND OLDBITS.0 = 1 THEN
IF NEWBITS.1 = 1 THEN
GOTO GODOWN
ELSE
GOTO GOUP
ENDIF
ENDIF
goto DoneRotEnc
GOUP:
if STATIC_CONTROL_MODE = 1 then
GOTO GOCHUP
ELSE
goto GOVOLUP
ENDIF
GODOWN:
if STATIC_CONTROL_MODE = 1 then
GOTO GOCHDW
ELSE
goto GOVOLDW
ENDIF
GOVOLUP:
Key = VOLUP
GOTO POUT
GOVOLDW:
Key = VOLDWN
GOTO POUT
GOCHDW:
Key = CHDWN
goto POUT
GOCHUP:
Key = CHUP
goto POUT
sendHeader:
TRISC.2 = 0
PauseUs 2400 ' Lead_in pulse
TRISC.2 = 1
pauseus 600
RETURN
sendZero:
TRISC.2 = 0
PauseUs 600 ' Lead_in pulse
TRISC.2 = 1
pauseus 600
RETURN
sendOne:
TRISC.2 = 0
PauseUs 1200 ' Lead_in pulse
TRISC.2 = 1
pauseus 600
RETURN
POUT: ' send IR code
for Y = 1 to Duration ' five times
GOSUB sendHeader
FOR X = 0 to 6 ' 12-bits total MSB first
IF Key.0[X] = 1 THEN '
GOSUB sendOne
ELSE
GOSUB sendZero
ENDIF
NEXT X
Key = addr
X = 0
FOR X = 0 to 4 ' 12-bits total MSB first
IF Key.0[X] = 1 THEN '
GOSUB sendOne
ELSE
GOSUB sendZero
ENDIF
NEXT X
TRISC.2 = 1
Pauseus 1000
next Y
GOTO DoneRotEnc
DoneRotEnc:
OLDBITS = NEWBITS
@ INT_ENABLE INT0_INT
@ INT_RETURN
END
Bookmarks