I am trying to write a basic program to turn on an LED when an input is high. I managed to make an LED flash thanks to people on this forum
, but I'm having trouble with my next simple program.
LED Flashing Program (works)
LED I/O Program (doesn't work)
I am making RA1 "high" by connecting it to +v through a 10k resistor. Is this correct?
LED Flashing Program (works)
Rich (BB code):
#include "htc.h"
#define _XTAL_FREQ 4000000
__CONFIG(FOSC_INTRC_NOCLKOUT & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & LVP_OFF & DEBUG_OFF & BOR4V_BOR40V & WRT_OFF);
int main(void) {
TRISA = 0b11111110; //RA0 is output, others are inputs
for(;;) {
RA0 = 1;
__delay_ms(100);
__delay_ms(100);
RA0 = 0;
__delay_ms(100);
__delay_ms(100);
}
}
Rich (BB code):
#include "htc.h"
#define _XTAL_FREQ 4000000
__CONFIG(FOSC_INTRC_NOCLKOUT & WDTE_OFF & PWRTE_ON & MCLRE_ON & CP_OFF & CPD_OFF & BOREN_OFF & IESO_OFF & FCMEN_OFF & LVP_OFF & DEBUG_OFF & BOR4V_BOR40V & WRT_OFF);
int main(void) {
TRISA = 0b11111110; //RA0 is output, others are inputs
for(;;) {
if(RA1 == 1){
RA0 = 1;
}
else {
RA0 = 0;
}
}
}