I'm new in the C language and im trying to make a luck fortune with leds, it will &quot;spin&quot; blinking the 8 leds in order and then blink only the winner one but i dont know if i can do it in C without making a case switch for every P2OUT of the microcontroller (the interrupt is because it will interact with a bluetooth module across with a cellphone application ) #include &lt;msp430g2553.h&gt; #include &lt;stdlib.h&gt; // libreria para el uso de rand() #include&lt;time.h&gt; int x; int a; int numero; volatile int Counter=0; /**  * main.c  */   #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A (void){     Counter--;     //Disminuir el Contador en 1     LPM3_EXIT;      //Salir del modo de bajo poder 3 }     void wait(int seconds){        Counter= seconds*2;        while(Counter){            LPM3;        }    }   void main(void) {     WDTCTL = WDTPW | WDTHOLD;   // stop watchdog timer     BCSCTL1= CALBC1_1MHZ;     DCOCTL = CALDCO_1MHZ;      P1SEL=0x06;     P1SEL2=0x06;       P2SEL=0x0;     P2SEL2=0x0;     P2DIR=0xFF;     P2OUT=0x00;      UCA0CTL1=0x81;//Enabled USCI logic held in reset state     UCA0CTL0=0x0;//UART Mode, Odd Parity, 8bit Data, 1 bit de parada, asynchronous     UCA0BR0=0x68;//Baud rate 9600     UCA0BR1=0x0;//Baud rate (UCA0BR0+UCA0BR1x256=9600)     UCA0MCTL=0x2;     UCA0STAT=0x0;     UCA0CTL1 =0x80;//Disabled USCI logic held in reset state     IE2=1;     __enable_interrupt();        for (;;){                           if (a==49){  // 1 recieved from bluetooth &quot;49&quot; in code ASCII                 srand (time(NULL));  //seed  of random number based on the time                numero = rand(1,9);    //generated random number between 1 and 9                for(int i=0,i&lt;9,i++){                    P2OUT=BIT(i);  //HELP HERE BLINKING THE LEDS WITH CYCLE FOR                     wait(5) //function of delay                }                P2OUT=;             } }          }   }  #pragma vector=USCIAB0RX_VECTOR  //interruption for bluetooth module HC-05 __interrupt void uartbt(void)       {     a=UCA0RXBUF;//INTERRUPCION DONDE SE ALMACENA EL VALOR CUANDO HAY COMUNICACION EN EL BLUETOOTH     IFG2=0;//Limpiamos bandera de interrupción para salir    }
6859
How do you set, clear, and toggle a bit?
10533
I have always been taught to driver an LED using an MCP using the following method (Driving the pin high) as shown in the diagram below:   However I have recently seen LED's being driven using the following method as shown in the diagram below. I assume in this method the LED is driven when the digital pin is set to low. Which method is best practice and why?
122430
I'm experimenting with writing a software UART on my microcontroller using GPIO pins. This is to temporarily add a UART channel on a project until we get the new design implemented that uses a uC with more UART ports.  What I'm having difficulty with is correctly detecting a start bit in a serial stream. The source of the stream is external and doesn't care when my device powers up. So it's very likely that my device will power on and start seeing data bits in the middle of a byte transmission. Undoubtedly, that will cause my software UART to read erroneous values, as it won't be able to tell the difference between a start bit and any other high-to-low transition.  Is this an inevitable issue with a UART channel? Or is there some clever trick that the uC manufacturers use in their hardware UARTs?
107306
I'm working on a guitar, and the plan is to use three latching push buttons so that each pickup can be turned on and off individually. I'm fairly confident that the following diagram should work for that (Feel free to correct me)   The buttons I want to use are , which have a built-in LED when turns on when the button is pressed.   Which brings me to my question: Is there a way to power the LED? If I introduce a 9volt into the wiring, wouldn't that cause problems with the guitar's standard electronics?
82355
I recently read an  about button debouncing and was wondering if I should keep this in mind when working with, for example, an Arduino (ATMega mC)? I assume it is an issue, especially when working with interrupts.  So is it better to detect bounce in code, or should this be taken care of with hardware? Please elaborate.
61840
I am using  for a project on converting analog signal to digital signal. It has an inbuilt multiplexer using which we have to provide an analog signal to one of the pin. However what happens is ;  Sometimes it latches to a particular value say 1000000 and remains at there no matter how many times Start of Conversion is pressed which should set the inner counter to 0.  Sometimes it gives slightly wrong output off by 100 or 1000 and when I press Start of conversion, it gives correct output, so its not reliable every time.  And most seriously , Suppose the control for multiplexer according to Datasheet are such that input pin 1 should be active, instead, it works only when the input is given to pin 5 for one particular IC and pin 3 for other. I have been trying to fit it in logic since 3 days however each day some new error happens. I have replaced it twice from my college lab and now the technician doesn't want to replace it anymore . What is amiss here ?
57029
I'm trying to make a simpler approach to flash LPC1114 MCU.  If the MCU is reset while pin1.1 is held low it enters bootloader mode. I'm using a simple arduino sketch to drive reset &amp; 1.1 pins via serial line.  It was pretty simple with reset:         &ndash; Schematic created using   I've just replaced my button with a transistor and it did the trick.  Now, with 1.1 pin I have the following setup:          i.e. by default it's not connected to anything, on button press it's pulled down. Well, replacing the button with transistor doesn't seem to work.  Any hints on how to fix that?
21351
I modified my Sega Master System to have a pause button on the actual controller. To process the signal, I soldered a quad NOR gate to the I/O and CPU circuits in the console. The idea is that the controller pause button sends a combined UP/DOWN signal, and the gate processes it and sends an NMI to the CPU, which is what the Pause button on the actual console does. This is the procedure recommended at the SMSPower forum, and I followed their diagrams.  Here's the thing: I installed the gate upside down, so that the packaging is resting on the circuit board, and the pins are sticking up in the air. I did this so it would be easier to solder the pins to the console, reasoning that the package is non-conductive anyway. When I tested it out, it didn't work correctly. As I was troubleshooting with my logic probe, I accidentally dislodged the Vcc connection, which I had soldered to a +5 Vcc solder point on the board. All of a sudden, it works correctly! I've checked the pin assignments over and over, and I'm positive that the Vcc pin isn't connected to anything; yet, the chip has power, and works as it is supposed to.  So, what is going on here? Was it a bad idea to install the chip package so that it touches the board? And why is the chip working when the Vcc pin is disconnected?  (edited to add requested information)  The gate is a CD4001AE Quad NOR; the datasheet is here:    The schematic is here, at the bottom of the page:
78960
I have an IC that has an GPIO with which I would like to drive a LED.   Since the device will be running off battery, keeping the power use low (Zero maybe) while the LED is off as a priority.  The GPIO supplies 3.3V when turned on and 0.0V votes when turned off.   It also has a limit of a maximum of 4mA.  The LED has a forward current of 20mA and a desired forward voltage of 2.0V.  When the LED is turned on it will most likely be blinking (using PWM) in the low kilohertz range.  After poking around I believe this may be the type of circuit I need.    Question 1: Am I even close to being on the right track.  Question 2: What is the correct component to use for item (5), (Transistor or  Mosfet), and how do I go about finding one (at the local Frys, RadioShack, Online) and how are they identified(specified)?  Question 3: Will the choice of item (5) have any effect on the ohm value of the resistor item (3)?  Apart from the normal Ohms law for the 3.0V power source and the 2.0V LED.  Question 4: What would be the ohm value of the resistor item (2), if any is required.
37
I am looking to build a circuit to control five different FET drivers individually. The input signal would be a single shot from a function generator, which should produce five output signals, with the same frequency and phase but the duty cycles need to be individually controllable. Basically, I am trying to replace five function generators (synchronized to the same clock) with one single function generator and a circuit board due to limited resources. The outputs need to have only two levels i.e pulse wave  EDIT: Olin's suggestion (using a MCU) or a FPGA seem to be the best options but any analog alternatives are much appreciated. Thanks :)
10168
I'm trying to display a 4-bit binary number on a 7 segment LED as a hexadecimal number (0-F). I have an assortment of 7400 series ICs including the 7447. But that one only works for BCD (0-9). The 7400 series doesn't seem to have a hex to 7-segment decoder and I don't have one on hand.  So I figure I'd have to build my own. The datasheet for a 7447 comes with the internal circuitry but I couldn't find a similar circuit for hex to 7-segment. I did K-diagrams for each LED segment by hand but the terms are rather large, much larger than for BCD.  Does anyone have a finished circuit for this that I can check my work against?  Does anyone have an optimized circuit for this that takes advantage of common subterms? There aren't many duplicate terms (like A0 &amp; ~A1 &amp; A2) but maybe using (A0 &amp; A2) &amp; ~A1 would allow sharing the (A0 &amp; A2) subterm and overall reduce the gate count.  Or maybe some tricks to use NAND, NOR or XOR gates for some parts?  I don't care about different path length or races in the circuit as it's only going to drive LEDs and should be far too quick to see any of that.
86877
I am working on an MSP430 project that requires me to route the output of one peripheral into the input of another peripheral. Thus, I have two MCU pins connected directly to each other. This looks suspicious to me since there is the possibility of a programming error causing both to be (possibly conflicting) outputs. Also, there is the issue of startup and programming states.  In the worst case, if one pin is driving HI, the other is driving LO, the GPIO pins generally have way more sink capability than source capability... so it'll be somewhat like taking a HI output and shorting it to near-ground. Which is bad... but how bad is it? Is it likely to cause damage to the MCU?  I often see examples on the web of people using Arduinos to light an LED between two pins without a resistor, and I haven't heard of any stories of anyone frying anything but the LED. Clearly you wouldn't want to do this in a product, but do manufacturers generally try to protect the MCU from GPIO pins being overloaded anyway?  Thinking about it in retrospect, putting a current-limiting resistor between the two pins would have prevented any worries, but even a minor hardware change is a very difficult thing to do at this point.  For future reference and the benefit of posterity, does anyone have any other ideas about the proper way of minimizing the risks of connecting two MCU pins together, and more generally, minimizing the risks that come from the possibility of overloading a GPIO pin?
103961
Edit:  I successfully made it work, but the algorithm not efficient I taking the date coming in to my block, pipeline the data for how much points I need to median filter (for example 31), take all the 31 pipeline points and send to sorting algorithm block which returns bus with the sorted data, from this bus I taking only the median value (middle of the bus) and output it.    The only hard thing in this block diagram I sketched is the sorting algorithm, right? So I found verilog code in GitHub for bitonic sort:   connected it to the rest of my block, and everything cool I getting the sorting right and successfully calculating the median value every clock cycle. This approach working but because this much of comparators every clock cycle I'm overloading my FPGA with complexity and a lot of LUTs (I sorting 31 points every clock cycle.. that ALOT).    How you guys think I should make this median filter algorithm better? sorting the whole array every clock cycle seems like solution but naive one.
81441
I am using a "Dual 16-bit binary counter with 3-state output registers" (SN74LV8154) to count input pulses up to 32 bits.  It is working fine most of the time, but some of the bits in the counter seem to flip randomly. The result is reflected in the register, as I see the output value sometimes jump forward and/or backward.   Jumps are persistent (not punctual misreadings) since the value does not jump the other way around right after the issue. e.g.    0x12fe 0x12ff 0x1200 (should be 0x1300) 0x1201 0x1202 (0x0100 still not on)   The chip allows to read byte by byte with the help of a 4 bit word selector. This is done quite frequently, word by word, and I record a timeseries with the result. I expect the counter to go up by a few increments between reads.  The result is fine most of the time, but it looks like some internal carries are either forgotten or doubled.  Here are a few examples:  |----------------------+------------------------+-------------| | Before               | After                  | Jump        | |                      | (Expected)             |             | |----------------------+------------------------+-------------| | 0b010011000011111111 |  0b010011001000000000  | 0b100000000 | |                      | (0b010011000100000000) |             | | 0b110001000001111111 |  0b110001000000000000  | -0b10000000 | |                      | (0b110001000010000000) |             | | 0b111100101011111111 |  0b111100110000000000  | 0b100000000 | |                      | (0b111100101100000000) |             | |----------------------+------------------------+-------------|   I also saw jumps by +/- 16, +/- 32, +/-65536, so I guess the issue is not related to the word size.   Any help on how to investigate this would be much appreciated.  Julien
4379
I am new to electronic prototyping and had a few questions.  I need to control 132 LEDs individually. I want to  make 3 rows ( 2 rows of 60 and 1 row of 12) I think i can matrix them but i would still need 63 outputs (3 high, 60 long).  I don't want to use 8 different  shift registers.  Are there any 32 bit or 64 bit led drivers(or shift registers, not really sure what there are called) And where can i buy them.  Any help is appreciated .
94979
I have my Caps Lock key remapped to Esc, so now I have a LED on my keyboard that is never on. I'd like to use it for something useful, like HDD or LAN activity.  Especially that I'm using a computer with a custom box &amp; heatsinks (built into my drawer so I don't have to listen to the HDD and it doesn't take up much space), and the LEDs are not visible otherwise.  If there's a library for controlling the keyboard LEDs, I could do some coding myself, if there isn't a solution for this already.  I'm on Gentoo ~amd64.  EDIT: Ok, forget about the HDD LED. It was just an example.  I want the Caps Lock LED to light up when it's my birthday. Or when I have email. Or when I say "Caps Lock LED, please light up!".  I absolutely do not want to use an extra wire. In fact, it would be nice if this would work on wireless keyboards as well.
71508
I would like to make a simple circuit to store or save 1 bit of data. The circuit should be able to remember the state of an LED ( on or off ) even if the supply is disconnected from the circuit. I need it to work like a hard drive, flash memory or SD memory card of cell phones.  I made a circuit as shown in the picture, The output is an LED in series with 470 ohm resistor. I use two bush buttons to charge or discharge the capacitor so the output LED is on or off.   After disconnecting the supply or turning off electricity, The circuit was able to remember the state of the LED for few minutes.   After 2 or 3 minutes, the capacitor discharged completely and the circuit lost its data.    How can I stop the capacitor from discharging ? or how can I slow the rate of discharging so that the circuit lose its data after a week or more ?  In this circuit I uses 555 as an inverter ( not gate ) but I may use any other IC's , My aim is just making a simple permanent memory.