KYP
Banned
Code:
#include <p18f4550.h>
#pragma config FOSC = HS // to select external osc
// #pragma config PWRT = ON // 62 ms waiting at start
// #pragma config WDT = OFF // watch dog timer off
#pragma config LVP = OFF
#pragma config PBADEN = OFF //PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config MCLRE = ON //MCLR pin enabled; RE3 input pin disabled
//END CONFIG
void Delay_ms( int ms )
{
int i;
for ( i = 0; i < ms; i++ )
Delay100TCYx ( 25 );
}
void main (void)
{
TRISE= 0b11111111;//sets PORTA as all inputs
TRISA= 0b00000000;//sets PORTB as all outputs
PORTA= 0b11111111;//turns off PORTB outputs so that the LED is initially off
while(1)
{
if (PORTEbits.RE0==0); //if switch goes low PORTBbits.RB4=1;//LED turns on
else
PORTAbits.RA0=0;//LED turns off
Delay_ms( 100000 );
}
}
Last edited by a moderator: