How to read PIR sensor on Port C Pin4 ?

Go To Last Post
5 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys,

I want to detect PIR on PC4,

I have created like below but got no proper response yet, any ideas ?

#define PIR_PIN PINC   //PIR input port
#define PIR	PC4 

DDRC = 0x70;  
if (bit_is_set(PIR_PIN, PIR))
		{
			lcd_string("PIR is detecting!");
		}

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Have you checked that the correct voltage levels are on the pin?
Is there alternate functions on that pin like JTAG? You didn't tell us what AVR you're referring to. If there is jtag, you'll have to disable it - see the relevant datasheet.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
DDRC = 0x70; 

You have made PC4 an output!

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

suppose to be 0xE0 ? thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

suppose to be 0xE0 ?

You never fail to amaze, bianchi77..

How can we possibly know what is on the other pins on your PORTC?
How could we then say anything about the other bits of the DDRC register?

All we can say is that if you want to handle port C pin 4 as an input, then the corresponding bit in DDRC must not be 1, but 0.

I.e. the DDRC value must be, in binary

???0????

where the question marks can not be known to us. There are 128 possible values of DDRC where bit 4 is zero. With the information you've given any of these values will do:

0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF, 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF

Yes, 0xE0 is one of those. Have you tried it? :roll:

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]