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.

Switches and Keypads<br />

Listing 7-3. Test program for Figure 7-9’s circuits.<br />

10 XBY(1F00H)=49 : REM 1<br />

11 XBY(1F01H)=50 : REM 2<br />

12 XBY(1F02H)=51 : REM 3<br />

13 XBY(1F03H)=67 : REM C<br />

14 XBY(1F04H)=52 : REM 4<br />

15 XBY(1F05H)=53 : REM 5<br />

16 XBY(1F06H)=54 : REM 6<br />

17 XBY(1F07H)=68 : REM D<br />

18 XBY(1F08H)=55 : REM 7<br />

19 XBY(1F09H)=56 : REM 8<br />

20 XBY(1F0AH)=57 : REM 9<br />

21 XBY(1F0BH)=69 : REM E<br />

22 XBY(1F0CH)=65 : REM A<br />

23 XBY(1F0DH)=48 : REM 0<br />

24 XBY(1F0EH)=66 : REM B<br />

25 XBY(1F0FH)=70 : REM F<br />

30 DO<br />

40 ONEX1 100<br />

50 WHILE 1=1<br />

60 END<br />

100 KEY=XBY(0E000H).AND.0FH<br />

110 DAT=XBY(1F00H+KEY)<br />

120 PRINT CHR(DAT)<br />

130 RETI<br />

requested function. Chapter 8 describes how to add a small display to a system, so you don’t<br />

have to use the host computer’s display for the menu.<br />

For some projects, you may want to use the numeric values of the keys directly, rather than<br />

interpreting them as ASCII codes. In this case, you’ll need to revise the lookup table, or<br />

create a second table that matches the numeric values of the key legends with their data<br />

outputs. For example, a data output of 0 would correspond to 1, instead of 49 (the ASCII<br />

code for 1). Again, you usually can’t use the keypad encoder’s data outputs directly because<br />

they don’t correspond to the values printed on the keys.<br />

If an application requires that users enter multi-digit numbers on the keypad, your program<br />

will have to translate the individual digits into a single value. Listing 7-4 is a program that<br />

waits for the user to enter a 4-digit hex address, then displays the data stored at that address<br />

in external RAM.<br />

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

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

Saved successfully!

Ooh no, something went wrong!