Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

OR command

Status
Not open for further replies.
How can i make something that works this way:
No matter of input i give it, it gives output 1. So for (1111=1, 0001=1, 0101=1 etc.)
And if input is 0000, it gives 0?

Or is there a way and how to programm that in C?

EDIT: and i am talking only about upper bits of one port. So this is for xxxxyyyy. Ys are 0-15 decimal, and it should be that way, only thing is that if that number is >15 (so xxxx!=0), than it should make xxxx=1, and if xxxx=0, then it is allright
 
Last edited:
I think what OP is looking for is

Pseudocode:
Code:
if (PORT & 0xf0) {
    output = 1;
}
else {
    output = 0;
}

So, if any of the upper bits in PORT is 1 then the output is 1. If all the upper bits in PORT are 0 the output is 0.
 
Last edited:
Ok, but those 3 were only examples. I dont want any of those bits to be 1.

And i dont know where to put that IF, because my code looks like this:

Code:
for (i=16;  i>0;  i--) {
     for (j=0; j<100; j++) {
          A(i);B1(i+4);C(i+8);D(i+12);
          }	
      }
if (i>16) {	
     PrintString("i would need to put 1 to one of my pins");	
    }
[MODNOTE]Use code tags! it makes it easier for viewing[/MODNOTE]
 
Last edited by a moderator:
Hm...maybe but..
I use lower 4 bits for my 4 to 16 decoder, so i need these 4 bits.
But if output of uC is higher than 16 (so it is not just yyyy, but xyyyy), than i want to "close" decoder and not show that lower yyyy bits, so is there a way to do that with the same port? Any of those xxxx pins are free, and i would 1 on any of them as output if my number is higher than 16 to put 5v on inhibit and not show anything

Here is a picture of it
View attachment 68931
 
Last edited:
you can do it in hardware, but if you have a spare port pin, you save yourself $$$ by doing it in software.
If i<16, set enable pin to 0, else (i>=16), set enable pin to 1 (assuming you are using a low enable).
that's the do this, do that of the above example. Your if statement is outside of your i loop, so i should always be 0 by the time you get to it, unless you are breaking from that statement. your if statement needs to be embedded in the i loop statement to be effective.

if this is a 1 of project, and you have spare $$$, buy the or gate and do it in hardware. But if you want to do it right, do it in software and use the spare port pin. NOTE: the enable pin doesn't have to be of the same port as your decoder address bits, but it can be. The less hardware you use, the simpler, cheaper, and easier to troubleshoot your project becomes (assuming, of course, there's no micro... troubleshooting software becomes a magnitude of order harder than simple hardware), but real engineer's try to lessen the cost where possible, and it ups the reliability. *IF* there's already a micro involved, use its logic when and where possible. Why leave unused port pins and add hardware, when that's really what a micro is, flexible hardware.

added note: and if you're using the or gate, you're also using 4 port pins on the enable/disable function, where doing it inside the micro, you only use 1 and you free up the other 3 pins.
 
Last edited:
Mike, you can see the code that's actually used in the following thread, along with the software solution: https://www.electro-tech-online.com/threads/strange-shadow-in-led-display.131718/#post1095832

The enable pin isn't even needed as of the 16 possible columns, only 12 are used; referring to a column the 12th results in all columns being disabled.

Obviously if the code was included in this thread there would have been a definitive answer here yesterday.
 
Mike, you can see the code that's actually used in the following thread, along with the software solution: https://www.electro-tech-online.com/threads/strange-shadow-in-led-display.131718/#post1095832

The enable pin isn't even needed as of the 16 possible columns, only 12 are used; referring to a column the 12th results in all columns being disabled.

Obviously if the code was included in this thread there would have been a definitive answer here yesterday.

Yep, that is my bad to not include it but ok, thank you once again to for code, but also look what is the other problem if you could help me with that

Yesterday, i bought cd4072 OR gate chip and put it in to my project and first it worked well, and then it stopped to work, and started to mix letters like it is not there. Then i bought another one, it was the same. I checked and it was all right with the wires.

Now, i just put the chip back on (and with your code, dougy83), and it works PERFECT :D no blinking, no mixing, nothing

I am worried, because i dont understand why, i understand that your code disable c to be higher than 12, but there were mixing as you can see in video, and now with soft, and hard solution it is good :D
 
Please see my response in your other thread
 
Status
Not open for further replies.

New Articles From Microcontroller Tips

Back
Top