X4ROY
Newbie level 6
i am using pic16f877a the aim of this program is to make a simple sensor i have an LDR light resistance around 1k ohms and dark resistance around 600k ohms .... when i cover the ldr i want there to be a low in the inpt and one particular group of leds glow and when i leave it open to light i want there to be a high at pin ra3 and the other set of leds glow ...
connections :
rb0 to rb3 pins connected led and resistor and to ground with proper polarities .
same for rb4 to rb7 pins ...
input side :
i connected 5v pin to one end of ldr the other end to ra3 pin ... it simply doesnt work i mean none of the if cases work no leds are glowing ....
code :
#include<htc.h>
#include<pic.h>
__CONFIG(HS & LVPDIS & UNPROTECT & WDTDIS);
void main(void)
{
TRISA=1x00;
TRISB=0x00;
PORTB=0b00000000;
for(;
{if(PORTA=0b00000000)
{PORTB = 0b11110000
else if (PORTA=0b00010000)
{PORTB = 0b00001111;}
}}
}
Added after 45 seconds:
hey that for loop there its an infinite for loop ... that symbol came of somehow
Added after 2 minutes:
i have no clue how to use trisa =1 i mean implement inputs ... if i put some voltage to an input port it must be high am i right ???
and if i dont put any voltage it shud be low is my understanding right ??
connections :
rb0 to rb3 pins connected led and resistor and to ground with proper polarities .
same for rb4 to rb7 pins ...
input side :
i connected 5v pin to one end of ldr the other end to ra3 pin ... it simply doesnt work i mean none of the if cases work no leds are glowing ....
code :
#include<htc.h>
#include<pic.h>
__CONFIG(HS & LVPDIS & UNPROTECT & WDTDIS);
void main(void)
{
TRISA=1x00;
TRISB=0x00;
PORTB=0b00000000;
for(;
{if(PORTA=0b00000000)
{PORTB = 0b11110000
else if (PORTA=0b00010000)
{PORTB = 0b00001111;}
}}
}
Added after 45 seconds:
hey that for loop there its an infinite for loop ... that symbol came of somehow
Added after 2 minutes:
i have no clue how to use trisa =1 i mean implement inputs ... if i put some voltage to an input port it must be high am i right ???
and if i dont put any voltage it shud be low is my understanding right ??