I have been off doing other things.
Some of my work has been with clients, some has been in some classes in Business Administration that I have taken to run my company better.
The latest effort is back to the Um Counter project.
One thing I have looked at is the cost of doing the project with discrete components as shown or using a microcontroller.
It turns out that using a microcontroller is about 40% less expensive and allows me to add a lot of features.
The down side is I have to flail at things that I have no control over, such as the Arduino software. The biggest problem is that the documentation I have seen for using an SPI bus calls out an spi.h file that doesn’t seem to exist.
But that is okay, I just wrote my own from scratch.
Unfortunately I am getting ahead of myself.
Why would I need to use a 74HC595 serial to parallel shift register?
There are two different microcontrollers used on Arduino boards. (Actually there are three but the ATmega 168 and ATmega 328 are very similar.)
The micro on the Arduino Mega boards is the ATmega 2560.
At first I planned to just use the ATmega2560 because an interim prototype had been built as a shield for an Arduino Mega.
At Digikey, the ATmega2560 is $17.97 in quantities I can use.
The ATmega328 is $3.93 in the same quantities, 4.5 times less expensive.
All I need is additional outputs to run the display, so what else works?
It turns out that the 74HC595 sells for $0.73 which means I could use two of these and still spend less than half of what the ATmega2560 costs.
So if you need more outputs at a low cost the ’595 does just what I need.
So how do I develop code without having the finished boards?
Use prototype boards!
This will allow me to develop the code to drive the 74HC595 as a function (subroutine for folks with a ForTran background.)
This is the circuit:

To make a long story short here are the code sections:
The Header
/*************************************************************/
/* Sketch to set up a function to send data out an SPI */
/* to a 74HC595 Serial to Parallel Register Chip */
/* BConley Circuitsville Engineering 15 Jan 2012 1617PST */
/* Does NOT Make use of Included Arduino SPI functions */
/* Uses an Arduino Nano 3.0 w/ ATmega 328 */
/* On q proto board */
/*************************************************************/
/* Inputs: */
/* SDATIN on Board, Arduino Nano pin 15, D12, MISO, PB4*/
/* SENS_P5V on Board, Arduino Pin 19, A0 (analog) */
/* SENS_D_P5V on board, Arduino Pin 20, A1 (analog) */
/* Outputs: */
/* SDATOUT on board, Arduino Nano Pin 14, D11, MOSI, PB3*/
/* SCLK on board, Arduino Nano Pin 16, D13, SCK, PB5 */
/* XTRIO_CLR on board, Arduino Nano pin 14, D10, PB2 */
/* OUTCLK on board, Arduino Nano Pin 11, D8, PB0 */
/* Other IO: */
/* Green LED, Arduino Nano Pin 6, D3, PD3 */
/* Red LED, Arduino Nano Pin 7, D4, PD4 */
/*************************************************************/
/* 74HC595 considerations: */
/* MSB is first out, first in */
/* */
/* NOT Use SPI.setBitOrder(MSBFIRST) */
/* Output HIGH turns LED OFF */
/* 74HC595 Has TWO (2) Clocks !!! */
/* Both clock data on the rising clock edge */
/* SCLK clocks data into the register */
/* OUTCLK clocks data into the output register so it is seen*/
/*************************************************************/
/* Pre Set up (Declarations and such) */
/* NOTE: SPI Library does NOT work, so do something else */
/*************************************************************/
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
/* 74HC595 Function code section Declares & Defines */
/* Required FUNCTION Stuff-copy & paste into calling routine */
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
//int xtraIO_Clr = 10; Not used in this application
int clockPin = 13; /* Define register clock as Arduino D13*/
int dataPin = 11; /* Define serial data out as Arduino D11*/
int outClkPin = 10; /* Define output reg. clock as Arduino D10*/
int sDatInPin = 15; /* Define ser. Data input as Arduino D15*/
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
/* End Rqrd FUNCTION Stuff-copy & paste into calling routine */
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
What goes into the SETUP() Function
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
/* 74HC595 Code for the SETUP function */
/* Required FUNCTION Stuff-copy & paste into calling routine */
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
// pinMode (xtraIO_Clr,OUTPUT);
pinMode (clockPin,OUTPUT);
pinMode (outClkPin,OUTPUT);
pinMode (dataPin,OUTPUT);
pinMode (sDatInPin,INPUT);
digitalWrite(outClkPin,LOW);
digitalWrite(clockPin,LOW);
// digitalWrite(xtraIO_Clr,LOW); /* this Clears the HC595 */
// digitalWrite(xtraIO_Clr,HIGH);
digitalWrite(outClkPin,HIGH); /* loads the cleared reg into output */
digitalWrite(outClkPin,LOW);
digitalWrite(redOut,HIGH);
digitalWrite(grnOut,HIGH);
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
/* End Rqrd FUNCTION Stuff-copy & paste into calling routine */
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
The Function Code
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
/* Required FUNCTION Stuff-copy & paste into calling routine */
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
/*************************************************************/
/* sendHC595 function */
/* function to send a byte to an 74HC595 serial to parallel*/
/*************************************************************/
void sendHC595(unsigned char Data){
unsigned char SendCnt, BitCnt;
unsigned char DatClk = 0;
// shiftOut(dataPin, clockPin, MSBFIRST, Count);
SendCnt = Data; /* Copy Count into SendCnt*/
while(DatClk0){
digitalWrite(dataPin,HIGH); // If Bit is High, Put out 1
}
else{
digitalWrite(dataPin,LOW); // If Bit is LOW, Put out 0
}
SendCnt = SendCnt << 1; //Shift left one place
delay(100);
digitalWrite(clockPin,HIGH);
delay(100);
DatClk++;
} /* End clocking out, DatClk loop */
DatClk=0;
digitalWrite(outClkPin,HIGH); /* This sequence loads the data out */
delay(100);
digitalWrite(outClkPin,LOW); /* End data out squence */
} /* End sendHC595 function */
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
/* End Rqrd FUNCTION Stuff-copy & paste into calling routine */
/*FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF*/
That wasn’t too hard, was it?


























