Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Shift register not working

Status
Not open for further replies.

venkates2218

Full Member level 6
Joined
Sep 30, 2016
Messages
354
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,298
Activity points
4,306
image1.png

Code:
#define	XTAL_FREQ	20MHZ		/* Crystal frequency in MHz */
#include <pic.h>
#include <xc.h>
#include "delay.h"

// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator: High-speed crystal/resonator on RA6/OSC2/CLKOUT and RA7/OSC1/CLKIN)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config MCLRE = ON       // RA5/MCLR/VPP Pin Function Select bit (RA5/MCLR/VPP pin function is MCLR)
#pragma config BOREN = OFF      // Brown-out Detect Enable bit (BOD disabled)
#pragma config LVP = OFF        // Low-Voltage Programming Enable bit (RB4/PGM pin has digital I/O function, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EE Memory Code Protection bit (Data memory code protection off)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

//VARIABLE INITIALION


int a0[7] = {0, 1, 1, 1, 1, 1, 1};
int a1[7] = {0, 0, 0, 0, 1, 1, 0};
int a2[7] = {1, 0, 1, 1, 0, 1, 1};
int a3[7] = {1, 0, 0, 1, 1, 1, 1};
int a4[7] = {1, 1, 0, 0, 1, 1, 0};
int a5[7] = {1, 1, 0, 1, 1, 0, 1};
int a6[7] = {1, 1, 1, 1, 1, 0, 1};
int a7[7] = {0, 0, 0, 0, 1, 1, 1};
int a8[7] = {1, 1, 1, 1, 1, 1, 1};
int a9[7] = {1, 1, 0, 1, 1, 1, 1};

void System_init(void) {
    TRISA = 0X00;
    PORTA = 0X00;
    CMCON = 0X07;

    TRISB = 0b00000000;
    PORTB = 0b00000000;
}

/**************************************************************
                    Main Program
 **************************************************************/
void main(void) {

    System_init();
    while (1) {
        RB2 = 1;
        RB3 = 0;
        for (int i = 0; i < 7; i++) {
            RB1 = 1;
            RB0 = a0[i];
            RB1 = 0;
            DelayMs(10);
        }
        RB2 = 0;
        RB3 = 1;
        for (int i = 0; i < 7; i++) {
            RB1 = 1;
            RB0 = a1[i];
            RB1 = 0;
            DelayMs(10);
        }
    }
}


Please refer the circuit image.
This is my circuit and programmed this program to display the number 7 segment display....
I can get the output but I can see the bits shifting while trying to display the numbers.
Is any error in program or circuit..?
 
Last edited by a moderator:

Hi,

Some schematic issues:
* missing power supply capacitors. 100nF at each VCC pin of each IC, plus one bulk capacitor.
* missing current limitng resistors for the display segments (max 6.25mA per segment to comply with max VCC current specification)


Code issues:
* it seems you want to latch in at falling clock edge, but HC164 needs rising clock edge.
* the 10ms delay is after each transferred bit but it should be a transferred byte.
I´m not that familiar with "C", but it seems that "int A0[7]" defines an array of 7 integer values (I assume an int is a 16 bit variable) ... but in your code you treat each integer as a single bit only.

*****
I recommend you to learn to write a small piece of code... then test this small bit of conde, then add the next code and test it. All step by step. Small steps.

Klaus
 

I can see the bits shifting while trying to display the numbers
That's what the code does. 74164 has no output latch, so the digit drivers should be switched off while you are shifting the data. Design the code respectively, e.g.

Code:
digits off
shift digit a data
digit a on
delay 5ms
digits off
shift digit b data
digit b on
delay 5ms
repeat
 

That's what the code does. 74164 has no output latch, so the digit drivers should be switched off while you are shifting the data. Design the code respectively, e.g.

Code:
digits off
shift digit a data
digit a on
delay 5ms
digits off
shift digit b data
digit b on
delay 5ms
repeat

Need clock to shift datas...?
 

The pseudocode in post #3 is a suggestion to modify the digit enable scheme in your initially posted code and remove delays in the wrong place. I was under the assumption that you can perform the abstraction.
 

The pseudocode in post #3 is a suggestion to modify the digit enable scheme in your initially posted code and remove delays in the wrong place. I was under the assumption that you can perform the abstraction.

Let assume 3 no.of digits we having.
After sending data to the 1st display need to switch off the 1st display and then have to send data to second display by switching on.
like this you are advising for operation without clock method..?
 

No. Shifting out the data involves toggling the clock for each bit.
 

You MUST have a clock. The shift register moves the bits one at a time so all 8 are presented to the LED simultaneously. The 74HC164 does not have a latched output so the bits will 'move' across the output pins each time you raise and lower the clock pin. That would make the LED segments change visibly so you have to turn the digit off (RB2,RB3) until all the bits are in place.

So the program flow should be:
1. 8x shift of the bits for the first digit while it is turned off.
2. turn the digit on for a few mS so it is displayed.
3. turn the digit off for about 1mS
4. repeat steps 1 - 3 for the second digit (and third...) then go back to step 1.

Only one digit at a time is lit up so you have to rely on persistence of vision to make it look as though they are all on at the same time.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top