Forum breadcrumbs - You are here:ForumGeneral: Help74HC165 not working?
You need to log in to create posts and topics.

74HC165 not working?

I've build simple circuit using 74HC165 in real life, using Arduino UNO (without IDE), at it's works perfectly. But when I want to simulate using SimulIDE, it simply not works, and I have no idea what is not correct here, or it is some limitations on SimulIDE or am I doing something wrong, or it's a bug, please help me. I'm using Rev1917

This sketch I've tested in real life

Sketch

 

circuit

 

And code

#include <avr/io.h>
#include <util/delay.h>
#include <stdio.h>

#define LATCH PB2
#define SCK PB5
#define INPUT PB4

#define YELLOW_LED PD2
#define GREEN_LED PD3

void setup();
uint8_t spiRead(uint8_t data);
uint8_t readShiftRegister();

int main() {
setup();

while (1) {
uint8_tinput=readShiftRegister();

if (input& (1<<0)) {
PORTD |= 1 << GREEN_LED;
} else {
PORTD &= ~(1 << GREEN_LED);
}

if (input& (1<<1)) {
PORTD |= 1 << YELLOW_LED;
} else {
PORTD &= ~(1 << YELLOW_LED);
}

_delay_ms(500);
}

return0;
}

void setup() {
DDRB &= ~(1 << INPUT);
DDRB |= (1 << SCK) | (1 << LATCH);
DDRD |= (1 << YELLOW_LED) | (1 << GREEN_LED);

PORTB |= (1 << LATCH);

SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR0); // Enable SPI, Master mode, Fosc/16
}

uint8_t spiRead(uint8_t data) {
SPDR = data;
while (!(SPSR & (1<< SPIF)));
return SPDR;
}

uint8_t readShiftRegister() {
uint8_tdata;

PORTB &= ~(1 << LATCH);
_delay_us(1);
PORTB |= (1 << LATCH);

data=spiRead(0xFF);

returndata;
}

I am not expert in using simulIDE.

I simply noticed pin C6 (RESET) is not connected to 5V, unless its fuse is set to use C6 as I/O pin.

I've build simple circuit using 74HC165 in real life, using Arduino UNO (without IDE), at it's works perfectly. But when I want to simulate using SimulIDE, it simply not works, and I have no idea what is not correct here, or it is some limitations on SimulIDE or am I doing something wrong, or it's a bug, please help me. I'm using Rev1917

Hi, I don't know what can be the problem, but your code is working for me.
You can try the files attached to this post.

Uploaded files:
lvivgeorge has reacted to this post.
lvivgeorge
Quote from KerimF on October 31, 2024, 4:39 pm

I am not expert in using simulIDE.

I simply noticed pin C6 (RESET) is not connected to 5V, unless its fuse is set to use C6 as I/O pin.

Thanks for reply, not sure what was the issue, but I simply checked next day without any changes and it worked.

arcachofo

Thanks for help! I'm not sure why, but I've checked this morning your and mine projects, and both worked, it is a bit strange, but thanks again!

Quote from lvivgeorge on November 1, 2024, 6:45 am

arcachofo

Thanks for help! I'm not sure why, but I've checked this morning your and mine projects, and both worked, it is a bit strange, but thanks again!

Maybe we are onto something here...
Something like this happened few days ago, and maybe some other times before.

Could be that there is something randomly failing, I will investigate.

Thanks to you for reporting.