|
请高手帮我看一下程序是否正确!谢谢(附电路图)
[复制链接]
程序如下:KEIL调试没错,不过仿真有问题!大家能不能帮我修改一下!
-
- #include
- #define keyR P0
- #define keyC P0
- sbit DE=P3^4;
- //sbit RD=P3^7;
- //sbit WR=P3^6;
- sbit A13=P2^5;
- sbit A14=P2^6;
- sbit A15=P2^7;
- sbit P00=P0^0;
- sbit P01=P0^1;
- sbit P02=P0^2;
- sbit P03=P0^3;
- sbit P04=P0^4;
- sbit P05=P0^5;
- sbit P06=P0^6;
- sbit P07=P0^7;
- char key[7][6]=0;
-
- void Delay1ms(unsigned int count)
- {
- unsigned int i,j;
- for(i=0;i
- for(j=0;j<120;j++);
- }
- void keycheck()
- {
- char led[7]={0,0,0,0,0,0,1};
- int i,j;
- char keyv[7]={1,2,4,8,16,32,64};
- P0=0x00;
- DE=1,WR=0;
- WR=1,A14=1,A13=1,A15=0;
- if((keyR &0x7f)!= 0x7f)
- {
- Delay1ms(20);
- if((keyR&0x7f)!= 0x7f)
- {
- P0=0X3E;
- DE=1,WR=0;
- WR=1,A14=0,A13=0,A15=1;//使SN74HC574N有效(上升沿有效);SN74HC244N有效(低电平有效)
- if((keyR&0x7f)!=0x7f)
- {
- for(i=0,j=0;i<6,j<6;i++,j++)
- {
- if(~keyR==keyv[i])
- {
- key[i][0]=1;
- led[j]=key[i][0];
- }
- }
- P0=0x01;
- DE=0,WR=0;WR=1;
- P00=~led[0];P01=~led[1];P02=~led[2];P03=~led[3];P04=~led[4];P05=~led[5];
- RD=0,DE=0;RD=1;
- }
-
- }
- else{
- P0=0X3D;
- DE=1,WR=0;
- WR=1,A14=0,A13=0,A15=1;
- if((keyR&0x7f)!=0x7f)
- {
- for(i=0,j=0;i<6,j<6;i++,j++)
- {
- if(~keyR==keyv[i])
- {
- key[i][1]=1;
- led[j]=key[i][1];
- }
- }
- P0=0x02;
- DE=0,WR=0;WR=1;
- P00=~led[0],P01=~led[1],P02=~led[2],P03=~led[3],P04=~led[4],P05=~led[5];
- RD=0,DE=0;RD=1;
- }
- }
- P0=0X3B;
- DE=1,WR=0;
- WR=1,A14=0,A13=0,A15=1;
- if((keyR&0x7f)!=0x7f)
- {
- for(i=0,j=0;i<6,j<6;i++,j++)
- {
- if(~keyR==keyv[i])
- {
- key[i][2]=1;
- led[j]=key[i][2];
- }
- }
- P0=0x10;
- DE=0,WR=0;WR=1;
- P00=~led[0];P01=~led[1];P02=~led[2];P03=~led[3];P04=~led[4];P05=~led[5];
- RD=0,DE=0;RD=1;
- }
-
- P0=0X37;
- DE=1,WR=0;
- WR=1,A14=0,A13=0,A15=1;
- if((keyR&0x7f)!=0x7f)
- {
- for(i=0,j=0;i<6,j<6;i++,j++)
- {
- if(~keyR==keyv[i])
- {
- key[i][3]=1;
- led[j]=key[i][3];
- }
- }
- P0=0x04;
- DE=0,WR=0;WR=1;
- P00=~led[5];P01=~led[4];P03=~led[2];
- RD=0,DE=0;RD=1;
- }
-
- P0=0X2F;
- DE=1,WR=0;
- WR=1,A14=0,A13=0,A15=1;
- if((keyR&0x7f)!=0x7f)
- {
- for(i=0;i<6;i++)
- {
- if(~keyR==keyv[i])
- {
- key[i][4]=1;
-
- }
- }
- }
-
- P0=0X1F;
- DE=1,WR=0;
- WR=1,A14=0,A13=0,A15=1;
- if((keyR&0x7f)!=0x7f)
- {
- for(i=0;i<7;i++)
- {
- if(~keyR==keyv[i])
- {
- key[i][5]=1;
- }
- }
- led[4]=key[4][5];
- P0=0x04;
- DE=0,WR=0;WR=1;
- P04=~led[4];
- RD=0,DE=0;RD=1;
- }
- }
- }
复制代码
|
|