There are many topics in this blog talking about the 7-segment display and how to interface it with different types of PIC microcontrollers. One of these topics shows how to interface PIC16F877A with a multiplexed 4-digit 7-segment display with the shift register 74HC164N.
There are many topics in this blog talking about the 7-segment display and how to interface it with different types of PIC microcontrollers. One of these topics shows how to interface PIC16F877A with a multiplexed 4-digit 7-segment display with the shift register 74HC164N.
In this topic we are going to see how to make a digital up/down counter using multiplexed 7-segment display with 74HC595 shift register and PIC16F877A microcontroller.
From the 74HC595 datasheet this shift register is a high speed, 8-stage serial shift register with a storage register and 3-state outputs. The registers have separate clocks.
Data is shifted on the positive-going transitions of the shift register clock input (SHCP). The data in each register is transferred to the storage register on a positive-going transition of the storage register clock input (STCP). If both clocks are connected together, the shift register will always be one clock pulse ahead of the storage register.
The following table shows the 74HC595 shift register pin-outs:
7-Segment display with 74HC595 shift register:
The following circuit schematic shows a multiplexed 4 digits connected to the 74HC595 shift register. The type of the 7-segment display used in this example is common anode.
In the circuit there are two push buttons, these buttons are used to increment and decrement the displayed number.
7-Segment display with 74HC595 shift register interfacing with PIC16F877A CCS C code:
Here is the example code I think it is a small and clear code.
//Β 4-DigitΒ 7-SegmentΒ displayΒ withΒ 74HC595Β interfacingΒ withΒ PIC16F877AΒ CCSΒ CΒ code //Β http://ccspicc.blogspot.com/ //Β [email protected] #define data_pin PIN_B0 #define clock_pin PIN_B1 #define latch_pin PIN_B2 #include <16F877A.h> #fuses HS,NOWDT,NOPROTECT,NOLVP #use delay(clock = 8000000) #use fast_io(B) #use fast_io(D) short s; // Used to know buttons position unsigned int j, digit ; unsigned long i = 0; unsigned int seg(unsigned int num) { Β Β switch (num) { Β Β Β Β case 0 : return 0x80; Β Β Β Β case 1 : return 0xF2; Β Β Β Β case 2 : return 0x48; Β Β Β Β case 3 : return 0x60; Β Β Β Β case 4 : return 0x32; Β Β Β Β case 5 : return 0x24; Β Β Β Β case 6 : return 0x04; Β Β Β Β case 7 : return 0xF0; Β Β Β Β case 8 : return 0; Β Β Β Β case 9 : return 0x20; Β Β Β Β } } void write_data(unsigned int number){ Β Β for(j = 0x80; j > 0; j = j >> 1) { Β Β Β Β Β if(number & j) Β Β Β Β Β Β Β output_high(data_pin); Β Β Β Β Β else Β Β Β Β Β Β Β output_low(data_pin); Β Β Β Β Β output_high(clock_pin); Β Β Β Β Β output_low(clock_pin); Β Β Β } Β Β Β Β Β output_high(latch_pin); Β Β Β Β Β output_low(latch_pin); } void main(){ Β Β port_b_pullups(TRUE);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Enable PORTB pull-ups Β Β output_b(0);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // PORTB initial state Β Β set_tris_b(0x18);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Configure RB3 & RB4 pins as inputs Β Β output_d(0);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // PORTD initial state Β Β set_tris_d(0);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Configure PORTD pins as inputs Β Β while(TRUE){ Β Β Β Β if(input(PIN_B3) && input(PIN_B4)) Β Β Β Β Β Β sΒ =Β 1; Β Β Β Β if(s == 1) { Β Β Β Β Β Β if(input(PIN_B3) == 0) { Β Β Β Β Β Β Β sΒ =Β 0; Β Β Β Β Β Β Β i++; Β Β Β Β Β Β Β if(i > 9999) Β Β Β Β Β Β Β Β Β iΒ =Β 0; Β Β Β Β Β Β } Β Β Β Β Β Β if(input(PIN_B4) == 0) { Β Β Β Β Β Β Β sΒ =Β 0; Β Β Β Β Β Β Β if(i < 1) Β Β Β Β Β Β Β Β Β iΒ =Β 1; Β Β Β Β Β Β Β i--; Β Β Β Β Β Β } Β Β Β Β } Β Β Β Β digitΒ =Β seg(iΒ %Β 10);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Prepare to display ones Β Β Β Β output_d(0x0F);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn off all displays Β Β Β Β write_data(digit); Β Β Β Β output_d(0x07);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn on display for ones Β Β Β Β delay_ms(1); Β Β Β Β digitΒ =Β seg((iΒ /Β 10)Β %Β 10);Β Β Β Β Β Β Β Β Β Β // Prepare to display tens Β Β Β Β output_d(0x0F);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn off all displays Β Β Β Β write_data(digit); Β Β Β Β output_d(0x0B);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn on display for tens Β Β Β Β delay_ms(1); Β Β Β Β digitΒ =Β seg((iΒ /Β 100)Β %Β 10);Β Β Β Β Β Β Β Β Β // Prepare to display hundreds Β Β Β Β output_d(0x0F);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn off all displays Β Β Β Β write_data(digit); Β Β Β Β output_d(0x0D);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn on display for hundreds Β Β Β Β delay_ms(1); Β Β Β Β digitΒ =Β seg((iΒ /Β 1000)Β %Β 10);Β Β Β Β Β Β Β Β // Prepare to display thousands Β Β Β Β output_d(0x0F);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn off all displays Β Β Β Β write_data(digit); Β Β Β Β output_d(0x0E);Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β // Turn on display for thousands Β Β Β Β delay_ms(1); Β Β } }
7-Segment display with 74HC595 shift register interfacing with PIC16F877A video:
The following video from a real hardware circuit for the digital counter.
Source :Β 4-Digit 7-Segment display with 74HC595 shift register