程序编好了 在protuer中仿真后输出的结果是 1 5 9 13 1 5 9 13 1 5 9 13 1 5 9 13
设计结果应该是 1 5 9 13 2 6 10 14 3 7 11 15 4 8 12 16
请个位大侠帮帮看看!!!!
#include <AT89X51.H> #define uchar unsigned char #define uint unsigned int void dlms(void); uchar kbscan(void);
void main(void) { uchar j; while (1) { j=kbscan(); dlms(); switch (j) { case 0x11: P1= 1; break; case 0x12: P1 = 2; break; case 0x14: P1 = 3; break; case 0x18: P1= 4; break; case 0x21: P1= 5; break; case 0x22: P1= 6; break; case 0x24: P1 = 7; break; case 0x28: P1= 8; break; case 0x41: P1= 9; break; case 0x42: P1= 10;break; case 0x44: P1= 11;break; case 0x48: P1= 12;break; case 0x81: P1= 13;break; case 0x82: P1= 14;break; case 0x84: P1= 15;break; case 0x88: P1= 16; break; default : P1=0; } } }
void dlms(void) { uchar i; for(i=200;i>0;i--){} }
uchar kbscan(void) {uchar s,r; P0=0xf0; if ((P0&0xf0)!=0xf0) {dlms(); if ((P0&0xf0)!=0xf0) {s=0xfe; while ((s&0x10)!=0) { P0=s; if ((P0&0xf0)!=0xf0) {r=(P0&0xf0)|0x0f; return ((~s)+(~r)); } else s=(s<<1)|0x01; } } } return(0); } |