jpsganesh
Full Member level 3
- Joined
- Aug 17, 2009
- Messages
- 175
- Helped
- 22
- Reputation
- 44
- Reaction score
- 21
- Trophy points
- 1,298
- Location
- India
- Activity points
- 2,286
// SENSOR GIVES LOGIC 1 AT NO ACTIVITY
////////////////////initialization//////////////////
#include "16f877a.h"
#org 0x1F00, 0x1FFF void loader16F877a(void) {} //protect bootloader code for the 8k 16F876/7
#fuses nowdt,noput,nobrownout
#use delay(clock=4000000)
////////////////////////////////////////////////////
#byte port_a = 0x05
#byte port_b = 0x06
#byte port_c = 0x07
#byte port_d = 0x08
#bit ir=port_a.1
#bit led1=port_b.0
#bit led2=port_b.1
#bit led3=port_b.2
#bit led4=port_b.3
#bit led5=port_b.4
#bit led6=port_b.5
#bit led7=port_b.6
#bit led8=port_b.7
#bit led9=port_d.5
#bit led10=port_d.4
/////////////////////////////////////////////////////\
char i,command,data;
int1 x;
////////////////////////////////////////////////////
char read_ir (void);
int1 process_ir_bit(void);
////////////////////////////////////////////////
void main (void)
{
set_tris_d(0x00);
set_tris_b(0x00);
port_b=0xff;
port_d=(0b00110000);
for(;;)
{
command=0x00;
while(ir==1);//start bit
while(ir==0);//start bit
while(ir==1);//start bit
for(i=0;i<16;i++)
{
while(ir==0);//address
while(ir==1);//address
}
///////////////command////////////////////////////////////
for(i=0;i<8;i++)
{
x=process_ir_bit();
if(x) {bit_Set(command,i); while(ir);while(ir==0);}
else {bit_clear(command,i);while(ir==0);}
}
////////////////data/////////////////////////////////////////
for(i=0;i<8;i++)
{
x=process_ir_bit();
if(x) {bit_Set(data,i); while(ir);while(ir==0);}
else {bit_clear(data,i);while(ir==0);}
}
//////////////////////////////////////////////////////////////
if(data==03) led1=~led1;
else if(data==07) led2=~led2;
else if(data==11) led3=~led3;
else if(data==15) led4=~led4;
else if(data==19) led5=~led5;
else if(data==23) led6=~led6;
else if(data==27) led7=~led7;
else if(data==31) led8=~led8;
else if(data==35) led9=~led9;
else if(data==39) led10=~led10;
else delay_ms(500);
delay_ms(100);
}
}
/////////////////////////////////////////////////////////
int1 process_ir_bit(void)
{
delay_us(300);
delay_us(560);
if(ir) return 1;
else return 0;
}
I changed entire logic which will not read repeat pulse and will not get hang in while loop and along with EXT INT RB0. Finally it's working now. Next I'm going to try to decode Sony IR Remote (Sony Protocol).
I changed entire logic which will not read repeat pulse and will not get hang in while loop and along with EXT INT RB0. Finally it's working now. Next I'm going to try to decode Sony IR Remote (Sony Protocol).
static void interrupt
isr(void)
{
RB2=0; // LED blink for test
if(INTF) // wait for RB0 to go Low - EXT INT
{
// Read Start Pulse
// for(on=0;RB0==0 && on<=50000 ;on++)
on=0; while(RB0==0 && on<=2500) on++;
// Measure Start Pulse - if start pulse on time is ~9ms
if(on>=2000 && on<=2200)
{
//RB2=0;
temp=0; while(RB0==1 && temp<=2500) temp;
// Measure Start Pulse - if start pulse off time is ~4.5ms
if(temp>=1000 && temp<=1200)
{
// Read Address Pulse
for(i=0;i<8;i++)
{
temp=0; while(RB0==0 && temp<=2500) temp;
adrs[i]=0; while(RB0==1 && adrs[i]<=2500) adrs[i]++;
}
// Read Inverted Address Pulse
for(i=0;i<8;i++)
{
temp=0; while(RB0==0 && temp<=2500) temp;
adrs1[i]=0; while(RB0==1 && adrs1[i]<=2500) adrs1[i]++;
}
// Read Command Pulse
for(i=0;i<8;i++)
{
temp=0; while(RB0==0 && temp<=2500) temp;
dat[i]=0; while(RB0==1 && dat[i]<=2500) dat[i]++;
}
// Read Inverted Command Pulse
for(i=0;i<8;i++)
{
temp=0; while(RB0==0 && temp<=2500) temp;
dat1[i]=0; while(RB0==1 && dat1[i]<=2500) dat1[i]++;
}
// Convert Address Time to Binary
lcd_command(0x01);
for(i=0;i<8;i++)
{
adrs[i]=(adrs[i]>150)? 1 : 0;
lcd_command(0x88-i-1);
lcd_data(adrs[i]+0x30);
}
// Convert Command Time to Binary
for(i=0;i<8;i++)
{
dat[i]=(dat[i]>150)? 1 : 0;
lcd_command(0xC8-i-1);
lcd_data(dat[i]+0x30);
}
// Convert Inv Cmd Time to Binary
// for(i=0;i<8;i++)
// {
// dat1[i]=(dat1[i]>150)? 1 : 0;
// lcd_command(0xC8-i-1);
// lcd_data(dat1[i]+0x30);
// }
// Binery to Decimal Convertionv - Address
address=0;
for(i=0;i<8;i++){
if(adrs[i]==1){
char power=1;
for(char j=0; j<i; j++){
power*=2;
}
address+=power;
}
}
// Binery to Decimal Convertion - Command
cmd=0;
for(i=0;i<8;i++){
if(dat[i]==1){
char power=1;
for(char j=0; j<i; j++){
power*=2;
}
cmd+=power;
}
}
// cmd1=0;
// for(i=0;i<8;i++){
// if(dat1[i]==1){
// char power=1;
// for(char j=0; j<i; j++){
// power*=2;
// }
// cmd1+=power;
// }
// }
}
// Display Decimal value on LCD
lcd_command(0x8A);
temp1=address;
disp();
lcd_command(0xCA);
temp1=cmd;
disp();
// lcd_command(0xCA);
// temp1=cmd1;
// disp();
}
}
INTF=0;
RB2=1;
}
Sorry for the delayed response. Today only I got chance to check this forum. I'm at customer place now. By this month end I'll go back to my home and share u the code from my old backup. However my code hangs somewhere sometime after that I couldn't work on that. Meanwhile if u need any help let me know or u can share ur code so that I/someone can go through and debug it.
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?