stm32 +tm1638 只能显示,不能读键 为何?那地方出了问题 求大神指点。
时间:10-02
整理:3721RD
点击:
void TM1638_Write(unsigned char DATA) //D′êy?Yoˉêy
{
unsigned char i;
for(i=0;i<8;i++)
{
CLK=0;
if(DATA&0X01)
DIO=1;
else
DIO=0;
DATA>>=1;
CLK=1;
}
}
unsigned char TM1638_Read(void) //?áêy?Yoˉêy
{
unsigned char i;
unsigned char temp=0;
DIO=1; //éè???aê?è?
for(i=0;i<8;i++)
{
delay_us(5) ;
temp>>=1;
CLK=0;
if(DIO)
temp|=0x80;
CLK=1;
}
return temp;
}
void Write_COM(unsigned char cmd) //·¢?í?üá?×?
{
STB=0;
TM1638_Write(cmd);
STB=1;
}
unsigned char Read_key(void)
{
unsigned char c[4],i,key_value=0;
STB=0;
delay_ms(100);
TM1638_Write(0x42);
delay_ms(100);
for(i=0;i<4;i++)
{
c=TM1638_Read();
}
STB=1; //4??×??úêy?Yo?3éò???×??ú
if(c[0]==0x04) key_value=1;
if(c[0]==0x40) key_value=2;
if(c[1]==0x04) key_value=3;
if(c[1]==0x40) key_value=4;
if(c[2]==0x04) key_value=5;
if(c[2]==0x40) key_value=6;
if(c[3]==0x04) key_value=7;
if(c[3]==0x40) key_value=8;
if(c[0]==0x02) key_value=9;
if(c[0]==0x20) key_value=10;
if(c[1]==0x02) key_value=11;
if(c[1]==0x20) key_value=12;
if(c[2]==0x02) key_value=13;
if(c[2]==0x20) key_value=14;
if(c[3]==0x02) key_value=15;
if(c[3]==0x20) key_value=16;
return (key_value);
}
网上的代码,显示没问题。
while (1)
{
LedDisplay(1,3,7,0,2,1,0,2);
delay_ms(1000);
key_value=Read_key();
switch (key_value)
{
case 1:
LedDisplay(1,0,0,0,0,0,0,0);
break;
case 2 :
LedDisplay(2,0,0,0,0,0,0,0);
break;
case 3 :
LedDisplay(3,0,0,0,0,0,0,0);
break;
case 4 :
LedDisplay(4,0,0,0,0,0,0,0);
break;
case 5 :
LedDisplay(5,0,0,0,0,0,0,0);
break;
case 6 :
LedDisplay(6,0,0,0,0,0,0,0);
break;
case 7 :
LedDisplay(7,0,0,0,0,0,0,0);
break;
case 8 :
LedDisplay(8,0,0,0,0,0,0,0);
break;
case 9:
LedDisplay(9,0,0,0,0,0,0,0);
break;
case 10 :
LedDisplay(0,1,0,0,0,0,0,0);
break;
case 11 :
LedDisplay(1,1,0,0,0,0,0,0);
break;
case 12 :
LedDisplay(2,1,0,0,0,0,0,0);
break;
case 13 :
LedDisplay(3,1,0,0,0,0,0,0);
break;
case 14 :
LedDisplay(4,1,0,0,0,0,0,0);
break;
case 15:
LedDisplay(5,1,0,0,0,0,0,0);
break;
case 16 :
LedDisplay(6,1,0,0,0,0,0,0);
break;
default :
break;//LedDisplay(0,0,0,0,0,0,0,0);
}
有这方面经验的高手们 指点小生 一下。
有需要 stm32 驱动tm1638的工程的告诉我 我把我的工程放上来
悬赏这份 放在那里,没放上积分
悬赏这份 放在那里,没放上积分