Override function ShiftOut in C code.
The shiftout function in wiringPi does not communicate with 595 properly, which causes LightWater02, SevenSegment, StopWatch, and LED Matrix to fail. So the function is to be override.
This commit is contained in:
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
* Filename : LightWater02.c
|
||||
* Description : Control LED by 74HC595
|
||||
* Author : freenove
|
||||
* modification: 2016/06/21
|
||||
* modification: 2018/08/04
|
||||
**********************************************************************/
|
||||
#include <wiringPi.h>
|
||||
#include <stdio.h>
|
||||
@@ -12,6 +12,23 @@
|
||||
#define latchPin 2 //ST_CP Pin of 74HC595(Pin12)
|
||||
#define clockPin 3 //CH_CP Pin of 74HC595(Pin11)
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
@@ -27,7 +44,7 @@ int main(void)
|
||||
x=0x01;
|
||||
for(i=0;i<8;i++){
|
||||
digitalWrite(latchPin,LOW); // Output low level to latchPin
|
||||
shiftOut(dataPin,clockPin,LSBFIRST,x);// Send serial data to 74HC595
|
||||
_shiftOut(dataPin,clockPin,LSBFIRST,x);// Send serial data to 74HC595
|
||||
digitalWrite(latchPin,HIGH); // Output high level to latchPin, and 74HC595 will update the data to the parallel output port.
|
||||
x<<=1; // make the variable move one bit to left once, then the bright LED move one step to the left once.
|
||||
delay(100);
|
||||
@@ -35,7 +52,7 @@ int main(void)
|
||||
x=0x80;
|
||||
for(i=0;i<8;i++){
|
||||
digitalWrite(latchPin,LOW);
|
||||
shiftOut(dataPin,clockPin,LSBFIRST,x);
|
||||
_shiftOut(dataPin,clockPin,LSBFIRST,x);
|
||||
digitalWrite(latchPin,HIGH);
|
||||
x>>=1;
|
||||
delay(100);
|
||||
|
||||
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
* Filename : SevenSegmentDisplay.c
|
||||
* Description : Control SevenSegmentDisplay by 74HC595
|
||||
* Author : freenove
|
||||
* modification: 2016/06/24
|
||||
* modification: 2018/08/04
|
||||
**********************************************************************/
|
||||
#include <wiringPi.h>
|
||||
#include <stdio.h>
|
||||
@@ -14,6 +14,23 @@
|
||||
//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);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int i;
|
||||
@@ -27,13 +44,13 @@ int main(void)
|
||||
while(1){
|
||||
for(i=0;i<sizeof(num);i++){
|
||||
digitalWrite(latchPin,LOW);
|
||||
shiftOut(dataPin,clockPin,MSBFIRST,num[i]);//Output the figures and the highest level is transfered preferentially.
|
||||
_shiftOut(dataPin,clockPin,MSBFIRST,num[i]);//Output the figures and the highest level is transfered preferentially.
|
||||
digitalWrite(latchPin,HIGH);
|
||||
delay(500);
|
||||
}
|
||||
for(i=0;i<sizeof(num);i++){
|
||||
digitalWrite(latchPin,LOW);
|
||||
shiftOut(dataPin,clockPin,MSBFIRST,num[i] & 0x7f);//Use the "&0x7f" to display the decimal point.
|
||||
_shiftOut(dataPin,clockPin,MSBFIRST,num[i] & 0x7f);//Use the "&0x7f" to display the decimal point.
|
||||
digitalWrite(latchPin,HIGH);
|
||||
delay(500);
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
* Filename : LEDMatrix.c
|
||||
* Description : Control LEDMatrix by 74HC595
|
||||
* Author : freenove
|
||||
* modification: 2016/06/24
|
||||
* modification: 2018/08/03
|
||||
**********************************************************************/
|
||||
#include <wiringPi.h>
|
||||
#include <stdio.h>
|
||||
@@ -33,6 +33,22 @@ unsigned char data[]={ // data of "0-F"
|
||||
0x00, 0x00, 0x7F, 0x48, 0x48, 0x40, 0x00, 0x00, // "F"
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // " "
|
||||
};
|
||||
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);
|
||||
}
|
||||
}
|
||||
int main(void)
|
||||
{
|
||||
int i,j,k;
|
||||
@@ -49,8 +65,8 @@ int main(void)
|
||||
x=0x80;
|
||||
for(i=0;i<8;i++){
|
||||
digitalWrite(latchPin,LOW);
|
||||
shiftOut(dataPin,clockPin,LSBFIRST,pic[i]);// first shift data of line information to the first stage 74HC959
|
||||
shiftOut(dataPin,clockPin,LSBFIRST,~x);//then shift data of column information to the second stage 74HC959
|
||||
_shiftOut(dataPin,clockPin,MSBFIRST,pic[i]);// first shift data of line information to the first stage 74HC959
|
||||
_shiftOut(dataPin,clockPin,MSBFIRST,~x);//then shift data of column information to the second stage 74HC959
|
||||
|
||||
digitalWrite(latchPin,HIGH);//Output data of two stage 74HC595 at the same time
|
||||
x>>=1;// display the next column
|
||||
@@ -62,8 +78,8 @@ int main(void)
|
||||
x=0x80; // Set the column information to start from the first column
|
||||
for(i=k;i<8+k;i++){
|
||||
digitalWrite(latchPin,LOW);
|
||||
shiftOut(dataPin,clockPin,LSBFIRST,data[i]);
|
||||
shiftOut(dataPin,clockPin,LSBFIRST,~x);
|
||||
_shiftOut(dataPin,clockPin,MSBFIRST,data[i]);
|
||||
_shiftOut(dataPin,clockPin,MSBFIRST,~x);
|
||||
digitalWrite(latchPin,HIGH);
|
||||
x>>=1;
|
||||
delay(1);
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env python3
|
||||
########################################################################
|
||||
# Filename : Blink.py
|
||||
# Description : Make an led blinking.
|
||||
# auther : www.freenove.com
|
||||
# modification: 2018/08/04
|
||||
########################################################################
|
||||
|
||||
def Hello():
|
||||
print('Hello World!')
|
||||
|
||||
Hello()
|
||||
Reference in New Issue
Block a user