Ishah
Member level 1
- Joined
- Mar 13, 2013
- Messages
- 33
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,502
Hi everyone,
I still got problems in my project, which I want to control LED with switch. But here nothing happen to PORTB.
Can anyone check my circuit in ISIS and my code.
Thanks.
I still got problems in my project, which I want to control LED with switch. But here nothing happen to PORTB.
Can anyone check my circuit in ISIS and my code.
Code:
/*
Project Title: Controled LED by switches
*/
void main()
{
TRISA=0XFF; //Configure all bit of PORTA as input
TRISB=0X00; //Configure all bit of PORTB as output
PORTA=0X00; // Clear bits to zero
PORTB=0X00; // Clear bits to zero
CMCON=0X07; // or CMCON register = 0X00000111
ADCON1=0X07; // Configure ADCON1, or ADCON1=0X06;
while (1);
{
if( TRISA.F0 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F0 == 1) //If the switch is pressed
PORTB.F0 = ~PORTB.F0; // Toggle LEDs on PORTB.0
Delay_ms(500); // Delay 1000 ms
}
}
else
if (TRISA.F1 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F1 == 1) //If the switch is pressed
PORTB.F1 = ~PORTB.F1; // Toggle LEDs on PORTB.1
Delay_ms(500); // Delay 1000 ms
}
}
else
if(TRISA.F2 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F2 == 1) //If the switch is pressed
PORTB.F2 = ~PORTB.F2; // Toggle LEDs on PORTB.2
Delay_ms(1000); // Delay 1000 ms
}
}
else
if(TRISA.F3 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F3 == 1) //If the switch is pressed
PORTB.F3 = ~PORTB.F3; // Toggle LEDs on PORTB.3
Delay_ms(1000); // Delay 1000 ms
}
}
else
if(TRISA.F4 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F4 == 1) //If the switch is pressed
PORTB.F4 = ~PORTB.F4; // Toggle LEDs on PORTB.4
Delay_ms(1000); // Delay 1000 ms
}
}
else
if(TRISA.F5 == 1) //If the switch is pressed
{
{
Delay_ms(30);
if( TRISA.F5 == 1) //If the switch is pressed
PORTB.F5 = ~PORTB.F5; // Toggle LEDs on PORTB.0
Delay_ms(1000); // Delay 1000 ms
}
}
}
}
Thanks.