Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ShiftLCD.h>
- #define NUMBER_OF_SHIFT_CHIPS 1
- #define DATA_WIDTH NUMBER_OF_SHIFT_CHIPS * 8
- #define PULSE_WIDTH_USEC 5
- #define POLL_DELAY_MSEC 1
- #define BYTES_VAL_T unsigned int
- // initialize the library with the numbers of the interface pins
- ShiftLCD lcd(2, 4, 3);
- // id 2 data ic1
- // id 3 IC pin 12, Clock, Storage Register Clock input ST_CP
- // id 4 IC pin 11, Strobe, Clock input SH_CP
- //Pin connected to latch pin (ST_CP) of 74HC595
- const int latchPin = 3;
- //Pin connected to clock pin (SH_CP) of 74HC595
- const int clockPin = 4;
- ////Pin connected to Data in (DS) of 74HC595
- const int dataPin = 5;
- char inputString[2];
- int ploadPin = 7; // Connects to Parallel load pin the 165
- //int clockEnablePin = 9; // Connects to Clock Enable pin the 165
- int inputdataPin = 6; // Connects to the Q7 pin the 165
- int inputclockPin =8; // Connects to the Clock pin the 165
- BYTES_VAL_T pinValues;
- BYTES_VAL_T oldPinValues;
- BYTES_VAL_T read_shift_regs()
- {
- byte bitVal;
- BYTES_VAL_T bytesVal = 0;
- /* Trigger a parallel Load to latch the state of the data lines,
- */
- digitalWrite(ploadPin, LOW);
- delayMicroseconds(PULSE_WIDTH_USEC);
- digitalWrite(ploadPin, HIGH);
- /* Loop to read each bit value from the serial out line
- * of the SN74HC165N.
- */
- for(int i = 0; i < DATA_WIDTH; i++)
- {
- bitVal = digitalRead(inputdataPin);
- /* Set the corresponding bit in bytesVal.
- */
- bytesVal |= (bitVal << ((DATA_WIDTH-1) - i));
- Serial.print(bytesVal, DEC);
- lcd.setCursor(0, 1);
- // print the number of seconds since reset:
- lcd.print(bytesVal, DEC);
- /* Pulse the Clock (rising edge shifts the next bit).
- */
- digitalWrite(inputclockPin, HIGH);
- delayMicroseconds(PULSE_WIDTH_USEC);
- digitalWrite(inputclockPin, LOW);
- }
- return(bytesVal);
- }
- /* Dump the list of zones along with their current status.
- */
- void display_pin_values()
- {
- Serial.print("Pin States:\r\n");
- for(int i = 0; i < DATA_WIDTH; i++)
- {
- Serial.print(" Pin-");
- Serial.print(i);
- Serial.print(": ");
- if((pinValues >> i) & 1)
- Serial.print("HIGH");
- else
- Serial.print("LOW");
- Serial.print("\r\n");
- }
- Serial.print("\r\n");
- }
- void setup() {
- // set up the LCD's number of rows and columns:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- lcd.print("ILZ-KOFFIE-01");
- pinMode(latchPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- Serial.begin(9600);
- Serial.println("reset");
- pinMode(ploadPin, OUTPUT);
- pinMode(inputdataPin, INPUT);
- pinMode(inputclockPin, OUTPUT);
- digitalWrite(ploadPin, HIGH);
- pinValues = read_shift_regs();
- display_pin_values();
- oldPinValues = pinValues;
- }
- void loop() {
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- // for (int numberToDisplay = 0; numberToDisplay < 256; numberToDisplay++) {
- digitalWrite(latchPin, LOW);
- int numberToDisplay = 254;
- shiftOut(dataPin, clockPin, MSBFIRST, numberToDisplay);
- delay(200);
- digitalWrite(latchPin, HIGH);
- delay(200);
- // update();
- pinValues = read_shift_regs();
- /* If there was a chage in state, display which ones changed.
- */
- if(pinValues != oldPinValues)
- {
- Serial.print("*Pin value change detected*\r\n");
- display_pin_values();
- oldPinValues = pinValues;
- }
- delay(POLL_DELAY_MSEC);
- // }
- }
- void update() {
- lcd.setCursor(0, 1);
- // print the number of seconds since reset:
- lcd.print(millis()/1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement