SN54HC165, SN74HC165 8-Bit Parallel-Load Shift Registers

SN54HC165, SN74HC165 8-Bit Parallel-Load Shift Registers
Çeşme:
- http://electroniqueamateur.blogspot.com.tr/2014/04/etude-de-ci-registre-decalage-74hc165.html
- https://www.youtube.com/watch?t=478&v=hR6qOhUeKMc
#include <LiquidCrystal.h> LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define shiftLoadPin 9 #define clkPin 8 #define dataPin 10 int values[8]; void setup() { lcd.begin(16, 2); pinMode(shiftLoadPin, OUTPUT); digitalWrite(shiftLoadPin, HIGH); pinMode(clkPin, OUTPUT); digitalWrite(clkPin, LOW); pinMode(dataPin, INPUT); } void loop() { digitalWrite(shiftLoadPin, LOW); digitalWrite(shiftLoadPin, HIGH); for (int i=0; i <= 7; i++){ values[7-i] = digitalRead(dataPin); digitalWrite(clkPin, HIGH); digitalWrite(clkPin, LOW); } String t = ""; for (int i = 0; i < 8; i++) { t = t + values[i]; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("SN74HC165"); lcd.setCursor(0, 1); lcd.print(t); delay(800); }
#include <avr/io.h> #include <util/delay.h> #include <Arduino.h> int dataPin = PB2; int latchPin = PB1; int clockPin = PB0; int i; byte data; int main(void) { Serial.begin(9600); DDRB &= ~(1<<dataPin); DDRB |= (1<<latchPin); DDRB |= (1<<clockPin); while (1) { PORTB &= ~(1<<latchPin); PORTB |= (1<<latchPin); data = 0; for (i = 7; i >= 0; i--) { if ((PINB & (1<<dataPin)) != 0) { data = data | (1 << i); } PORTB |= (1<<clockPin); PORTB &= ~(1<<clockPin); } Serial.println(data, BIN); _delay_ms(100); } return 0; }