Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

PIC18F4520 program to check input states

Status
Not open for further replies.

hussong1555

Member level 1
Joined
Jul 3, 2008
Messages
37
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Location
USA
Activity points
1,503
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.

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????
 

hussong1555

Member level 1
Joined
Jul 3, 2008
Messages
37
Helped
2
Reputation
4
Reaction score
0
Trophy points
1,286
Location
USA
Activity points
1,503
Thanks for the help, i will try it monday morning
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top