A. 单片机控制74LS164控制数码管显示怎么编程(汇编语言)
74LS164是串入并出转换芯片,可以借助串口来实现,也可以用普通IO口模拟实现。举例如下:
#include<reg51.h>
#define uchar unsigned char
uchar table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f};
sbit keyup=P3^6;
sbit keydn=P3^7;
void delay()
{
int i=1000;
while(i--);
}
main()
{
uchar i;
i=0;
SCON=0x00;
TI=1;
while(1)
{
SBUF=table[i];
while(TI==0);
TI=0;
delay();
if(keyup==0)
{
i++;
while(keyup==0);
}
if(keydn==0)
{
if(i>0)i--;
while(keydn==0);
}
i%=10;
}
}
B. 51单片机中,如何编程使其按下第一个开关数显显示0(或1)...按下第8个开关数显显示7(或8)...
程序如下:
ORG0000H
;-----------------------------------------
START:
MOVA,P1;读入8个按键.
MOVB,A
CPLA
JZSTART
MOVR6,#8
CALLDL_R6_MS;延时消抖.
MOVA,P1;读入8个按键.
CJNEA,B,START
;-----------------------------------------
WAIT_KEY:
MOVA,P1;读入8个按键.
CPLA
JNZWAIT_KEY;等待按键释放.
;-----------------------------------------
MOVR2,#0;按键号码.
JNBB.0,_0
JNBB.1,_1
JNBB.2,_2
JNBB.3,_3
JNBB.4,_4
JNBB.5,_5
JNBB.6,_6
;-----------------------------------------
INCR2
_6:INCR2
_5:INCR2
_4:INCR2
_3:INCR2
_2:INCR2
_1:INCR2
_0:
;-----------------------------------------
MOVA,R2
MOVDPTR,#DUAN
MOVCA,@A+DPTR;
CPLA
MOVP0,A
SJMPSTART
;----------------------------------------------
DUAN:
DB0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
;0123456789
;----------------------------------------------
DELAY1MS:;延时:999T=1ms
MOVR7,#241
DJNZR7,$
DJNZR7,$
RET
;----------------------------------------------
DL_R6_MS:;延时:R6*1ms
ACALLDELAY1MS
DJNZR6,$-2
RET