CD4028BE BCD to Decimal Decoder

used products:

1. Arduino UNO
2. CD4028BE

Arduino:

#define aPin 2 #define bPin 3 #define cPin 4 #define dPin 5 #define del 500 void setup() { pinMode(aPin, OUTPUT); pinMode(bPin, OUTPUT); pinMode(cPin, OUTPUT); pinMode(dPin, OUTPUT); } void loop() { for (int i = 0; i < 10; i++) { digitalWrite(aPin, bitRead(i, 0)); digitalWrite(bPin, bitRead(i, 1)); digitalWrite(cPin, bitRead(i, 2)); digitalWrite(dPin, bitRead(i, 3)); delay(del); } }

C:

#include <avr/io.h> #include <util/delay.h> int main(void) { //DDRD = 60; //DDRD = B00111100; // binary //DDRD = (1<<PD5) | (1<<PD4) | (1<<PD3) | (1<<PD2); //DDRD = _BV(5) | _BV(4) | _BV(3) | _BV(2); DDRD = _BV(PD5) | _BV(PD4) | _BV(PD3) | _BV(PD2); PORTD = 0; int hex = 0x0; while (1) { PORTD = hex << 2; hex++; if (hex > 0x09) { hex = 0x0; } _delay_ms(300); } }

Assembler:

;.nolist ;.include "./m328Pdef.inc" ;.list .def temp = r16 .def counter = r17 .org 0x0000 rjmp start /** turn on if bit set **/ .macro lifset sbrc counter, @0 jmp else cbi portd, @1 jmp endif else: sbi portd, @1 endif: .endmacro start: ldi temp, high(RAMEND) out sph, temp ldi temp, low(RAMEND) out spl, temp sbi DDRD, 2 sbi DDRD, 3 sbi DDRD, 4 sbi DDRD, 5 loop: clr counter ten: lifset 0, 2 lifset 1, 3 lifset 2, 4 lifset 3, 5 rcall delay_500ms inc counter cpi counter, 10 brne ten rjmp loop 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 dir portd.2 out dir portd.3 out dir portd.4 out dir portd.5 out Dim counter as Integer Do Forever For counter = 0 To 9 portd.2 = counter.0 portd.3 = counter.1 portd.4 = counter.2 portd.5 = counter.3 Wait 50 ms Next Loop