I've been trying to interface a SN74HC594 chip to an AVR 2313 (using
avr-gcc)
and having a tough time with it.
I have the following function, but it appears as if only the MSB get's
set
every time it's called.
void write7SegChar(char displayValue) {
// Turn bit on PORTX |= BIT(x)
// Turn bit off PORTX &= ~BIT(x)
// Toggle bit PORTX ^= ~BIT(x)
//
// Load PB0 with serial value (MSB First)
// Pulse SCLK (PB1) with each value
// Pulse RCLK (PB2) after all eight bits are gone
//
// PB3 is RCLR
// PB4 is SCLR
PORTB &= ~(_BV(PB3) | _BV(PB4)); // bring RCLR & SCLR LOW for clear
PORTB |= (_BV(PB3) | _BV(PB4)); // bring high again
for (int i = 0; i < sizeof(char); i++) {
if((displayValue << i) & 0x80) {
PORTB |= _BV(PB0);
} else {
PORTB &= ~_BV(PB0);
}
PORTB |= _BV(PB1); // strobe SCLK
PORTB &= ~_BV(PB1);
}
PORTB |= _BV(PB2); // strobe RCLK
PORTB &= ~_BV(PB2);
return;
}
I have pull up resistors on all the clr and clock pins (PB1-PB4) so I
don't
think it's an open collector problem.
VCC is 5VDC, and the uP clock is at 4MHz so I shouldn't need any delay
when strobing clock or clear.
I can't see what I'm doing wrong here. Any suggestions are welcome.
Thanks,
Kevin
avr-gcc)
and having a tough time with it.
I have the following function, but it appears as if only the MSB get's
set
every time it's called.
void write7SegChar(char displayValue) {
// Turn bit on PORTX |= BIT(x)
// Turn bit off PORTX &= ~BIT(x)
// Toggle bit PORTX ^= ~BIT(x)
//
// Load PB0 with serial value (MSB First)
// Pulse SCLK (PB1) with each value
// Pulse RCLK (PB2) after all eight bits are gone
//
// PB3 is RCLR
// PB4 is SCLR
PORTB &= ~(_BV(PB3) | _BV(PB4)); // bring RCLR & SCLR LOW for clear
PORTB |= (_BV(PB3) | _BV(PB4)); // bring high again
for (int i = 0; i < sizeof(char); i++) {
if((displayValue << i) & 0x80) {
PORTB |= _BV(PB0);
} else {
PORTB &= ~_BV(PB0);
}
PORTB |= _BV(PB1); // strobe SCLK
PORTB &= ~_BV(PB1);
}
PORTB |= _BV(PB2); // strobe RCLK
PORTB &= ~_BV(PB2);
return;
}
I have pull up resistors on all the clr and clock pins (PB1-PB4) so I
don't
think it's an open collector problem.
VCC is 5VDC, and the uP clock is at 4MHz so I shouldn't need any delay
when strobing clock or clear.
I can't see what I'm doing wrong here. Any suggestions are welcome.
Thanks,
Kevin