Maker Pro
Maker Pro

Very Simple Circuit but cannot work! Please help.

JayJoe

Jul 31, 2015
12
Joined
Jul 31, 2015
Messages
12
void initiate_main()
{
trisa=1; porta=0;
trisd=0; portd=0;

}

void main()
{
initiate_main();
while(1)
{
if(porta.f0==1)
{
portd.f0=1;
}

else
{
portd.f0=0;
}
}
}

What's wrong with the programming?
 

Attachments

  • Untitled.png
    Untitled.png
    28.9 KB · Views: 108

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
portd.f0 = 0 or 1, but the LED is on portb.
Either change the HW port of the assignment in the SW.
 

JayJoe

Jul 31, 2015
12
Joined
Jul 31, 2015
Messages
12
oh, i uploaded the wrong picture. anyway, stick with this circuit ive uploaded, even ive change the programming code to port b, it still doesnt work!
 

Harald Kapp

Moderator
Moderator
Nov 17, 2011
13,700
Joined
Nov 17, 2011
Messages
13,700
The programming seems o.k.
Is the oscillator running? Is the power supply o.k.? Is the LED in the correct orientation (short leg = cathode to ground)?
 

JayJoe

Jul 31, 2015
12
Joined
Jul 31, 2015
Messages
12
Ive found the answer. Port A cannot be input. It turns out working when i use port D as input. can anybody tell me why?
 

JayJoe

Jul 31, 2015
12
Joined
Jul 31, 2015
Messages
12
Hmm. I am thinking the same too, but it works using port d instead of port a. Still wondering.
Sorry that i'm still new to PIC, thanks for your reply.
Anyway, may i know the word 'TRIS' stands for?
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
Hmm. I am thinking the same too, but it works using port d instead of port a. Still wondering.
Sorry that i'm still new to PIC, thanks for your reply.
Anyway, may i know the word 'TRIS' stands for?
I believe it means "Tri-State" Register. IE a port that can have one of 3 states. High (5V), Low(0V) or Open(Hi Z).

Chris
 

davenn

Moderator
Sep 5, 2009
14,254
Joined
Sep 5, 2009
Messages
14,254
Anyway, may i know the word 'TRIS' stands for?

from this www site ..... http://www.mikroe.com/chapters/view/16/chapter-3-pic16f887-microcontroller/

3.3 INPUT/OUTPUT PORTS
In order to synchronize the operation of I/O ports with the internal 8-bit organization of the microcontroller, they are, similar to registers, grouped into five ports denoted by A, B, C, D and E. All of them have several features in common:

  • For practical reasons, many I/O pins are multifunctional. If a pin performs any of these functions, it may not be used as a general-purpose input/output pin.
  • Every port has its ‘satellite’, i.e. the corresponding TRIS register: TRISA, TRISB, TRISC etc. which determines the performance of port bits, but not their contents.
By clearing any bit of the TRIS register (bit=0), the corresponding port pin is configured as an output. Similarly, by setting any bit of the TRIS register (bit=1), the corresponding port pin is configured as an input. This rule is easy to remember 0 = Output, 1 = Input.

fig3-35.gif

PORTA and TRISA register
Port A is an 8-bit wide, bidirectional port. Bits of the TRISA and ANSEL registers control the Port A pins. All Port A pins act as digital inputs/outputs. Five of them can also be analog inputs (denoted by AN):

fig3-36.gif


Dave
 

CDRIVE

Hauling 10' pipe on a Trek Shift3
May 8, 2012
4,960
Joined
May 8, 2012
Messages
4,960
I love the graphics on the MikroElectronika website.

Chris
 

JayJoe

Jul 31, 2015
12
Joined
Jul 31, 2015
Messages
12
I believe it means "Tri-State" Register. IE a port that can have one of 3 states. High (5V), Low(0V) or Open(Hi Z).

Chris
Oh, tri-state. Thanks. May I know what do you mean by 'Open(Hi Z)'?
 

JayJoe

Jul 31, 2015
12
Joined
Jul 31, 2015
Messages
12
from this www site ..... http://www.mikroe.com/chapters/view/16/chapter-3-pic16f887-microcontroller/

3.3 INPUT/OUTPUT PORTS
In order to synchronize the operation of I/O ports with the internal 8-bit organization of the microcontroller, they are, similar to registers, grouped into five ports denoted by A, B, C, D and E. All of them have several features in common:

  • For practical reasons, many I/O pins are multifunctional. If a pin performs any of these functions, it may not be used as a general-purpose input/output pin.
  • Every port has its ‘satellite’, i.e. the corresponding TRIS register: TRISA, TRISB, TRISC etc. which determines the performance of port bits, but not their contents.
By clearing any bit of the TRIS register (bit=0), the corresponding port pin is configured as an output. Similarly, by setting any bit of the TRIS register (bit=1), the corresponding port pin is configured as an input. This rule is easy to remember 0 = Output, 1 = Input.

View attachment 21240

PORTA and TRISA register
Port A is an 8-bit wide, bidirectional port. Bits of the TRISA and ANSEL registers control the Port A pins. All Port A pins act as digital inputs/outputs. Five of them can also be analog inputs (denoted by AN):

View attachment 21241
Dave

Great. Now I understand better. Thanks for the website davenn! :)
 
Last edited:

jayanthd

Jul 4, 2015
43
Joined
Jul 4, 2015
Messages
43
Try this code in your mikroC PRO PIC Compiler and it will work. If you have used 4 MHz crystal then select XT for Oscillator typr in edit project dialog box else choose HS.

Code:
void initiate_main()
{
    cmcon = 7;
    cvrcon = 0;
    adcon1 = 0x87;
    trisa = 1;
    porta = 0;
}

void main()
{
    initiate_main();
    delay_ms(200);

    while(1)
    {
        if(porta.f0 == 1)
        {
            delay_ms(50);
            if(porta.f0 == 1)
            {
                portd.f0 = 1;
            }
        }
        else if(porta.f0 == 0)
        {
            delay_ms(50);
            if(porta.f0 == 0)
            {
                portd.f0 = 0;
            }
        }
    }
}
 
Top