First commit with SRs 165N and 595N functionality
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
#include "Arduino.h"
|
||||
#include <stdint.h>
|
||||
#include "165.h"
|
||||
|
||||
SR165 NewSR165(uint8_t pl, uint8_t ce, uint8_t cp, uint8_t q7) {
|
||||
SR165 newSr = {
|
||||
.parallelLoadIn = pl,
|
||||
.clockEnable = ce,
|
||||
.complementaryOut = q7,
|
||||
.clockIn = cp
|
||||
};
|
||||
|
||||
pinMode(newSr.clockIn, OUTPUT);
|
||||
pinMode(newSr.clockEnable, OUTPUT);
|
||||
pinMode(newSr.parallelLoadIn, OUTPUT);
|
||||
pinMode(newSr.complementaryOut, INPUT);
|
||||
|
||||
return newSr;
|
||||
}
|
||||
|
||||
byte SR165_read(SR165 *sr) {
|
||||
// Write pulse to load pin
|
||||
digitalWrite(sr->parallelLoadIn, LOW);
|
||||
delayMicroseconds(5);
|
||||
digitalWrite(sr->parallelLoadIn, HIGH);
|
||||
delayMicroseconds(5);
|
||||
|
||||
// Get data from 74HC165
|
||||
digitalWrite(sr->clockIn, HIGH);
|
||||
digitalWrite(sr->clockEnable, LOW);
|
||||
byte incoming = shiftIn(sr->complementaryOut, sr->clockIn, LSBFIRST);
|
||||
digitalWrite(sr->clockEnable, HIGH);
|
||||
|
||||
return incoming;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef __165__
|
||||
#define __165__
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct SR165 {
|
||||
uint8_t parallelLoadIn;
|
||||
uint8_t clockEnable;
|
||||
uint8_t complementaryOut;
|
||||
uint8_t clockIn;
|
||||
} SR165;
|
||||
|
||||
SR165 NewSR165(uint8_t pl, uint8_t ce, uint8_t cp, uint8_t q7);
|
||||
byte SR165_read(SR165 *sr);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
#include "Arduino.h"
|
||||
#include "595n.h"
|
||||
|
||||
SR595N NewSR595N(uint8_t ser, uint8_t rclk, uint8_t srclk) {
|
||||
struct SR595N newSR = {
|
||||
.ser = ser,
|
||||
.rclk = rclk,
|
||||
.srclk = srclk
|
||||
};
|
||||
|
||||
pinMode(newSR.ser, OUTPUT);
|
||||
pinMode(newSR.rclk, OUTPUT);
|
||||
pinMode(newSR.srclk, OUTPUT);
|
||||
|
||||
return newSR;
|
||||
}
|
||||
|
||||
void SR595N_write(SR595N *sr, uint8_t value) {
|
||||
digitalWrite(sr->rclk, LOW);
|
||||
shiftOut(sr->ser, sr->srclk, MSBFIRST, value);
|
||||
digitalWrite(sr->rclk, HIGH);
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
#ifndef __595N__
|
||||
#define __595N__
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct SR595N {
|
||||
uint8_t ser;
|
||||
uint8_t rclk;
|
||||
uint8_t srclk;
|
||||
} SR595N;
|
||||
|
||||
SR595N NewSR595N(uint8_t ser, uint8_t rclkh, uint8_t srclk);
|
||||
void SR595N_write(SR595N *sr, uint8_t value);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,48 @@
|
||||
/* BtnBOX by Eduardo Silva
|
||||
* Notes:
|
||||
* calling Wire.begin() will take use of the pins 2 and 3. Maybe try not using
|
||||
* them from the getgo
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "595n.h"
|
||||
#include "165.h"
|
||||
// #include "Wire.h"
|
||||
|
||||
// NOTES - 595N
|
||||
// On the board, the first output pin on the SR595 is Qb
|
||||
// Which means that our outputs go from 0b00000010 to 0b01111110
|
||||
#define IN_SERIAL_PIN 4 // SER - pin14 (Serial Pin)
|
||||
#define IN_LATCH_PIN 5 // RCLK - pin12 (Latch Pin)
|
||||
#define IN_CLOCK_PIN 6 // SRCLK - pin11 (Clock Pin)
|
||||
/*
|
||||
+-- --+
|
||||
|P5 P4 P3 P2 P1 P0|
|
||||
+-----------------+
|
||||
P0 0b00000010
|
||||
P1
|
||||
*/
|
||||
|
||||
// NOTES - 165
|
||||
#define OUT_PARALLEL_LOAD_IN 10 // PL - pin1 (Async Parallel Load In)
|
||||
#define OUT_CLOCK_IN 9 // CP - pin2 (Clock In)
|
||||
#define OUT_COMPLEMENTARY_OUT 8 // Q7 - pin7 (Complementary Output)
|
||||
#define OUT_CLOCK_ENABLE 7 // CE - pin15 (Clock Enable)
|
||||
|
||||
SR595N input = NewSR595N(IN_SERIAL_PIN, IN_LATCH_PIN, IN_CLOCK_PIN);
|
||||
SR165 output = NewSR165(OUT_PARALLEL_LOAD_IN, OUT_CLOCK_ENABLE,
|
||||
OUT_CLOCK_IN, OUT_COMPLEMENTARY_OUT);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
SR595N_write(&input, 0b10101010);
|
||||
}
|
||||
|
||||
void loop(void) {
|
||||
delay(200);
|
||||
|
||||
byte srOutput = SR165_read(&output);
|
||||
|
||||
Serial.println(srOutput, BIN);
|
||||
}
|
||||
Reference in New Issue
Block a user