Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] Visitors Counter with PIC16F877A (2 photoresistors)

Status
Not open for further replies.

Larbi Rahmani

Newbie level 4
Newbie level 4
Joined
May 30, 2014
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
30
Hi,

I'm working on a visitors counter on 7 segments display, and when the number reaches 0 a relay is switched off.

but I'm running with some problems with simulation with proteus ISIS, and I couldn't know where the problem is:

Simulation: (I'm using 2 photoresistors)

Capture.JPG

code:
Code:
#define   Relay      RB7_bit

long  POT,POT2;

unsigned char ar[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90};


unsigned int compt = 0;


void interrupt()
{
 while(INTF)
 {

    while(POT>=125)
    {
        point1:
        if(POT2>=125)// check the direction from 1 to 2
        {
         if(compt<9)compt++;
         else compt = 9;
         Delay_ms(500);
         break;
        }
        else
        {
         goto point1;
        }
    }

    while(POT2>=125)
    {
       point2:
       if(POT>=125)// check the dirrection from 2 to 1
       {
         if(compt>0)compt--;
         else compt = 0;
         Delay_ms(500);
         break;
       }
        else
        {
         goto point2;
        }
    }

   INTF_bit = 0;// clear flag
   break;
 }
}

void main(){

TRISA0_bit = 1;//set as input
TRISA1_bit = 1;// set as input

TRISB7_bit = 0;// set as output

TRISB=0x00;
ADCON0 = 0x05;

  // interrupt settings...
  GIE_bit = 1;// Enable global interrupt
  INTE_bit = 1;// Enable external interrupt
  INTEDG_bit = 0;// interrupt on falling edge
  INTF_bit = 0;


   PORTB=ar[compt];
   
    
  while(1)
  {    
    delay_ms(500);
  POT = ADC_Read(0);
  POT = POT*255/1023;
  
  POT2= ADC_Read(1);
  POT2= POT2*255/1023;


            if(compt>0)
            Relay = 1;

            else
            Relay = 0;
            
   PORTB=ar[compt];
  }
}

Can you help please, because number isn't incrementing.
 

What causes an interrupt? The photocell input?

I'm not familiar with proteus, but I would verify that the interrupt routine actually gets called.
 

What causes an interrupt? The photocell input?

I'm not familiar with proteus, but I would verify that the interrupt routine actually gets called.

When someone crosses the first photoresistor then the second the counter increases. and vise versa.
 

Frpm your design i can see that your Relay is incomplete, supply the relay! or will you use Red and blue code to determine your results?

yes I'm just testing, but the counter didn't start no metter what configuration I make, I can't see where the problem is.
 

as i saw in interrupt u have keep pointer in while loop twise. so this should not ne done in interrupt routine??
and what exactly problem u r facing?????
 

as i saw in interrupt u have keep pointer in while loop twise. so this should not ne done in interrupt routine??
and what exactly problem u r facing?????

I based my simulation on this blog post:
**broken link removed**

he is using it with no problems
 

hello,


INTF is RB0 interrupt... with RB0 as input , but connected to 7segment display ???
Never use "While" loop and "goto" inside an interrupt.. very bad habit.

Impossible to follow your mind !
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top