CD4511BE & 4 Digit 7 Segment Display

CD4511BE & 4 Digit 7 Segment Display
/* * Arduino UNO 4511 BCD to 7-digit LED driver * * 4511 pins 3 (lamp test), 4 (ripple blanking), and 16 (Vcc) * are connected to +5V on the Arduino UNO. * * 4511 pin 8 is connect to GND on the Arduino UNO. * The common cathode on the LED digit also connects to GND. * * 4511 pins 9 through 15 connect to the LED digit as * appropriate. */ //#define LATCH_ENABLE 13 // to pin 5 on the 4511 #define DATA1 4 // to pin 7 on the 4511 #define DATA2 5 // to pin 1 on the 4511 #define DATA3 6 // to pin 2 on the 4511 #define DATA4 7 // to pin 6 on the 4511 void setup() { Serial.begin(9600); //pinMode( LATCH_ENABLE, OUTPUT ) ; pinMode( DATA1, OUTPUT ) ; pinMode( DATA2, OUTPUT ) ; pinMode( DATA3, OUTPUT ) ; pinMode( DATA4, OUTPUT ) ; } // This macro tests bit 'b' in value 'v' and reports // high or low as appropriate. #define T(v,b) (v & (1<<b) ? HIGH : LOW) void show( unsigned int value ) { int v0 = T(value, 0); int v1 = T(value, 1); int v2 = T(value, 2); int v3 = T(value, 3); if ( value <= 9 ) { // enable the latch so we can write //digitalWrite( LATCH_ENABLE, LOW ); digitalWrite(DATA1, v0); digitalWrite(DATA2, v1); digitalWrite(DATA3, v2); digitalWrite(DATA4, v3); Serial.print(v0); Serial.print(","); Serial.print(v1); Serial.print(","); Serial.print(v2); Serial.print(","); Serial.print(v3); Serial.println(); // disable the latch now that we're done writing //digitalWrite( LATCH_ENABLE, HIGH ); } } void loop() { for ( int i = 0; i <= 9; i++ ) { show(i) ; delay(500) ; // msec } }
#include <avr/io.h> #define F_CPU 16000000 #include <util/delay.h> // This macro tests bit 'b' in value 'v' and reports // high or low as appropriate. #define T(v,b) (v & (1<<b) ? 1 : 0) #define DATA1 PD4 // to pin 7 on the 4511 #define DATA2 PD5 // to pin 1 on the 4511 #define DATA3 PD6 // to pin 2 on the 4511 #define DATA4 PD7 // to pin 6 on the 4511 void trigger(int value, int bit, int pin) { if (T(value,bit) != 0) { PORTD |= (1<<pin); } else { PORTD &= ~(1<<pin); } } int main(void) { DDRD |= (1<<DATA1); DDRD |= (1<<DATA2); DDRD |= (1<<DATA3); DDRD |= (1<<DATA4); while (1) { for (int i = 0; i <= 9; i++) { trigger(i, 0, PD4); trigger(i, 1, PD5); trigger(i, 2, PD6); trigger(i, 3, PD7); _delay_ms(500); } } }
.nolist .include "./m328Pdef.inc" .list .equ DATA1 = 4 ; to pin 7 on the 4511 .equ DATA2 = 5 ; to pin 1 on the 4511 .equ DATA3 = 6 ; to pin 2 on the 4511 .equ DATA4 = 7 ; to pin 6 on the 4511 .def temp = r16 .def counter = r17 .org 0x0000 rjmp start start: ldi temp, low(ramend) out spl, temp ldi temp, high(ramend) out sph, temp sbi DDRD, DATA1 sbi DDRD, DATA2 sbi DDRD, DATA3 sbi DDRD, DATA4 .macro setif sbrs temp, @0 cbi PORTD, @1 sbrc temp, @0 sbi PORTD, @1 .endmacro loop: clr counter for: mov temp, counter setif 0, DATA1 setif 1, DATA2 setif 2, DATA3 setif 3, DATA4 rcall delay_500ms inc counter cpi counter, 9 brne for rjmp loop ret delay_500ms: ; the subroutine: ldi r18, 31 ; load r18 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 r18 ; decrement r18 brne OUTER_LOOP ; and loop if outer loop not finished ret ; return from subroutine
#chip mega328p #define DATA1 PORTD.4 ' to pin 7 on the 4511 #define DATA2 PORTD.5 ' to pin 1 on the 4511 #define DATA3 PORTD.6 ' to pin 2 on the 4511 #define DATA4 PORTD.7 ' to pin 6 on the 4511 dir DATA1 out dir DATA2 out dir DATA3 out dir DATA4 out Do Forever For temp = 0 To 9 DATA1 = temp.0 DATA2 = temp.1 DATA3 = temp.2 DATA4 = temp.3 Wait 50 ms Next Loop