Hi Alexey, So I understand you'd like to add your sample to jallib repository. I can't test it for real, but I expect it's working, right ?
Could you please resend a message with your program attached, not copy/pasted in the body ? It's easier to get a clean to commit. Also, just a tought, it usually is a bad idea to use _usec_delay() compiler directive, and better use delay.jal library, particularly when there are lots of delay statements. _usec_delay() calls actually expands, like macro, so it usually uses more code space. In your sample, you'll save 10 bytes (though eats 4 bytes more RAM..) Thanks Cheers, Seb 2011/5/21 stalex <[email protected]> > Hello. > I have written a program to analyze footprint of signal of keys from > IR-remote and > do something on pressing different keys on IR-remote. For example - > play/pause winamp playing and so on :) > As i cant find the finished code for JAL for different IR protocols I > would like to share my code with anyone who using JAL :) > > Schematic is simple - the significant detail is than IR reciever > TSOPxxx connected to INT0(RB0) pin on MC > and have pull up resistor on this connect > > The main idea of this program to measure ticks of timer1 between > interrupts from INT0. Conver this intervals > to 'binary' array that convert to dwrod variable and have a keycode of > any key on IR-remote. > -------------------- > -- > > ----------------------------------------------------------------------------- > -- Title: demo of analyze of IR-remote timing between interrupts from > -- TSOP IR reciver, and so a footprint of signal of different keys > from IR-remote > -- Author: Alexey Studenikin [email protected] , Copyright (c) 2011, > all rights reserved. > > > ;@jallib section chipdef > -- chip setup > include 18f4550 > > -- even though the external crystal is 20 MHz, the configuration is > such that > -- the CPU clock is derived from the 96 Mhz PLL clock (div2), > therefore set > -- target frequency to 48 MHz > pragma target clock 48_000_000 > > > include delay > include usb_serial > include print > include pic_data_eeprom > > > > alias led is pin_b6 > pin_b6_direction = output > led = off > alias led2 is pin_b7 > pin_b7_direction = output > led2=off > alias led3 is pin_b5 > pin_b5_direction = output > led3=off > var bit IR_pin is pin_B0 > pin_B0_direction = input > > -- set up interrupts > INTCON_INT0IE = on -- allow interrupt from changing state on INT0 > INTCON_INT0IF = off -- flush flag of interrupt from INT0 > INTCON2_INTEDG0 = 1 -- setting up inerrupt INT0 from changing state 0- > >1 > INTCON_GIE = on -- allow interrupts > > -- setting up timer > T1CON_T1CKPS = 0b_11 -- prescale to 8 > T1CON_TMR1CS = 0 -- clock source from internal clock > PIE1_TMR1IE = on -- allow interrup from TMR1 > PIR1_TMR1IF = off -- flush flag of interrupt TMR1 > INTCON_PEIE = on -- allow interrupt > T1CON_TMR1ON = off -- stoping timer > > > > const byte len=50 ;length of array of intervals between interrupts > from int0 > var byte buttonnumber=0 -- if first press of button > var byte trainH[len] ; array of Hight byte of TMR1 > var byte trainL[len] > > var byte trainnum=0 ;current position in array > var byte realtrainlen=0 ;real lenght of train > > procedure INT_ISR is > pragma interrupt > > if INTCON_INT0IF then -- if interrupt from INT0 > INTCON_INT0IF = off -- flushing flag > > if (buttonnumber==0) then -- if first packet in train - initialize > timer and variables > buttonnumber=buttonnumber+1 > trainnum=0 > TMR1H=0 > TMR1L=0 > T1CON_TMR1ON=on > end if > > if (buttonnumber>0) then ; > T1CON_TMR1ON = off ;stopping timer while writing > trainH[trainnum]= TMR1H > trainL[trainnum]= TMR1L > trainnum=trainnum+1 > > TMR1H=0 ; zeroing timer > TMR1L=0 > T1CON_TMR1ON = on ;starting timer again > end if > end if > > if PIR1_TMR1IF then -- if we have interrupt from timer that means that > train of packets have finished > PIR1_TMR1IF = off -- flushing flag > T1CON_TMR1ON = off ; stopping timers > PIE1_TMR1IE = off ; disabling interrupt from timer > realtrainlen=trainnum > trainnum =len ; making 'flag' to start procedure of analyzing whole > train > end if > end procedure > > > -- constants > const byte str_welcome[] = "JALLIB USB Serial Demo app\n" > > > -- setup the USB serial library > usb_serial_init() > > var bit has_shown_welcome_msg = true > var byte ch > > var byte i=0 > var byte i1=0 > var dword keynum=0 > > -- main loop > forever loop > -- poll the usb ISR function on a regular base, in order to > -- serve the USB requests > usb_serial_flush() > > -- check if USB device has been configured by the HOST > if ( usb_cdc_line_status() != 0x00 ) then > if !has_shown_welcome_msg then > has_shown_welcome_msg = true > print_string( usb_serial_data, str_welcome ) > end if > else > has_shown_welcome_msg = false > end if > > ;if we already have len(full) 'bits' and 'ticks' > var word t=0 > if (trainnum>=len) then > ;while thinking of data we dont need interrupts > INTCON_INT0IE=off > T1CON_TMR1ON = off > PIE1_TMR1IE = off > keynum=0 > > > print_crlf(usb_serial_data) > ;in my IR-remote the meaningful information int between 17 and 17+17 > "bits" > ;so lets convert from high byte of timer ticks between int0 to binary > dword 'keynumber' of button of IR-transmitter > for 17 using i loop > i1=i+17 > ;convert intervals between changes of input from IR receiver > from hight timer ticks to 'bits' > ;in your case there may be another values, you can see 'raw' > intervals in code below > if (trainH[i1]>0) then if (trainH[i1]<=7) then t=0 end if end > if > if (trainH[i1]>7) then if (trainH[i1]<=14) then t=1 end if > end if > if (trainH[i1]>14) then if (trainH[i1]<255) then t=2 end if > end if > > > ;convert from binary array to one dword > if (t==1) then > keynum=keynum+1 > end if > keynum=keynum<<1 > > ;lets see binary 'keynumber' > print_word_dec(usb_serial_data,t) > > ;in need we can print whole array of numbers of timer ticks > between interrupts from int0 > ; > print_byte_dec(usb_serial_data,trainH[i]) > usb_serial_data = "_" > print_byte_dec(usb_serial_data,trainL[i]) > > usb_serial_data = "[" > print_byte_dec(usb_serial_data,i1) > usb_serial_data = "]" > usb_serial_data = " " > end loop > > > ;print resulting 'keynber' and real length of train > usb_serial_data ="_" > print_dword_binary(usb_serial_data,keynum) > usb_serial_data ="_" > print_dword_dec(usb_serial_data,keynum) > usb_serial_data ="_" > print_byte_dec(usb_serial_data, realtrainlen ) > > > ;do something on different keynumber - optional > case keynum of > 249902 : > block > led =on > _usec_delay(5000) > led=off > end block > 168302 : > block > led2 =on > _usec_delay(5000) > led2 =off > end block > 184622 : > block > led3 =on > _usec_delay(5000) > led3 =off > end block > 205022 : ;button up > block > led3 =on > _usec_delay(5000) > led3 =off > end block > 225422: ;button down > block > led3 =on > _usec_delay(5000) > led3 =off > > end block > > > end case > > _usec_delay(300000) > ;getting ready to recieve another button > trainnum=0 > i=0 > buttonnumber=0 > keynum=0 > INTCON_INT0IE=on > PIE1_TMR1IE = on > > end if > > > end loop > > -- You received this message because you are subscribed to the Google Groups "jallib" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/jallib?hl=en.
