hussong1555
Member level 1
I wrote the following code for C18 compiler. basically what I am trying to accomplish is the have an LED light up at RD0 when RA0 is high then turn off when RA0 is low. then the same for RD1 and RA1.
what I am getting is LED 0 and 1 are always on regardless of the state of RA0 and RA1. Where am I going wrong????
Code:
#define HI 1
#define LO 0
//Header files
#include <p18f45k20.h>
#include <delays.h>
//Define variables
char servoA_status;
char servoB_status;
char LED_A;
char LED_B;
void main(void)
{
TRISA = 0b00000011; //PORTA bit 7:2 to output (0); bits 1:0 are inputs (1)
TRISB = 0b00000000; //PORTB bit 7:0 to output (0);
TRISC = 0b00000000; //PORTC bit 7:0 to output (0);
TRISD = 0b00000000; //PORTD bit 7:0 to output (0);
LATA = 0b00000000; //set all outputs to low
LATB = 0b00000000; //set all outputs to low
LATC = 0b00000000; //set all outputs to low
LATD = 0b00000000; //set all outputs to low
while (1)
{
LATDbits.LATD7 = ~LATDbits.LATD7; // toggle LATD
// Delay1KTCYx(50); // Delay 50 x 1000 = 50,000 cycles; 200ms @ 1MHz
servoA_status=PORTAbits.RA0;
servoB_status=PORTAbits.RA1;
if (servoA_status=HI)
{
LATDbits.LATD0 = HI; // turn on LED
// Delay10KTCYx(50); // Delay 50 x 10000 = 500,000 cycles; 2000ms @ 1MHz
}
else
LATDbits.LATD0 = LO; // turn off LED
if (servoB_status=HI)
{
LATDbits.LATD1 = HI; // turn on LED
// Delay10KTCYx(50); // Delay 50 x 10000 = 500,000 cycles; 2000ms @ 1MHz
}
else
LATDbits.LATD1 = LO; // turn off LED
}
}
what I am getting is LED 0 and 1 are always on regardless of the state of RA0 and RA1. Where am I going wrong????