Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

switch case help!!!!

Status
Not open for further replies.

paddy_p

Member level 2
Joined
May 31, 2012
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Mumbai India
Activity points
1,669
Hello,

I am using switch case function in code.

Can i use multiple statements in each case or it should be single statement in each case?

thanks,
paddy
 

paddy_p

Member level 2
Joined
May 31, 2012
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Mumbai India
Activity points
1,669
Please refer below mentioned code

Code:
switch(i)
            {
               case 0:
               output_high(pin_B7);        //turn on LED               
               output_high(pin_A2);        //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               output_low(pin_B7);        //turn off LED               
               output_high(pin_A2);       //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               break; 
               
               case 1:
               output_high(pin_B6);               
               output_high(pin_A2);        //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               output_low(pin_B6);               
               output_high(pin_A2);        //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               break;
        }
Is it valid?
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
can u post the full code and what is excepted output......
 

paddy_p

Member level 2
Joined
May 31, 2012
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Mumbai India
Activity points
1,669
I am just checking for alarm condition and if it occurs i have to blink the LED.

To do this i am toggling port pins in every case.

So i have written same cases for 8 values.
 

jjeevan007

Full Member level 5
Joined
Apr 13, 2012
Messages
311
Helped
44
Reputation
88
Reaction score
43
Trophy points
1,308
Location
bangalore
Activity points
2,781
the code looks fine but what is output u are getting now
 

paddy_p

Member level 2
Joined
May 31, 2012
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Mumbai India
Activity points
1,669
I just want to confirm that switch case supports multiple statements or not.

And i don't have hardware ready with me to check the output.
 

Tahmid

Advanced Member level 5
Joined
Jun 17, 2008
Messages
4,758
Helped
1,791
Reputation
3,574
Reaction score
1,650
Trophy points
1,393
Location
Silicon Valley, California, USA (from Dhaka, Bangl
Activity points
30,545
Please refer below mentioned code

Code:
switch(i)
            {
               case 0:
               output_high(pin_B7);        //turn on LED               
               output_high(pin_A2);        //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               output_low(pin_B7);        //turn off LED               
               output_high(pin_A2);       //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               break; 
               
               case 1:
               output_high(pin_B6);               
               output_high(pin_A2);        //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               output_low(pin_B6);               
               output_high(pin_A2);        //clock to latch
               delay_us(100);
               output_low(pin_A2);
               delay_us(100);
               break;
        }
Is it valid?


Yes, it's fine.

I like to keep the statements in the case within parentheses. But, that's a matter of personal preference and isn't necessary. Your code is fine.
 

paddy_p

Member level 2
Joined
May 31, 2012
Messages
47
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,288
Location
Mumbai India
Activity points
1,669
Hello,

I have to make an indication device which has 120 LED's.

I have connected that LED's to one port of micro controller via 74HCT574 and ULN2004.

i.e Micro controller port -> 74HCT574-> ULN2004 -> LED's

For 120 LED's I have used multiple 74HCT574 IC'c and ULN2004 IC's.

I am sending common data on all 74HCT574 and enabling particular 74HCT574 by giving clock to it.

Is this circuit okay? And should I get enough intensity?

Please suggest.

thanks,
paddy
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top