Simple input/output not working ??

General discussion on mikroC.
Post Reply
Author
Message
mibole
Posts: 5
Joined: 28 Oct 2011 13:12

Simple input/output not working ??

#1 Post by mibole » 28 Oct 2011 13:38

Hi. I'm fairly new to pic programming, and was wondering why my program doesn't work.
I have attached an LED on portD4, and I want it on if D3 is 1. So to test this, I made to setup in the attached image. The code is the following:

Code: Select all

void main() {
  TRISD = 0b00001000;
  LATD.F0 = 1;
  while(1) {
    LATD.F4 = LATD.F3;
  }
}
It doesn't matter if I put LATD.F0 to 1 or 0, the LED doesn't light up.
Can someone help clarify this?
Thanks :-)
Attachments
schematic.jpg
schematic.jpg (37.17 KiB) Viewed 1826 times

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Simple input/output not working ??

#2 Post by janko.kaljevic » 31 Oct 2011 12:27

Hello,

Please try with this:

Code: Select all

  while(1) {
    LATD4_bit = RD3_bit;
  }
And check your connection between LED diode and PIC. There should be resistor.

Best regards.

mibole
Posts: 5
Joined: 28 Oct 2011 13:12

Re: Simple input/output not working ??

#3 Post by mibole » 31 Oct 2011 15:45

Thanks for your answer. Unfortunately, I got a compiler error:

"Undeclared identifier [LATD4_bit] in expression"

Any idea? Thanks.

... and yes, I needed a current limiting resistor. Thanks :-)

User avatar
janko.kaljevic
Posts: 3565
Joined: 16 Jun 2011 13:48

Re: Simple input/output not working ??

#4 Post by janko.kaljevic » 01 Nov 2011 10:39

Hello,

I apologize, LATD4_bit was implemented in PRO version of compiler.
Please use LATD.F4 instead.

Best regards.

mibole
Posts: 5
Joined: 28 Oct 2011 13:12

Re: Simple input/output not working ??

#5 Post by mibole » 01 Nov 2011 20:05

Thanks, but I still have the problem.
Do you know if there is some register I need to set?
Thanks.

mibole
Posts: 5
Joined: 28 Oct 2011 13:12

Re: Simple input/output not working ??

#6 Post by mibole » 05 Nov 2011 20:10

SOLVED!
Figured it out. Needed to be PORT instead of LAT when reading from the pin.

Code: Select all

void main() {
  TRISD = 0b00001000;
  LATD.F0 = 1;
  while(1) {
    LATD.F4 = PORTD.F3;
  }
}

Post Reply

Return to “mikroC General”