0

On this circuit and code, I tried to make a counter that when no one pass through (for example it is a passage at the metro station), there will read 1 value at RC7 lead of the processor. If someone pass through the signal change to 0. And program will count the how many people pass away over there and show the number of people on the 7-Segment LCD until 10. When 10 people pass through of the passage, the LED (D1) will be blinking for 1 seconds.

I tried to write a code about this algorithm, and when I load it to Pic18F45K22 but, it is not working. Proteus show error message like,

[PIC18] PC=0x0000. $MCLR$ is low. Processor is in reset. [U1]

The circuit that I designed given at below Figure 1:

Figure 1

The solutions that I tried:

  1. I used pull-up resistors. It did not work.
  2. We describe the frequency value in Micro C code. It did not work.

And the algorithm given at below:

#include <xc.h>
#define _XTAL_FREQ 4000000



unsigned char x=0;
void MSDelay(unsigned int);
void main()
{
    TRISC=0xff;
    TRISA=0x00;
    while(1)
    {
        if (PORTC==0)
        {
            x++;
            MSDelay(200);
        }
        if (x==1)
        {
            PORTA==0x3f;
        }
        if (x==2)
        {
            PORTA==0x06;
        }
        if (x==3)
        {
            PORTA==0x5b;
        }
        if (x==4)
        {
            PORTA==0x4f;
        }
        if (x==5)
        { 
            PORTA==0x66;
        }
        if (x==6)
        {
            PORTA==0x6d;

        }
    }

}

void MSDelay(unsigned int itime){                   //for delay
    unsigned int i;
    unsigned int j;
    for(i=0;i<itime;i++){
        for(j=0;j<165;j++){
        }
    }

}
Mike
  • 4,041
  • 6
  • 20
  • 37
kkrgzz
  • 452
  • 4
  • 12
  • I write on the code the counter if statement until 6. It is not a problem and the other thing is, when I determine x variable by int it is still not working. – kkrgzz May 05 '21 at 21:36
  • I solved the problem with adding external osscilator to microprocessor. – kkrgzz May 05 '21 at 21:42
  • 1
    Write an answer and don't edit your question as an answer!!! – Mike May 06 '21 at 06:08

1 Answers1

1

So I make the answer for you:
The error ist here:

if (x==1)
    {
        PORTA==0x3f;
    }

If you want assign a value you need = and not ==

    if (x==1)
    {
        PORTA=0x3f;
    }
Mike
  • 4,041
  • 6
  • 20
  • 37
  • 1
    Thanks for answer, I didn't have any time to explain my error. I'm sorry but I'll explain soon. – kkrgzz May 12 '21 at 15:31