用矩阵按键输入“0~9”、独立按键输入运算符,数码管显示输入数据及结果,做一个简易的10000以内加、减、乘运算。
我想问一下,我在实现用矩阵输入0-9的时候,该如何给值,书上的列子也没有看懂请问路过的好心人给我解解疑惑吧
#include"STC12C5A60S2.H" #define ON 0 #define OFF 1 sbit RS=P2^6; sbit RW=P2^7; sbit E=P4^4; sbit Back_Light=P4^5; sbit Buzz=P2^5; unsigned char Key_Code[16]= { 0xe7,0xd7,0xb7,0x77, 0xeb,0xdb,0xbb,0x7b, 0xed,0xdd,0xbd,0x7d, 0xee,0xde,0xbe,0x7e }; unsigned char Num_TAB[10]="0123456789"; void Init_INT(); void Init_LCD(); void Set_xy(unsigned char x,unsigned char y); void Wcom(unsigned char com); void WDat(unsigned char Dat); void Ready(); void Buzz_Start(); void Buzz_Stop(); void Delay(); void main() { P4SW=0xFF; Back_Light=ON; P1=0xF0; //这句不能漏,而且只能这样写,否则无法中断 Init_LCD(); Init_INT(); while(1); } void Init_INT() { TCON=0x00; EX0=1; EA=1; } void Init_LCD() { Wcom(0x00); Wcom(0x06); Wcom(0x38); Wcom(0x0F); Set_xy(0,1); } void Read_Key() interrupt 0 { unsigned char Key,Key_H,Key_L; unsigned char i=0; Buzz_Start(); P1=0x0F; //用我这种带中断按键,反转是分先后的;别人的不用。 if(P1!=0x0F) { Delay(); if(P1!=0x0F) { Key_L=P1&0x0F; } } P1=0xF0; if(P1!=0xF0) { Delay(); if(P1!=0xF0) { Key_H=P1&0xF0; } } Key=Key_H|Key_L; for(i=0;i<10;i++) { if(Key==Key_Code[i]) { WDat(Num_TAB[i]); } } while((P1&0xF0)!=0xF0); Buzz_Stop(); } void Set_xy(unsigned char x,unsigned char y) { if(y==1){Wcom(x|0x80);} if(y==2){Wcom(x|0xC0);} } void Wcom(unsigned char com) { Ready(); RS=0; RW=0; E=1; P0=com; E=0; } void WDat(unsigned char Dat) { Ready(); RS=1; RW=0; E=1; P0=Dat; E=0; } void Ready() { unsigned char sta; P0=0xFF; RS=0; RW=1; do { E=1; sta=P0; E=0; } while(sta&0x80); } void Buzz_Start() { Buzz=ON; } void Buzz_Stop() { Buzz=OFF; } void Delay() { unsigned char t=250; while(t--); }