Hardware Reference
In-Depth Information
; *********************************************************************************
; Each digit consists of 2 bytes of data. The first byte is
; digit select; the second byte is the digit pattern.
; *********************************************************************************
disp_tab
dc.b
$80,$7F,$40,$70,$20,$5F,$10,$5B
dc.b
$08,$33,$04,$79,$02,$6D,$01,$30
end
The C language version of the program is as follows:
#include “c:\cwHCS12\include\hcs12.h”
#include “c:\cwHCS12\include\spi0util.h”
// include spi0util.c into the project
#include “c:\cwHCS12\include\delay.h”
// include delay.c into the project
void openspi0(void);
void main (void)
{
unsigned char disp_tab[8][2] 5 {{0x80,0x7F},{0x40,0x70},{0x20,0x5F},{0x10,0x5B},
{0x08,0x33},{0x04,0x79},{0x02,0x6D},{0x01,0x30}};
char i;
openspi0();
/* configure the SPI0 module */
DDRK ⏐5 BIT7;
/* configure pin PK7 as output */
while(1) {
for (i 5 0; i , 8; i 11 ) {
putcspi0(disp_tab[i][0]);
/* send out digit select value */
putcspi0(disp_tab[i][1]);
/* send out segment pattern */
PTK & 5 ,, BIT7;
/* transfer values to latches of 74HC595s */
PTK ⏐5 BIT7;
/* “ */
delayby1ms(1);
/* display a digit for 1 ms */
}
}
}
void openspi0(void)
{
SPI0BR 5 0;
/* set baud rate to 12 MHz */
SPI0CR1 5 0x50;
/* disable SPI interrupt, enable SPI, SCK idle low, shift
data on rising edge, shift data msb first */
SPI0CR2 5 0x02;
/* disable bidirectional mode, disable SPI in wait mode */
WOMS 5 0;
/* enable Port S pull up */
}
This example illustrates one of the applications of the shift register 74HC595. The main
drawback of the example program is that the CPU spends all its time on the task of multiplex-
ing the displays. The program can be modified to be interrupt-driven to free the CPU from idle
waiting. Several manufacturers produce LED display drivers to eliminate the display multi-
plexing task altogether. The MC14489 from Freescale and the MAX7221 from Maxim are two
examples.
 
Search WWH ::




Custom Search