I have purchased my for PIC16F18875 and a PICKIT3 programmer.
I have everything set up and am able to compile and program no problem.
I am completely new to this and finding it a little confusing as to what works with what pic. I have found that :
TRISBbits.TRISB0 = 0; //Set Port B Bit 0 as output, works for me as PORTBbits etc
I managed to get the standard LED and LED flashing beginner programmes to work but I can not work out how to get the led to go on and off dependant on the input from another pin.
Below I have set B0 as the output to an LED and D1 as the input switch.
I assume by connecting D1 to the 5V rail then this would activate the pin and make the LED illuminate. No matter what I do the input has no effect on the LED.
What am I doing wrong? Please be kind as I have only just started. I have watched loads of videos and followed tutorials but just cant figure it out.
#include <xc.h>
#define _XTAL_FREQ 8000000
void main(void)
{
TRISBbits.TRISB0 = 0; //Set Port B Bit 0 as Output
TRISDbits.TRISD1 = 1; // Set Port A Bit 0 as Input
while (1)
{
if (LATDbits.LATD1==1)
{
__delay_ms(200);
if (LATDbits.LATD1==1)
{
LATBbits.LATB0=1;
}
}
}
}
I have everything set up and am able to compile and program no problem.
I am completely new to this and finding it a little confusing as to what works with what pic. I have found that :
TRISBbits.TRISB0 = 0; //Set Port B Bit 0 as output, works for me as PORTBbits etc
I managed to get the standard LED and LED flashing beginner programmes to work but I can not work out how to get the led to go on and off dependant on the input from another pin.
Below I have set B0 as the output to an LED and D1 as the input switch.
I assume by connecting D1 to the 5V rail then this would activate the pin and make the LED illuminate. No matter what I do the input has no effect on the LED.
What am I doing wrong? Please be kind as I have only just started. I have watched loads of videos and followed tutorials but just cant figure it out.
#include <xc.h>
#define _XTAL_FREQ 8000000
void main(void)
{
TRISBbits.TRISB0 = 0; //Set Port B Bit 0 as Output
TRISDbits.TRISD1 = 1; // Set Port A Bit 0 as Input
while (1)
{
if (LATDbits.LATD1==1)
{
__delay_ms(200);
if (LATDbits.LATD1==1)
{
LATBbits.LATB0=1;
}
}
}
}