EasyManuals Logo

Freenove Ultimate Starter Kit User Manual

Freenove Ultimate Starter Kit
286 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #191 background imageLoading...
Page #191 background image
191
Chapter 18 74HC595 & 7-segment display.
www.freenove.com
support@freenove.com
Code
In this code, uses 74HC595 to control the 7-segment display. The usage of 74HC595 is generally the same to
last section. The content 74HC595 outputs is different. We need code character “0”- “Fone by one, and then
output them with 74HC595.
C Code 18.1.1 SevenSegmentDisplay
First observe the project result, and then analyze the code.
1. Use cd command to enter 18.1.1_SevenSegmentDisplay directory of C code.
cd ~/Freenove_Ultimate_Starter_Kit_for_Raspberry_Pi/Code/C_Code/18.1.1_SevenSegmentDisplay
2. Use following command to compile SevenSegmentDisplay.c and generate executable file
SevenSegmentDisplay”.
gcc SevenSegmentDisplay.c -o SevenSegmentDisplay -lwiringPi
3. Then run the generated file “SevenSegmentDisplay”.
sudo ./SevenSegmentDisplay
After the program is executed, SevenSegmentDisplay starts to display the character “0- “Fsuccessively.
The following is the program code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <wiringPi.h>
#include <stdio.h>
#include <wiringShift.h>
#define dataPin 0 //DS Pin of 74HC595(Pin14)
#define latchPin 2 //ST_CP Pin of 74HC595(Pin12)
#define clockPin 3 //CH_CP Pin of 74HC595(Pin11)
//encoding for character 0-F of common anode SevenSegmentDisplay.
unsigned char
num[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
void _shiftOut(int dPin,int cPin,int order,int val){
int i;
for(i = 0; i < 8; i++ ){
digitalWrite(cPin,LOW);
if(order == LSBFIRST){
digitalWrite(dPin,((0x01&(val>>i)) == 0x01) ? HIGH : LOW);
delayMicroseconds(10);
}
else {//if(order == MSBFIRST){
digitalWrite(dPin,((0x80&(val<<i)) == 0x80) ? HIGH : LOW);
delayMicroseconds(10);
}
digitalWrite(cPin,HIGH);
delayMicroseconds(10);
}
}

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Freenove Ultimate Starter Kit and is the answer not in the manual?

Freenove Ultimate Starter Kit Specifications

General IconGeneral
BrandFreenove
ModelUltimate Starter Kit
CategorySingle board computers
LanguageEnglish