Continue to Site

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.

[PIC] WTA Mode selection code (C code)

Status
Not open for further replies.

alpha91

Full Member level 3
Joined
Sep 23, 2011
Messages
168
Helped
1
Reputation
2
Reaction score
2
Trophy points
1,298
Activity points
2,625
Hi all, I am trying to write a code for PIC so that it can carry out different function depends on setting mode.

Default mode: both LED blinking
Mode 1 : LED 1 is blinking
Mode 2 : LED 2 is blinking

But my code doesnt work as what i thought. I am using IF statement
my code is as below:

void main () {

unsigned char MODE1;
CMCON = 0x07;
TRISA = 0x11;
TRISB = 0x00;
MODE1 = 0x00;


while (1){
if (PORTA.F0 == 1) // if button 1 is press
{
delay_ms (50);
if ( PORTA.F0 == 1) // if button 1 is press
{
if (MODE1 == 0x02) // if current mode is 02
{
MODE1 = 0x00; // reset mode to 00
}

else {
MODE1 ++; // else mode is switch to next mode
}
}
}

if (MODE1 == 0x01) // if mode is 01
{
PORTB = 0x01; // LED 2 is blinking
delay_ms (500);
PORTB = 0x00;
delay_ms (500);
}
if (MODE1 == 0x02) // if mode is 02
{
PORTB = 0x02; //LED 1 is blinking
delay_ms (500);
PORTB = 0x00;
delay_ms (500);
}
else //else mode
{
PORTB = 0x03; // both LED is blinking
delay_ms (500);
PORTB = 0x00;
delay_ms (500);
}
}
}

Can anyone tell me what did i do wrong?
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top