Code:
;Configuration Bits in the MICROCHIP / MPASM SUITE / P16F1933.INC file
;
;----- CONFIG1 Options --------------------------------------------------
;_FOSC_LP EQU H'FFF8' ; LP Oscillator, Low-power crystal connected between OSC1 and OSC2 pins
;_FOSC_XT EQU H'FFF9' ; XT Oscillator, Crystal/resonator connected between OSC1 and OSC2 pins
;_FOSC_HS EQU H'FFFA' ; HS Oscillator, High-speed crystal/resonator connected between OSC1 and OSC2 pins
;_FOSC_EXTRC EQU H'FFFB' ; EXTRC oscillator: External RC circuit connected to CLKIN pin
;_FOSC_INTOSC EQU H'FFFC' ; INTOSC oscillator: I/O function on CLKIN pin
;_FOSC_ECL EQU H'FFFD' ; ECL, External Clock, Low Power Mode (0-0.5 MHz): device clock supplied to CLKIN pin
;_FOSC_ECM EQU H'FFFE' ; ECM, External Clock, Medium Power Mode (0.5-4 MHz): device clock supplied to CLKIN pin
;_FOSC_ECH EQU H'FFFF' ; ECH, External Clock, High Power Mode (4-32 MHz): device clock supplied to CLKIN pin
;
;_WDTE_OFF EQU H'FFE7' ; WDT disabled
;_WDTE_SWDTEN EQU H'FFEF' ; WDT controlled by the SWDTEN bit in the WDTCON register
;_WDTE_NSLEEP EQU H'FFF7' ; WDT enabled while running and disabled in Sleep
;_WDTE_ON EQU H'FFFF' ; WDT enabled
;
;_PWRTE_ON EQU H'FFDF' ; PWRT enabled
;_PWRTE_OFF EQU H'FFFF' ; PWRT disabled
;
;_MCLRE_OFF EQU H'FFBF' ; MCLR/VPP pin function is digital input
;_MCLRE_ON EQU H'FFFF' ; MCLR/VPP pin function is MCLR
;
;_CP_ON EQU H'FF7F' ; Program memory code protection is enabled
;_CP_OFF EQU H'FFFF' ; Program memory code protection is disabled
;
;_CPD_ON EQU H'FEFF' ; Data memory code protection is enabled
;_CPD_OFF EQU H'FFFF' ; Data memory code protection is disabled
;
;_BOREN_OFF EQU H'F9FF' ; Brown-out Reset disabled
;_BOREN_SBODEN EQU H'FBFF' ; Brown-out Reset controlled by the SBOREN bit in the BORCON register
;_BOREN_NSLEEP EQU H'FDFF' ; Brown-out Reset enabled while running and disabled in Sleep
;_BOREN_ON EQU H'FFFF' ; Brown-out Reset enabled
;
;_CLKOUTEN_ON EQU H'F7FF' ; CLKOUT function is enabled on the CLKOUT pin
;_CLKOUTEN_OFF EQU H'FFFF' ; CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin
;
;_IESO_OFF EQU H'EFFF' ; Internal/External Switchover mode is disabled
;_IESO_ON EQU H'FFFF' ; Internal/External Switchover mode is enabled
;
;_FCMEN_OFF EQU H'DFFF' ; Fail-Safe Clock Monitor is disabled
;_FCMEN_ON EQU H'FFFF' ; Fail-Safe Clock Monitor is enabled
;
;;----- CONFIG2 Options --------------------------------------------------
;_WRT_ALL EQU H'FFFC' ; 000h to 7FFh write protected, no addresses may be modified by EECON control
;_WRT_HALF EQU H'FFFD' ; 000h to 3FFh write protected, 400h to 7FFh may be modified by EECON control
;_WRT_BOOT EQU H'FFFE' ; 000h to 1FFh write protected, 200h to 7FFh may be modified by EECON control
;_WRT_OFF EQU H'FFFF' ; Write protection off
;
;_PLLEN_OFF EQU H'FEFF' ; 4x PLL disabled
;_PLLEN_ON EQU H'FFFF' ; 4x PLL enabled
;
;_STVREN_OFF EQU H'FDFF' ; Stack Overflow or Underflow will not cause a Reset
;_STVREN_ON EQU H'FFFF' ; Stack Overflow or Underflow will cause a Reset
;
;_BORV_25 EQU H'FBFF' ; Brown-out Reset Voltage (VBOR) set to 2.5 V
;_BORV_19 EQU H'FFFF' ; Brown-out Reset Voltage (VBOR) set to 1.9 V
;
;_LVP_OFF EQU H'DFFF' ; High-voltage on MCLR/VPP must be used for programming
;_LVP_ON EQU H'FFFF' ; Low-voltage programming enabled
;
;
;
;
@ __config _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF ;commented the line in the picbasic folder file="12F1822.inc"
;-------------------------------------------------------------------------------
CLEAR ;Set all RAM registers to zero
;===============================================================================
;PORTS CONFIGURATION
;RA0 IR
;RA2, RA4 connection to relay
;RA5 LED
OSCCON.1=0
OSCCON.0=0 ;When the SCS bits of the OSCCON register = 00,
;the system clock source is determined by
;configuration of the FOSC<2:0> bits in the
;Configuration Word Register 1 (CONFIG1)
OSCCON.6=1 ;int osc freq 4MHz (IRCF bits)
OSCCON.5=1 ;int osc freq 4MHz (IRCF bits)
OSCCON.4=0 ;int osc freq 4MHz (IRCF bits)
OSCCON.3=1 ;int osc freq 4MHz (IRCF bits)
ANSELA=0 ;turn off the Analog to Digital converter,
;needs to be disabled prior to use I/O on portA.0 to 5
CM1CON0.7=0 ;Comparators Off (CxON bit)
FVRCON.7=0 ;Fixed Voltage Reference is disabled (FVREN bit)
DEFINE OSC 4 ;=4MHz
DEFINE PULSIN_MAX 490
OPTION_REG.7=1
Header VAR WORD
index VAR BYTE
IR_pulse VAR BYTE[31]
IR_data VAR BYTE[31]
PORTA=0
TRISA=%000001 ;PORTA.0 input for the IR
IRIN:
PULSIN PORTA.0,0,Header
IF (Header<400) OR (Header>490) THEN GOTO IRIN
FOR index=0 TO 31
PULSIN PORTA.0,1,IR_pulse[index]
NEXT
FOR index=0 TO 31
WRITE index,IR_pulse[index]
IF IR_pulse[index]<100 THEN
IR_pulse[index]=0
ELSE
IR_pulse[index]=1
ENDIF
NEXT
'Volume UP
FOR index=0 TO 31
LOOKUP Index,[1,1,1,0, 0,0,0,0, 1,1,1,0, 0,0,0,0, 1,1,1,0, 0,0,0,0, 0,0,0,1, 1,1,1,1],IR_data
IF IR_pulse[index]<>IR_data then Volume_DOWN
NEXT index
PORTA.5=1 ;turn ON the LED and operate (set) the relay
PORTA.4=0
PORTA.2=1
PAUSE 2 ;Relay Data sheet: 3 ms max. (mean value: approx. 2.0 ms)
PORTA.2=0
pause 1000 ;protect the relay for overusage when they keep the vol up pressed
'Volume DOWN
Volume_DOWN:
FOR index=0 TO 31
LOOKUP Index,[1,1,1,0, 0,0,0,0, 1,1,1,0, 0,0,0,0, 1,1,0,1, 0,0,0,0, 0,0,1,0, 1,1,1,1],IR_data
IF IR_pulse[index]<>IR_data then IRIN
NEXT index
PORTA.5=0 ;turn OFF the LED and release (reset) the relay
PORTA.2=0
PORTA.4=1
PAUSE 1 ;Relay Data sheet: 2 ms max. (mean value: approx. 1.0 ms)
PORTA.4=0
pause 1000 ;protect the relay for overusage when they keep the vol down pressed
GOTO IRIN
Bookmarks