...because with the code posted up, ISIS show me this results for "vol_up" like in picture attached ; it's something wrong ?! Thanks for your attention & cooperation !
...because with the code posted up, ISIS show me this results for "vol_up" like in picture attached ; it's something wrong ?! Thanks for your attention & cooperation !
...with some modification ; the results are now OK (in simulation, hope in real-world too !).
...and (of course !) ...Code:TRISIO = %00111110 ANSEL=0 OPTION_REG.7=0 IOCB=%00111110
...and at last...Code:if but1=0 then vol_up if but2=0 then vol_down if but3=0 then btn_up if but4=0 then btn_down if but5=0 then mute
The results are like in picture; hope testing "in vivo" tomorrow...Code:vol_up: delay = 970 '(970 us low + 970 us high + 660 us low = 2600 us pulse total time) gosub ir_out
You should modulate your signal on a carrier of about 38 kHz. You can generate this with assembly or use a pic12f683 and use the internal pwm generator. Then you can modulate this signal by switching the trisio pin.
I once did it this way:
It sends a Sony DVD play command every five seconds (as an example)
Code:@ device pic12F683, intrc_osc_noclkout, wdt_off, pwrt_on, mclr_off, protect_off, bod_off INCLUDE "MODEDEFS.BAS" DEFINE PULSIN_MAX 5000 GPIO = %00100000 TRISIO = %00001100 CCP1CON = %00001100 ' Mode select = PWM T2CON = %00000100 ' Timer2 ON + 1:1 prescale (last two bits) CCPR1L = %00001101 ' pwm duty 50% PR2 = %00011001 ' Set PWM frequency to +/- 40kHz, set to 26 for 38kHz or 28 for 36kHz ANSEL = %00000000 CMCON0 = %00000111 led var GPIO.5 counter VAR BYTE counter2 VAR BYTE command VAR WORD 'IR command to send temp VAR WORD bitcount VAR WORD bitselector var word rewind CON $79A 'sony DVD codes for testing play CON $59A postdata con $36 clear loop: command = play gosub sendIR pause 5000 goto loop sendIR: ' send IR code for counter = 1 to 5 ' five times TRISIO.2 = 0 PauseUs 2450 ' Lead_in pulse TRISIO.2 = 1 pauseus 450 ' (space) bitcount = 11 ' send first 11 bits temp = command GoSub transmit bitcount = 8 ' send remaining 8 bits temp = postdata GoSub transmit TRISIO.2 = 0 PauseUs 650 ' ptrail (pulse) TRISIO.2 = 1 Pauseus 13080 next counter Return transmit: bitselector = 1 << (bitcount - 1) For counter2 = 1 TO bitcount 'number of bits TRISIO.2 = 0 'make output (pin active, led on) PauseUs 540 'first part of bit, pulse IF (temp & bitselector) = 0 Then 'if bit is 0 PauseUs 580 'send second part of bit ,pulse EndIF TRISIO.2 = 1 'make input (pin inactive, led off) PauseUs 560 'space (no pulse) temp = temp << 1 'shift one bit Next counter2 Return
I finally got the code working but it is very ineffecient. I am only 17 and I came up with the code with only a little help so give me some credit. Its not the best but if any of you have other ways to compress the code and make it more effecient please reply. Thanks
Code:DEFINE OSC 4 ANSEL = %00000000 IR_PULSE var word(11) SIGNAL var word START_PULSE var word INDEX var byte X var byte Main: Pulsin PORTC.3, 0, start_pulse if (start_pulse < 220) or (start_pulse > 260) then main for index = 0 to 11 pulsin PORTC.3, 0, ir_pulse(index) next index Convert: x = 1 signal = 0 for index = 0 to 11 if (ir_pulse(index) > 90) then ADD_X READ_IR: x = x * 2 next index serout PORTC.2, 2, [#signal, 9] clear goto main ADD_X: signal = signal + x goto read_ir end
I intend to build remote using 12F675 (I have a lot...and none of 12F683). How generating a carrier of 39 kHz with assembly ? I found something about 40 kHz pulse on Mr.Bruce site, but...
Please, one clue ?!
?!?
Pulse: '// Emits # of 39kHz bursts held in variable Cycles
ASM ;// with auto delay between bursts
bsf gpio, 0 ;// 1uS, LED=on [need 25uS total ???????
goto $+1 ;// 3uS (2uS per goto $+1)
goto $+1 ;// 5uS
goto $+1 ;// 7uS
goto $+1 ;// 9uS
goto $+1 ;// 11uS
' goto $+1 ;// 13uS 'comment this for 39 kHz ???
bcf gpio, 0 ;// 14uS, LED=off
goto $+1 ;// 16uS
goto $+1 ;// 18uS
goto $+1 ;// 20uS
goto $+1 ;// 22uS
decfsz _Cycles,F ;// 23uS
goto _Pulse ;// 25us
ENDASM
PAUSEUS 500 '// 500uS delay between each data bit
RETURN '// Return to Main
...and next ?
Last edited by fratello; - 15th May 2010 at 18:55.
I try to simulate this remote using 12F683 (because of PWM) :
But the results are similarly ; I really don't understand what I do wrong ...Code:@ device pic12F683, intrc_osc_noclkout, wdt_off, pwrt_on, mclr_off, protect_off, bod_off INCLUDE "MODEDEFS.BAS" GPIO = %00000010 TRISIO = %00000010 CCP1CON = %00001100 ' Mode select = PWM T2CON = %00000100 ' Timer2 ON + 1:1 prescale (last two bits) CCPR1L = %00001101 ' pwm duty 50% PR2 = %00011001 ' Set PWM frequency to +/- 40kHz, set to 26 for 38kHz or 28 for 36kHz ANSEL = %00000000 CMCON0 = %00000111 led var GPIO.5 but1 var GPIO.1 LED=0 delay var word i var byte timeX var byte '========================================= main: pause 100 if but1=0 then vol_up vol_up: delay = 970 '(970 us low + 970 us high + 660 us low = 2600 us pulse total time) while but1=0 gosub ir_out gosub debounce wend PAUSE 50 Goto Main '========================================= ir_out: led=1 pauseus delay led=0 pauseus delay led=1 pauseus 660 led=0 pause 10 'wait 10ms before repeating return '========================================= Debounce : For timeX= 1 to 50 Pause 5 next timeX Return '========================================= END ' of program
Instead of led = 1 or led = 0 use this: TRISIO.2 = 0 or TRISIO.2 = 1
You have to connect your IR led to GPIO.2, not GPIO.5
Toggling TRISIO.2 will modulate your IR led
Bookmarks