18.11.2014 Views

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

The Microcontroller Idea Book - Jan Axelson's Lakeview Research

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 8<br />

Listing 8-3. Controls eight 7-segment LEDs with ICM7218 driver.<br />

10 REM address of 8255 Port A<br />

20 A=0FC00H<br />

30 REM address of 8255 control word<br />

40 X=A+3<br />

50 REM set 8255 for all outputs<br />

60 XBY(X)=80H<br />

70 REM set WR<br />

80 XBY(X)=9<br />

90 REM write to each digit<br />

100 FOR M=0 TO 7<br />

110 REM step through all numbers at each digit<br />

120 FOR I=0 TO 8<br />

130 REM add 10h to turn off decimal point<br />

140 D=I+10H+M*20H<br />

150 GOSUB 500<br />

160 REM delay to display each digit<br />

170 K=500<br />

180 FOR J=1 TO K : NEXT J<br />

190 NEXT I<br />

200 NEXT M<br />

210 END<br />

490 REM write data to port A and toggle W (PC.4)<br />

500 XBY(A)=D<br />

510 XBY(X)=8H<br />

520 XBY(X)=9<br />

530 RETURN<br />

range for peak current for most LEDs, and the 2.5-milliampere average current causes the<br />

displays to appear brighter than you might expect. With all digits displaying 8’s, this circuit<br />

draws 140 milliamperes, so be sure your power supply can handle it.<br />

To write a value to the display, you select the digit with data-address inputs DA0-DA2, write<br />

the data to inputs ID0-ID7, and strobe WRITE low. <strong>The</strong> WRITE pulse must be at least 400<br />

nanoseconds wide, and ID0-ID7 must remain valid for at least 125 nanoseconds after WRITE<br />

goes high. BASIC-52 is slow enough to meet these requirements, using XBY statements to<br />

write to the port that controls the 7218C.<br />

Pin 9 allows you to select one of three modes, which determine what digits the displays<br />

show. In Code B mode, you can display the message HELP.<br />

134 <strong>The</strong> <strong>Microcontroller</strong> <strong>Idea</strong> <strong>Book</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!