Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- LIST P=PIC12F683
- #include <p12F683.inc>
- ;External reset, no code protection, watchdog timer off, internal clock
- __CONFIG _MCLRE_ON & _CP_OFF & _WDT_OFF & _INTRC_OSC_NOCLKOUT
- ;This Code tells the pic to constantly emit an IR bitstream on pin IR_PIN
- ;every 50ms+255ms(if DELAY1_PIN is low)+255ms(if DELAY2_PIN) is low.
- ;The IR bitstream is in the SONY TV format.
- ;The device ID is configurable by changing TV_ID.
- ;The IR data payload is configurable by changing BEACON_ID.
- ;An LED flashes when data is set, this pin can be configured by changing LED_PIN.
- ;Remember, for all pins you change to update GPIO_CONFIG and PULLUP_CONFIG.
- ;Variable Definitions
- cblock 0x20
- count1
- counta
- countb
- count
- Delay_Count
- Bit_Cntr
- Data_Byte
- Dev_Byte
- Pulse
- endc
- ;Configurable constants
- GPIO_CONFIG Equ b'111100' ;GP0/GP1 outputs (0 = output), GP2/GP4/GP5 inputs
- PULLUP_CONFIG Equ b'110100' ;Enable pullups on GP2/GP4/GP5
- DELAY1_PIN Equ 5 ;Pin that controls short delays
- DELAY2_PIN Equ 4 ;Pin that controls longer delays
- IR_PIN Equ 0 ;Use GP0 as the IR transmitter pin
- LED_PIN Equ 1 ;Use GP1 as the LED
- TV_ID Equ 0x01 ;Device ID bits to send (TV ID ATM)
- BEACON_ID Equ d'16' ;Use ProgUp button ID as the beacon ID for now
- org 0
- setupPins
- BCF STATUS,RP0 ; Switch -> Bank 0
- CLRF GPIO ;Init GPIO - GPIO set all outputs to 0
- BSF STATUS,RP0 ; Select Registers at Bank 1
- CLRF ANSEL ;set analog config bits to zero - all pins are digital I/O
- MOVLW GPIO_CONFIG ;GP0/GP1 outputs, GP2/GP4/GP5 inputs
- MOVWF TRISIO ;write bitset to GPIO control register(TRISIO)
- BCF OPTION_REG,0x7 ;Enable input pullup resistors
- MOVLW PULLUP_CONFIG ;Load pullup config
- MOVWF WPU ;write config to register
- MOVLW 0x60 ;0x70 = 8Mhz,0x60 = 4Mhz
- MOVWF OSCCON ; Set the internal clock speed to 4 Mhz
- main
- BCF STATUS,RP0 ; Switch -> Bank 0
- BTFSS GPIO,DELAY1_PIN ;Test to see if we should delay 255ms
- CALL Delay255
- BTFSS GPIO,DELAY2_PIN ;Test to see if we should delay 255ms
- CALL Delay255
- BSF GPIO,LED_PIN ;Turn on the LED
- movlw BEACON_ID ;Load the data to send via IR
- call Transmit ;Actually bitbang the IR
- BCF GPIO,LED_PIN ;Turn off the LED
- CALL Delay50 ;Delay 50ms as a minimum
- GOTO main
- ;Delay routines
- Delay255 movlw 0xff ;delay 255 mS
- goto d0
- Delay100 movlw d'100' ;delay 100mS
- goto d0
- Delay50 movlw d'50' ;delay 50mS
- goto d0
- Delay27 movlw d'27' ;delay 27mS
- goto d0
- Delay20 movlw d'20' ;delay 20mS
- goto d0
- Delay5 movlw 0x05 ;delay 5.000 ms (4 MHz clock)
- d0 movwf count1
- d1 movlw 0xC7
- movwf counta
- movlw 0x01
- movwf countb
- Delay_0 decfsz counta, f
- goto $+2
- decfsz countb, f
- goto Delay_0
- decfsz count1 ,f
- goto d1
- retlw 0x00
- ;end of Delay routines
- ; IR Routines
- Transmit MOVWF Data_Byte ;move W to Data_Byte
- MOVLW 0x07 ;set 7 DATA bits out
- MOVWF Bit_Cntr
- call TX_Start ;send start bit
- Ser_Loop RRF Data_Byte , f ;send one bit
- BTFSC STATUS , C
- call TX_One
- BTFSS STATUS , C
- call TX_Zero
- DECFSZ Bit_Cntr , f ;test if all done
- GOTO Ser_Loop
- ;now send device data
- movlw TV_ID
- movwf Dev_Byte ;set device to TV
- MOVLW 0x05 ;set 5 device bits out
- MOVWF Bit_Cntr
- Ser_Loop2 RRF Dev_Byte , f ;send one bit
- BTFSC STATUS , C
- call TX_One
- BTFSS STATUS , C
- call TX_Zero
- DECFSZ Bit_Cntr , f ;test if all done
- GOTO Ser_Loop2
- retlw 0x00
- TX_Start
- movlw d'92'
- call IR_pulse
- movlw d'23'
- call NO_pulse
- retlw 0x00
- TX_One
- movlw d'46'
- call IR_pulse
- movlw d'23'
- call NO_pulse
- retlw 0x00
- TX_Zero
- movlw d'23'
- call IR_pulse
- movlw d'23'
- call NO_pulse
- retlw 0x00
- IR_pulse
- MOVWF count ; Pulses the IR led at 38KHz
- irloop
- BSF GPIO, IR_PIN
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- BCF GPIO, IR_PIN
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP
- NOP
- NOP ;
- NOP ;
- DECFSZ count,F
- GOTO irloop
- RETLW 0
- NO_pulse
- MOVWF count ; Doesn't pulse the IR led
- irloop2 BCF GPIO, IR_PIN
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- BCF GPIO, IR_PIN
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP ;
- NOP
- NOP
- NOP ;
- NOP ;
- DECFSZ count,F
- GOTO irloop2
- RETLW 0
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement