/* **********scan11.c***************** Scanned matrix keyboard program for the MC68HC11EVB This example accompanies the book "Embedded Microcomputer Systems: Real Time Interfacing", Brooks-Cole, copyright (c) 2000, Jonathan W. Valvano 7/6/99 Interface between the TExaS simulator running a MC68HC11 EVB with ICC11 freeware compiler TExaS Copyright 1999 by Jonathan W. Valvano for more information about ICC11 see http://www.imagecraft.com You may use this file without restrictions Port C bits PC7-PC4 are open collector row drivers, Port C bits PC3-PC0 are inputs from the row */ #include "HC11.h" const struct Row{ unsigned char out; unsigned char keycode[4];}; typedef const struct Row RowType; RowType ScanTab[5]={ { 0x70, "abcd" }, { 0xB0, "efgh" }, { 0xD0, "ijkl" }, { 0xE0, "mnop" }, { 0x00, " " }}; void Ritual(void){ /* PC3-PC0 are inputs */ PIOC=0x40; /* CWOM=1 */ DDRC=0xF0;} /* PC7-PC4 are outputs */ /* Returns ASCII code for key pressed, Num is the number of keys pressed both equal zero if no key pressed */ unsigned char Scan(unsigned int *Num){ RowType *pt; unsigned char column,key; int j; (*Num)=0; key=0; /* default values */ pt=&ScanTab[0]; while(pt->out){ PORTC=pt->out; /* select row */ column=PORTC; /* read columns */ for(j=3; j>=0; j--){ if((column&0x01)==0){ key=pt->keycode[j]; (*Num)++;} column>>=1;} /* shift into position */ pt++; } return key;} #define bufsize 10 unsigned char buf[bufsize]; unsigned char *pt; unsigned char letter; unsigned int n; void main(void){ unsigned int i; pt=&buf[0]; Ritual(); for(i=0;i