Hi - I'm trying to get to grips with programming micro-controllers using c before I go to Uni next year. I'm doing a view tasks on the internet and have written a program to simply turn an led on and off as a biased switch is pressed. I was wondering how I could write a similar program to transfer the state of the lower 5 dil switches (RC0 to RC4) to LEDs (RA0 to RA4) without allowing RC5 to affect anything.
/*
A program that causes an LED, connected to RA0,
to go on and off as the biased switch,
connected to RC6, is closed and opened.
All other LEDs (connected to RA1 to RA4) and the buzzer (RA5)
should be off.
/*
#include <p18f2221.h>
#pragma config OSC=HS /* 0.4us cycle time with 10MHz osc */
#pragma config WDT=OFF
#define Switch PORTCbits.RC6
#define LED PORTAbits.RA0 void main(void){
ADCON1=0x0f; /* digital IO */
TRISA=0xc0; /* 6 LEDs as outputs */
TRISC=0xff; /* PORTC as inputs */
PORTA=0x00; /* all LEDs off */
while(1){ /* forever */
if(Switch) /* is switch open (non zero)*/
LED=0;
else
LED=1; /* turn LED on */
}
}
Any of your help and time would be much appreciated.