Created
August 29, 2020 05:18
Interfacing the 74HC595 shift registers with PIC16F887 digital pins - https://aki-technical.blogspot.com/2020/05/interfacing-74hc595-shift-registers.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<xc.h> | |
// PIC16F887 Configuration Bit Settings | |
// CONFIG1 | |
#pragma config FOSC = XT | |
#pragma config WDTE = OFF | |
#pragma config PWRTE = OFF | |
#pragma config MCLRE = ON | |
#pragma config CP = OFF | |
#pragma config CPD = OFF | |
#pragma config BOREN = ON | |
#pragma config IESO = ON | |
#pragma config FCMEN = ON | |
#pragma config LVP = ON | |
// CONFIG2 | |
#pragma config BOR4V = BOR40V | |
#pragma config WRT = OFF | |
#define _XTAL_FREQ 4000000 | |
void shiftOut(char pattern){ | |
/*RE0.2 AS OUTPUT*/ | |
PORTE=0x00; | |
TRISE=0x00; | |
ANSEL=0x00; | |
//RE2=0; | |
for(int i=0;i<8;i++){ | |
RE0=0; | |
RE1=((pattern&0x80)!=0)?1:0; | |
RE0=1; | |
pattern<<=1; | |
for(int k=0;k<100;k++); | |
} | |
//RE2=1; | |
} | |
void main(){ | |
char ssd[16]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D, | |
0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71}; | |
unsigned int myTime=0; | |
while(1){ | |
RE2=0; | |
shiftOut(ssd[myTime%10]); | |
shiftOut(ssd[myTime/10]); | |
RE2=1; | |
myTime+=1; | |
if(myTime>=60) | |
myTime=0; | |
__delay_ms(1000); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment