bit infrared,buffer,change,j;
unsigned char measure=0,ref1=0,timepassed;
volatile unsigned char i=0;
void interrupt()
{
if(INTCON.T0IF)
{
measure++;
TMR0=0;
INTCON.T0IF=0;
}
}
void main(){
unsigned char measuretxt[7];
ANSEL = 0; // Configure AN pins as digital I/O
ANSELH = 0;
PORTB = 0;
PORTC = 0;
PORTD = 0;
TRISB = 0;
TRISC = 0;
TRISD = 0x01;
OPTION_REG=0x80;
TMR0=0;
INTCON.T0IE=1;
INTCON.GIE=1;
j=0;
buffer=0;
while(1)
{
infrared=~PORTD.F0;
if(buffer==infrared) change=0;
else
{
change=1;
buffer=infrared;
}
/*
|-----| |-----| |-----|
| | | | | |
____| |____| |____| |____
*/
if(change)
{
if(!j){ ref1=measure; j=1; }
else{ timepassed=measure-ref1;
ref1=measure;
}
EEPROM_Write(0x00+i,timepassed);
i++;
}
}
}
can u it share asmably lang. & its fx. alsoFragrance said:hi
here you go it is based on pic16f84a
regards
Fragrance
bit infrared,buffer,j,change,writetoeeprom,devam;
unsigned char timepassed=0,eeprombuffer[80];
volatile unsigned char i=0,ii=0,k;
volatile unsigned int timer=0,offtimer=0;
void interrupt()
{
if(INTCON.T0IF)
{
timer++;
if(!change && i>5)
{ offtimer++;
if(offtimer>1000){ PORTC.F0=~PORTC.F0; writetoeeprom=1; offtimer=0;}
}
TMR0=200;
INTCON.T0IF=0;
}
}
void main(){
//unsigned char measuretxt[7];
ANSEL = 0;
ANSELH = 0;
PORTC = 0;
PORTD = 0;
TRISC = 0;
TRISD = 0x03;
OPTION_REG=0x88;
TMR0=200;
INTCON.T0IE=1;
INTCON.GIE=1;
j=0;
//LCD_Init();
buffer=~PORTD.F0;
writetoeeprom=0;
devam=1;
while(devam)
{
infrared=~PORTD.F0;
if(buffer!=infrared)
{
if(!j){ timer=0; j=1;}
else
{
timepassed=timer;
timer=0;
eeprombuffer[i]=timepassed; //EEPROM_Write(0x00+i,timepassed);
i++;
}
buffer=infrared;
change=1;
}
else
{
change=0;
if(writetoeeprom)
{
PORTC.F1=~PORTC.F1;
writetoeeprom=0;
for(ii=0;ii<i;ii++)
{
EEPROM_Write(0x00+ii,eeprombuffer[ii]);
}
devam=0;
}
}
/*
|-----| |-----| |-----|
| | | | | |
____| |____| |____| |____
*/
}
while(1);
}
sahu said:can u it share asmably lang. & its fx. alsoFragrance said:hi
here you go it is based on pic16f84a
regards
Fragrance
bit infrared,buffer,j,change,writetoeeprom,devam,outputmode;
unsigned char timepassed=0,eeprombuffer[80];
volatile unsigned char i=0,ii=0;
volatile unsigned int timer=0,offtimer=0;
void receive(void);
void transmit(void);
void interrupt()
{
if(INTCON.T0IF)
{
timer++;
TMR0=200;
if(PORTD.F2)
{
TMR0=0xFF - eeprombuffer[ii++];
if(ii>=i) {INTCON.T0IE=0; outputmode=0; PORTC.F6=~PORTC.F6; }
if(outputmode)
{
PORTC.F5=~PORTC.F5;
CCPR1L = 0x08;
CCP1CON = 0x0C;
}
else
{
CCPR1L = 0;
CCP1CON = 0;
}
outputmode=~outputmode;
}
else if(!change && i>5 && devam)
{ offtimer++;
if(offtimer>1000){ writetoeeprom=1; INTCON.T0IE=0;}
}
}
INTCON.T0IF=0;
}
void main(){
//unsigned char measuretxt[7];
ANSEL = 0;
ANSELH = 0;
PORTA = 0;
PORTC = 0;
PORTD = 0;
TRISC = 0;
TRISD = 0b00000111;
OPTION_REG=0x88;
TMR0=200;
INTCON.T0IE=1;
INTCON.GIE=1;
/*
* PWM registers configuration
* Fosc = 20000000 Hz
* Fpwm = 37878.79 Hz (Requested : 38000 Hz)
* Duty Cycle = 25 %
* Resolution is 9 bits
* Prescaler is 4
* Ensure that your PWM pin (RC2) is configured as digital output
* see more details on [url]https://www.micro-examples.com/[/url]
* this source code is provided 'as is',
* use it at your own risks
*/
PR2 = 0b00100000 ;
T2CON = 0b00000101 ;
CCPR1L = 0; //0x08 ; // 0b00001000;
CCP1CON = 0; //0x0C ; // 0b00001100 ;
j=0;
//LCD_Init();
buffer=~PORTD.F0;
writetoeeprom=0;
devam=1;
outputmode=1;
while(1)
{
if(PORTD.F1) receive();
if(PORTD.F2) transmit();
}
}
void transmit(void)
{
if(!j)
{
i=EEPROM_Read(0x80);
for(ii=0;ii<i;ii++)
{
eeprombuffer[ii]=EEPROM_Read(0x00+ii);
}
j=1;
ii=0;
PORTC.F7=~PORTC.F7;
INTCON.T0IE=1;
TMR0=0;
}
}
void receive(void)
{
while(devam)
{
infrared=~PORTD.F0;
if(buffer!=infrared)
{
if(!j){ timer=0; j=1;}
else
{
timepassed=timer;
timer=0;
eeprombuffer[i]=timepassed; //EEPROM_Write(0x00+i,timepassed);
i++;
}
buffer=infrared;
change=1;
}
else
{
change=0;
if(writetoeeprom)
{
PORTC.F4=~PORTC.F4;
writetoeeprom=0;
for(ii=0;ii<i;ii++)
{
EEPROM_Write(0x00+ii,eeprombuffer[ii]);
}
EEPROM_Write(0x80,i);
devam=0;
j=0;
}
}
}
}
cebrax said:Hello again!
I finished the receive and store part. But I can't replay. Any help?
cebrax said:I already did that I think.. Do you think this is the problem?
Code:if(PORTD.F1) receive(); if(PORTD.F2) transmit();
cebrax said:I've completed the learning part, it can successfully store the delays(well, with some 10-20 usec error). Now replaying it is problem.. I don't have an oscilloscope that's why I can't see my output waveform. Can any one out there compile and look at the output?
mikroC PRO for PIC compiler
cebrax said:Proteus 7.4 SP3
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);
}
}
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?