A Free Template From Joomlashack

A Free Template From Joomlashack

Sign in with a social network::

Powered by OneAll Social Login

Who is online

We have 10 guests online

Chat with us

I/O Expansion PDF Print E-mail
Written by Vlado Berend   

I had a requirement where a 20-pin microcontroller had to drive one LED display plus other peripherals. To drive the LED display, required 8 pins that were not available, because they were already used by other peripherals. After a literature search, I found a cheap shift register which performs like the PCF8574 (which is not cheap at all!).

Using shift registers has been mentioned in various places including the Svet elektronike magazine, but none contained a practical example. In this chapter I will show you a practical way to implement this. For this purpose, PCBs were designed to drive four 7-segment LED displays as well as a 32 LED circular bar-graph display. The basic circuit is shown in Figure 1. The shift register is driven using the pins Strobe (ST), clock (CLK) and data (DATA).

Before we write the data (which will be shifted into the shift register), we must first set the strobe pin to logical 1 (note that the pin on the microcontroller is also labelled STR). Then on the data pin we set a data value (0 or 1) followed by setting the clock pin to logical 1. By setting the clock pin to a logical 1, the shift register shifts that data by one bit, into its 8-bit register. After that, we reset the clock pin to a logical 0, set a new data value, for the second bit, and raise the clock pin to a logical 1 again. This sequence is repeated until all 8 bits are shifted in. At the end of this sequence, we must reset the strobe pin to a logical 0, which transfers the register data to the output pins (Q1 – Q8). Let’s look at a Bascom program (Out_port.bas) which does this.

Dim I As Word , N As Byte , V As Byte , 
C As Byte , Z As Byte
Config Portd = Output
Portd = 0
Strobe Alias Portd.2              ‘to pin 1 CD4094
Dat Alias Portd.3                   ‘to pin 2 CD4094
Clk Alias Portd.4                   ‘to pin 3 CD4094
N = 255                                ‘all outputs are set to high
Gosub 4094
 Input I
 N.i = Not N.i
 Gosub 4094
  Set Strobe                         ‘enable writing
  For C=7 To 0 Step-1           ‘each bit of variable
Dat = N.c
Set Clk
Reset Clk
  Reset Strobe                   ‘shift register changes do not, 
affect output until strobe goes low

By setting N = 255 (binary = 11111111), we set all bits to a logical 1 and therefore no LED is lit. If we want to turn on one LED we have to pull down that particular bit. Many newbies don’t know that one can change a bit within a variable very easily. For example: if a variable (N) has a value 255 (binary 11111111) and you want to change only the least-significant bit to 0, (binary 11111110) you can do that very easily using the statement N.0 = 0. With this simple statement you can change single bits in your byte variable.

I/O Expansion


Continue reading

Shop area

Last Updated on Wednesday, 01 August 2012 14:34
Joomla Tutorial: by JoomlaShack