Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bit infrared,buffer,change,initial,sample,loop,output;
- volatile unsigned int timer=0;
- volatile unsigned char i=0,j=0,timetable[70];
- void receive(void);
- void interrupt()
- {
- if(INTCON.T0IF)
- {
- if(timer<65534)timer++;
- TMR0=50;
- //PORTC.F1=~PORTC.F1; // will change per 17.8 usec = 1 timer
- INTCON.T0IF=0;
- }
- }
- void main()
- {
- ANSEL = 0;
- ANSELH = 0;
- PORTA = 0;
- PORTC = 0;
- PORTD = 0;
- TRISC = 0;
- TRISD = 0b00000011;
- OPTION_REG=0x88;
- TMR0=50;
- PR2 = 0b00100000 ;
- T2CON = 0b00000101 ;
- CCPR1L = 0x00; // 0x0F ;
- CCP1CON = 0b00001100 ;
- INTCON.T0IE=1;
- INTCON.GIE=1;
- initial=1;
- sample=1;
- buffer=~PORTD.F0;
- delay_ms(5000);
- while(1)
- {
- infrared=~PORTD.F0;
- if(buffer!=infrared){change=1;buffer=infrared;PORTC.F1=1;} else change=0;
- if(change && sample)
- {
- if(initial)
- {
- timer=0;
- initial=0;
- }
- else
- {
- timetable[i++]=timer;
- timer=0;
- }
- }
- if(!initial && timer>=2000 && i>2)
- {
- for(j=0;j<=i;j++)
- {
- EEPROM_Write(0x00+j,timetable[j]);
- }
- EEPROM_Write(0x80,i);
- PORTC.F0=1;
- while(1)
- {
- while(PORTD.F1);
- j=0;
- i=EEPROM_Read(0x80);
- for(j=0;j<=i;j++)
- {
- timetable[j]=EEPROM_Read(0x00+j);
- }
- loop=1;
- j=0;
- timer=0;
- CCPR1L = 0x0F;
- for(j=0;j<=i;j++)
- {
- while(timer<timetable[j]);
- timer=0;
- output=~output;//CCPR1L = 0x0F;CCPR1L = 0x00;
- if(output)CCPR1L = 0x0F;
- else CCPR1L = 0x00;
- }
- CCPR1L = 0x00;
- PORTC.F7=~PORTC.F7;
- delay_ms(255);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement