fantabulous68
Member
PIC16f690, initialisation of ports, LEDS,reading from a pin
I want an LED connected to pin RAO to glow if pin RA1==0
when i run my code the LED keeps pulsing on and off regardless of what value RA1 equals to.
could someone plz help me. Thanks
I want an LED connected to pin RAO to glow if pin RA1==0
when i run my code the LED keeps pulsing on and off regardless of what value RA1 equals to.
could someone plz help me. Thanks
Code:
#include <pic.h>
#include "pic.h"
#include "delay.h"
#include "math.h"
#include <stdio.h>
#include <stdlib.h>
void init(void)
{
TRISB=0x00;
TRISC=0xFC;
ANSEL=0; // Set inputs to digital
TRISA=0x02; //making pin RA1 input
}
void main(void)
{
init(); // initialise I/O ports, LCD
while(1) // Loop forever
{
if(RA1==0) //if receiver detects something then output is active low
{PORTA=0x01;} //light up led connected to RA0 if detect object
else
{PORTA=0x00;} //dont light led if no detection
}
}