CPU控制的键盘扫描实验.docxVIP

  • 2
  • 0
  • 约2.35千字
  • 约 6页
  • 2023-03-20 发布于上海
  • 举报
CPU 键盘扫描实验 电路图如下: 要求按下 s1 键时,p3 口的 8 位 LED 正向流水点亮;按下 s2 键时,p3 口的 8 位 LED 反向流水点亮;按下 s3 键时,p3 口的 8 位 LED 熄灭;按下 s4 键时,p3 口的 8 位 LED 闪烁。 程序代码: #includereg51.h unsigned char tab[ ]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f}; //段码表sbit S1=P1^4; //将 S1 位定义为 P1.4 引脚 sbit S2=P1^5; //将 S2 位定义为 P1.5 引脚sbit S3=P1^6; //将 S3 位定义为 P1.6 引脚sbit S4=P1^7; //将 S4 位定义为 P1.7 引脚 /*流水灯延时*/ void delay0() { unsigned char i,j; for(i=0;i250;i++) for(j=0;j250;j++) ; } /*软件消抖延时*/ void delay1() { unsigned char i,j; for(i=0;i100;i++) for(j=0;j100;j++) ; } /*正转*/ void zheng() { int i; for(i=0;i8;i++) {P3=tab[i]; delay0();} } /

文档评论(0)

1亿VIP精品文档

相关文档