User manual
LPCXpresso Experiment Kit - User’s Guide
Page 70
Copyright 2013 © Embedded Artists AB
Create a subroutine for updating the shift register. Let the subroutine take an 8-bit variable as input,
where bit 0 represents segment A, bit 1 segment B, etc. The suggested structure of the subroutine is
presented in the code block below.
void updateShiftReg( uint8_t segments )
{
uint8_t bitCnt;
//Pull SCK and MOSI low, pull SSEL low
...
//wait 1us
...
//Loop through all eight bits
for (bitCnt = 0; bitCnt < 8; bitCnt++)
{
//output MOSI value (bit 7 of “segments”)
...
//wait 1us
...
//pull SCK high
...
//wait 1us
...
//pull SCK low
...
//shift “segments”
segments = segments << 1;
}
//Pull SSEL high
...
}
The suggested delay values are quite small (1us). They can be smaller according to the 74HC595
datasheet, but for simplicity you can use 1us. The previous delay function created had a resolution of
1ms. Update this function so that it is possible to also have smaller values in the microsecond region.
Finally create a look-up table for getting the segment values given a number between 0 and 9.