HD74LS139 Dual 2-line-to-4-line Decoders / Demultiplexers

used products:

1. Arduino UNO
2. HD74LS139P
3. SN74HC139N

Arduino:

int pins[2] = {2,3}; void setup() { for (int j = 0; j < 2; j++) { pinMode(pins[j], OUTPUT); } } void loop() { for (int i = 0; i < 4; i++) { for (int j = 1; j >= 0; j--) { byte state = bitRead(i, j); digitalWrite(pins[j], state); } delay(500); } }

C:

#include <avr/io.h> #include <util/delay.h> const int selectPins[2] = {PD2, PD3}; int main(void) { for (int i = 0; i < 2; i++) { DDRD |= (1<<selectPins[i]); } while (1) { for (int i = 0; i < 4; i++) { for (int j = 1; j >= 0; j--) { byte state= ((i >> j) & 0x01); if (state) { PORTD |= (1<<selectPins[j]); } else { PORTD &= ~(1<<selectPins[j]); } } _delay_ms(500); } } return 0; }