Serial to parallel converter 74HC595

published: 17 November 2019 / updated 16 November 2020

Lire cette page en français

 

Presentation

pins diagram

The symbols are from the Texas Instruments documentation.

PINSYMBOLDESCRIPTION
1Q1parallel data output
2Q2parallel data output
3Q3parallel data output
4Q4parallel data output
5Q5parallel data output
6Q6parallel data output
7Q7parallel data output
8GNDground (0 V)
9Q7parallel data output
10SRCLRmaster reset (active LOW)
11SRCLKShift Register CLocK input
12RCLKRegister CLocK input
13OEoutput enable (active LOW)
14SERSERial data input
15Q0parallel data output
16VCCpositive supply voltage

Connecting the 74HC595 converter

In order not to overload the ARDUINO board, the converter is powered by a source external, here in red on the prototyping board.

connecting the 74HC595 to the ARDUINO MEGA board
pinvers - to
10SRCLR -> external +5V
11SRCLK -> PB6 - pin 12 ARDUINO MEGA
12RCLK -> PB5 - pin 11 ARDUINO MEGA
13OE -> external GND
14SER -> PB4 - pin 10 ARDUINO MEGA
16VCC -> external +5V

Serial to parallel conversion

We define in advance the PORTB:

\ for more 1 74HC595, change 1 by number of HC595 
1 constant NB_74HC595 
NB_74HC595 8 * constant NB_REG_PINS \ number of Register Pins 
 
\ PORTB 
37 constant PORTB	\ Port B Data Register 
36 constant DDRB	\ Port B Data Direction Register 
\ 35 constant PINB	\ Port B Input Pins - unused 

The words defPIN: high low output input and pin@ are described in the article Definition and management of PORT connections

With defPIN: we create the words SER RCLK SRCLK. These words designates connectors of the ARDUINO cate and are named according to their use in relation with the 74HC595 converter:

\ for Arduino MEGA 
PORTB %00010000 defPIN: SER     \ PB4 -> pin 14 on the 74HC595 - dataPin 
PORTB %00100000 defPIN: RCLK    \ PB5 -> pin 12 on the 74HC595 - latchPin 
PORTB %01000000 defPIN: SRCLK   \ PB6 -> pin 11 on the 74HC595 - clockPin 
\ PORTB %10000000 defPIN: OE      \ PB7 -> pin 13 on the 74HC595 

The word init.74HC595 initializes the bits of the PORTB designated by SER RCLK SRCLK as outputs and set these bits low.

: init.74HC595 ( ---) 
    SER     output 
    RCLK    output 
    SRCLK   output 
    SER     low 
    RCLK    low 
    SRCLK   low 
  ; 

The word csend sends a byte to the 74HC595 converter. The word csend provides serialization of the bit byte:

: csend ( c ---) 
    RCLK low                    \ latchPin LOW 
    NB_REG_PINS 
    for 
        dup $80 and 
        if      SER high        \ datapin HIGH 
        else    SER low         \ datapin LOW 
        then 
        1 lshift 
        SRCLK high              \ clockPin HIGH 
        SRCLK low               \ clockPin LOW 
    next 
    drop     
    RCLK high                   \ latchPin HIGH 
  ; 

Complete source code

The complete listing is available here: 8 bit data in serial and send it to 74HC595 chip