For more detail about 74HC595, please see this post.
In this example I use two registers to show a timing of 60 seconds.
00:00 / 00:00
![]() |
Schematic diagram |
Source code is here:
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); | |
} | |
} |
![]() |
A screen shot while the simulation shows 17 seconds count. |
If you want a standard PCB for ATMega32 micro-controller, you can order my AVR Microcontroller project from PCBWay with a reasonable price. Click here to get a free $5 credit for new account.
![]() |
ATMega16 ATMega32 Experiment Board PCB from PCBWay |
No comments:
Post a Comment