CD4094B CMOS 8-Stage Shift and Store Bus Register

used products:

1. Arduino UNO
2. CD4094BE
3. M74HC4094B1

content:

Products: CD4094BE or M74HC4094B1 Çeşme: http://forum.arduino.cc/index.php?topic=211583.0 http://senster.com/blog/wp-content/uploads/2009/02/expanding_outputs.pdf http://electronics.stackexchange.com/questions/113473/cd4094be-arduino-problems

Arduino:

// http://forum.arduino.cc/index.php?topic=211583.0 //Pin connected to Strobe (pin 1) of 4094 int strobePin = A3; //Pin connected to Data (pin 2) of 4094 int dataPin = A4; //Pin connected to Clock (pin 3) of 4094 int clockPin = A5; void setup() { Serial.begin(9600); //set pins to output because they are addressed in the main loop pinMode(strobePin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { //count up routine for (int count = 0; count < 100; count++) { //get the value for the tens display byte tens = count / 10; //get the value for the units display byte units = count % 10; //shift the tens value 4 bits to the left and attach the units value using a bitwise OR byte out = (tens << 4|units); Serial.print("v: "); Serial.print(out); Serial.println(); //set strobe pin low to begin storing bits digitalWrite(strobePin, LOW); shiftOut(dataPin, clockPin, MSBFIRST, out); //set strobe pin high to stop storing bits digitalWrite(strobePin, HIGH); delay(200); } }

C:

#ifndef F_CPU #define F_CPU 16000000UL #endif #include <avr/io.h> #include <util/delay.h> #define PIN_STROBE 3 #define PIN_DATA 4 #define PIN_CLOCK 5 int main(void) { DDRC = (1<<PIN_CLOCK) | (1<<PIN_DATA) | (1<<PIN_STROBE); while (1) { for (int counter = 0; counter < 100; counter++) { PORTC &= ~(1<<PIN_STROBE); PORTC &= ~(1<<PIN_CLOCK); PORTC &= ~(1<<PIN_DATA); for (int i=7; i>=0; i--) { PORTC &= ~(1<<PIN_CLOCK); if ((counter&(1<<i))) { PORTC |= (1<<PIN_DATA); } else { PORTC &= ~(1<<PIN_DATA); } PORTC |= (1<<PIN_CLOCK); PORTC &= ~(1<<PIN_DATA); } PORTC &= ~(1<<PIN_CLOCK); PORTC |= (1<<PIN_STROBE); _delay_ms(100); } } }

Assembler:

;.nolist ;.include "./m328Pdef.inc" ;.list .def temp = r16 .def counter = r17 .def i = r18 .def number = r19 .equ PIN_STROBE = 3 .equ PIN_DATA = 4 .equ PIN_CLOCK = 5 .org 0x0000 rjmp start start: ;ldi temp, 0xaa ;lsr temp ;andi temp, 0x01 ;ldi temp, 0xff&~(1<<PIN_STROBE) ldi temp, high(RAMEND) out sph, temp ldi temp, low(RAMEND) out spl, temp sbi DDRC, PIN_CLOCK sbi DDRC, PIN_DATA sbi DDRC, PIN_STROBE .macro lifset cpi temp, 1 breq else cbi PORTC, PIN_DATA jmp endif else: sbi PORTC, PIN_DATA endif: .endmacro loop: ldi counter, 0 rcall xtimes rjmp loop xtimes: cbi PORTC, PIN_STROBE cbi PORTC, PIN_CLOCK cbi PORTC, PIN_DATA mov number, counter ldi i, 8 fori: cbi PORTC, PIN_CLOCK mov temp, number andi temp, 0x01 lifset lsr number sbi PORTC, PIN_CLOCK cbi PORTC, PIN_DATA dec i brne fori cbi PORTC, PIN_CLOCK sbi PORTC, PIN_STROBE rcall delay_500ms inc counter cpi counter, 100 brne xtimes ret delay_500ms: ; the subroutine: ldi r16, 31 ; load r16 with 31 OUTER_LOOP: ; outer loop label ldi r24, 0xfd ; load registers r24:r25 with 1021, our new ; init value ldi r25, 0x03 ; the loop label DELAY_LOOP: ; "add immediate to word": r24:r25 are ; incremented adiw r24, 1 ; if no overflow ("branch if not equal"), go ; back to "delay_loop" brne DELAY_LOOP dec r16 ; decrement r16 brne OUTER_LOOP ; and loop if outer loop not finished ret ; return from subroutine

Great Cow BASIC:

#chip mega328p #define PIN_STROBE = portc.3 #define PIN_DATA = portc.4 #define PIN_CLOCK = portc.5 dir PIN_STROBE out dir PIN_DATA out dir PIN_CLOCK out Dim counter as Byte Dim inc as Integer Dim temp as Byte Do Forever For counter = 0 To 100 temp = counter PIN_STROBE = 0 PIN_DATA = 0 PIN_CLOCK = 0 For inc = 0 To 7 PIN_CLOCK = 0 PIN_DATA = temp.7 Rotate temp Left PIN_CLOCK = 1 PIN_DATA = 0 Next PIN_CLOCK = 0 PIN_STROBE = 1 Wait 10 ms Next Loop