最近开始学单片机外围芯片的控制方法。每学一个,都会把调完的程序发到论坛上共享。这些程序高手应该都司空见惯了,但对于我来说,这些都是我学习的痕迹。希望以后回过头来,能看到过去学习的点点滴滴,以作纪念。 本人菜鸟一只,希望高手多多指教。
/************************************************************************** This program uses 8279 to show the number which is pressed on the keyboard. Each time one key is pressed,it will be shown on the right side.And other numbers will be rotate to the left.And the left side number will be dropped. (Book Exp14 Question 1 )
BUG:No de-shaking!! *********************************************************************/ #include <reg51.h> #define uchar unsigned char xdata uchar COM _at_ 0xFF01;//address of 8279's control/state word xdata uchar DAT _at_ 0xFF00;//address of 8279's date register uchar code table[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e}; uchar idata diss[8] = {0,0,0,0,0,0,0,0}; sbit clflag = ACC ^ 7; uchar keyin(); uchar deky(); void disp(uchar idata * d);
void main(void) { uchar i,temp; char j; COM = 0xde; do {ACC = COM;} while(clflag == 1);/* wait for the clear*/ COM = 0x10; COM = 0x80; COM = 0x2a; while(1) { for(i = 0;i < 8;i ++) { disp(diss);/*show the buffer*/ temp = keyin(); for(j = 6;j >= 0;j --) diss[j+1] = diss[j]; diss[0] = temp; } } }
void disp(uchar idata * d) /* show function*/ { uchar i; COM = 0x90; for(i = 0;i < 8;i ++) { COM = i+0x80;/*IF THIS CAN BE OMIT,tested:yes*/ DAT = table[* d]; d ++; } }
uchar keyin(void) { uchar i; while(deky() == 0); //No key is press // delay(); //de-shaking COM = 0x40; //read FIFO RAM i = DAT; // i = i & 0x3f; //get the value of the key return (i); //return the value of the key }
uchar deky(void) //judge if the FIFO has key pressed { uchar k; k = COM; return (k & 0x0f); //0 represents no key is pressed }
|