共2条
1/1 1 跳转至页
问
"P1口具有内部上拉电阻,当端口用作输入时,必须通过指令将端口的位锁存器置1",请问用哪条指令将位锁存器置1?谢谢
我的程序是这样写的:
mov a,#00001111B
mov p1,a ;p1.0 p1.1 p1.2 p1.3是输入口
mov a,p1
xrl a,#0FH
jz ISK0 ;f*1输出
xrl a,#1FH
jz ISK1 ;f*2输出
xrl a,#2FH
jz ISK2 ;f*3输出
xrl a,#3FH
jz L3
L3: ljmp ISK3 ;f*4输出
xrl a,#4FH
........
P1口是4个开关(0n-off),检测开关的不同状态的!请问用哪条指令将位锁存器置1? 答 1: 请大家帮忙!我初学单片机,请问用哪条指令将位锁存器置1,我这个程序用将位锁存器置1吗?
我的硬件图:
http://www.21icsearch.com/buzi/upimage/upfile/20054161653490.jpg
答 2: 高4位被封锁程序好象是在无键压下时,根据P1口的高8位进行分支...
将:
mov a,#00001111B
mov p1,a ;p1.0 p1.1 p1.2 p1.3是输入口
改为:
mov p1,#0ffh ;测试高4位XXX,低4位测试键盘
答 3: 谢谢 hotpower,我去试试 答 4: 还是不行,我的程序是根据输入方波频率,输出是1-16倍频!;;p2.0 is output port;p3.2 is wave input;p1.0,p1.1,p1.2,p1.3 are input key.
;;input wave is below 2kHz.
CounterH EQU 030H
CounterL EQU 031H
TimerH equ 032h
TimerL equ 033h
Counter1H equ 034H
Counter1L equ 035H
Timer1H equ 036H
Timer1L equ 037H
Timer2H equ 038H
Timer2L equ 039H
ORG 0000H
LJMP START
org 0400H
START:
mov sp,#60h
mov a,#11111110B
mov p2,a ;p2.0 是输出口
mov a,#00001111B
mov p1,a ;p1.0 p1.1 p1.2 p1.3是输入口
mov a,0
mov CounterH,a
mov CounterL,a
mov TimerH,a
mov TimerL,a
mov TMOD,#019H ;设置工作方式寄存器
mov TL0,#00H
mov TH0,#00H
;;;;测P3.2口方波低电平宽度
jb p3.2, $ ; 等待/INT0变低
setb TR0 ; 启动定时
jnb p3.2, $ ; 一旦/INT0变高,启动定时
jb p3.2, $ ;等待/INT0再变低
clr TR0
mov a,TL0
mov CounterL,a
mov a,TH0
mov CounterH,a
;;;;周期/50 即为:频率*50
sub1:
clr c
mov a,CounterL
subb a,#50d
jnc getTimer
mov a,CounterH
jz readKey
dec CounterH
clr c
mov a,#0ffh
subb a,#50d
setb c
addc a,CounterL
getTimer:
mov CounterL,a
inc TimerL
mov a,TimerL
jnz sub1
inc TimerH
jnz sub1
;;;;read key读开关状态,1ms查询开关状态一次
readKey:
mov TL1,#0FCH ;定时器1赋初值
mov TH1,#18H
setb TR1 ;启动定时器
DLY:
jbc TF0,REP ;查询计数溢出
ajmp DLY
REP:
mov TL1,#0FCH ;定时器1赋初值
mov TH1,#18H
mov a,TimerL
mov Counter1L,a
mov a,TimerH
mov Counter1H,a
mov a,p1
xrl a,#0FH
jz ISK0 ;f*1输出
xrl a,#1FH
jz ISK1 ;f*2输出
xrl a,#2FH
jz ISK2 ;f*3输出
xrl a,#3FH
jz L3
L3: ljmp ISK3 ;f*4输出
xrl a,#4FH
jz L4
L4: ljmp ISK4 ;f*5输出
xrl a,#5FH
jz L5
L5: ljmp ISK5 ;f*6输出
xrl a,#6FH
jz L6
L6: ljmp ISK6 ;f*7输出
xrl a,#7FH
jz L7
L7: ljmp ISK7 ;f*8输出
xrl a,#8FH
jz L8
L8: ljmp ISK8 ;f*9输出
xrl a,#9FH
jz L9
L9: ljmp ISK9 ;f*10输出
xrl a,#0AFH
jz L10
L10: ljmp ISK10 ;f*11输出
xrl a,#0BFH
jz L11
L11: ljmp ISK11 ;f*12输出
xrl a,#0CFH
jz L12
L12: ljmp ISK12 ;f*13输出
xrl a,#0DFH
jz L13
L13: ljmp ISK13 ;f*14输出
xrl a,#0EFH
jz L14
L14: ljmp ISK14 ;f*15输出
xrl a,#0FFH
jz L15
L15: ljmp ISK15 ;f*16输出
ajmp DLY
ISK0:
mov Timer1L,Counter1L
mov Timer1H,Counter1H
ljmp outputWave
ISK1:
clr c
mov a,Counter1H
rrc a
mov Timer1H,a
mov a,Counter1L
rrc a
mov Timer1L,a
ljmp outputWave
ISK2:
clr c
mov a,Counter1L
subb a,#3d
jnc getTimer2
mov a,Counter1H
jz I2
I2: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#3d
setb c
addc a,Counter1L
getTimer2:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK2
inc Timer1H
jnz ISK2
ISK3:
clr c
mov a,Counter1L
subb a,#4d
jnc getTimer3
mov a,Counter1H
jz I3
I3: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#4d
setb c
addc a,Counter1L
getTimer3:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK3
inc Timer1H
jnz ISK3
ISK4:
clr c
mov a,Counter1L
subb a,#5
jnc getTimer4
mov a,Counter1H
jz I4
I4: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#5
setb c
addc a,Counter1L
getTimer4:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK4
inc Timer1H
jnz ISK4
ISK5:
clr c
mov a,Counter1L
subb a,#6d
jnc getTimer5
mov a,Counter1H
jz I5
I5: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#6d
setb c
addc a,Counter1L
getTimer5:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK5
inc Timer1H
jnz ISK5
ISK6:
clr c
mov a,Counter1L
subb a,#7d
jnc getTimer6
mov a,Counter1H
jz I6
I6: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#7d
setb c
addc a,Counter1L
getTimer6:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK6
inc Timer1H
jnz ISK6
ISK7:
clr c
mov a,Counter1L
subb a,#8d
jnc getTimer7
mov a,Counter1H
jz I7
I7: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#8d
setb c
addc a,Counter1L
getTimer7:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK7
inc Timer1H
jnz ISK7
ISK8:
clr c
mov a,Counter1L
subb a,#9d
jnc getTimer8
mov a,Counter1H
jz I8
I8: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#9d
setb c
addc a,Counter1L
getTimer8:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK8
inc Timer1H
jnz ISK8
ISK9:
clr c
mov a,Counter1L
subb a,#10d
jnc getTimer9
mov a,Counter1H
jz I9
I9: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#10d
setb c
addc a,Counter1L
getTimer9:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK9
inc Timer1H
jnz ISK9
ISK10:
clr c
mov a,Counter1L
subb a,#11d
jnc getTimer10
mov a,Counter1H
jz I10
I10: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#11d
setb c
addc a,Counter1L
getTimer10:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK10
inc Timer1H
jnz ISK10
ISK11:
clr c
mov a,Counter1L
subb a,#12d
jnc getTimer11
mov a,Counter1H
jz I11
I11: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#12d
setb c
addc a,Counter1L
getTimer11:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK11
inc Timer1H
jnz ISK11
ISK12:
clr c
mov a,Counter1L
subb a,#13d
jnc getTimer12
mov a,Counter1H
jz I12
I12: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#13d
setb c
addc a,Counter1L
getTimer12:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK12
inc Timer1H
jnz ISK12
ISK13:
clr c
mov a,Counter1L
subb a,#14d
jnc getTimer13
mov a,Counter1H
jz I13
I13: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#14d
setb c
addc a,Counter1L
getTimer13:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK13
inc Timer1H
jnz ISK13
ISK14:
clr c
mov a,Counter1L
subb a,#15d
jnc getTimer14
mov a,Counter1H
jz I14
I14: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#15d
setb c
addc a,Counter1L
getTimer14:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK14
inc Timer1H
jnz ISK14
ISK15:
clr c
mov a,Counter1L
subb a,#16d
jnc getTimer15
mov a,Counter1H
jz I15
I15: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#16d
setb c
addc a,Counter1L
getTimer15:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK15
inc Timer1H
jnz ISK15
outputWave:
c1: cpl p2.0
mov Timer1L,Timer2L
mov Timer1H,Timer2H
c2: djnz Timer2L,c2
mov Timer2L,0FFH
djnz Timer2H,C2
ajmp C1
end
看看哪里有问题?
我的程序是这样写的:
mov a,#00001111B
mov p1,a ;p1.0 p1.1 p1.2 p1.3是输入口
mov a,p1
xrl a,#0FH
jz ISK0 ;f*1输出
xrl a,#1FH
jz ISK1 ;f*2输出
xrl a,#2FH
jz ISK2 ;f*3输出
xrl a,#3FH
jz L3
L3: ljmp ISK3 ;f*4输出
xrl a,#4FH
........
P1口是4个开关(0n-off),检测开关的不同状态的!请问用哪条指令将位锁存器置1? 答 1: 请大家帮忙!我初学单片机,请问用哪条指令将位锁存器置1,我这个程序用将位锁存器置1吗?
我的硬件图:
http://www.21icsearch.com/buzi/upimage/upfile/20054161653490.jpg
答 2: 高4位被封锁程序好象是在无键压下时,根据P1口的高8位进行分支...
将:
mov a,#00001111B
mov p1,a ;p1.0 p1.1 p1.2 p1.3是输入口
改为:
mov p1,#0ffh ;测试高4位XXX,低4位测试键盘
答 3: 谢谢 hotpower,我去试试 答 4: 还是不行,我的程序是根据输入方波频率,输出是1-16倍频!;;p2.0 is output port;p3.2 is wave input;p1.0,p1.1,p1.2,p1.3 are input key.
;;input wave is below 2kHz.
CounterH EQU 030H
CounterL EQU 031H
TimerH equ 032h
TimerL equ 033h
Counter1H equ 034H
Counter1L equ 035H
Timer1H equ 036H
Timer1L equ 037H
Timer2H equ 038H
Timer2L equ 039H
ORG 0000H
LJMP START
org 0400H
START:
mov sp,#60h
mov a,#11111110B
mov p2,a ;p2.0 是输出口
mov a,#00001111B
mov p1,a ;p1.0 p1.1 p1.2 p1.3是输入口
mov a,0
mov CounterH,a
mov CounterL,a
mov TimerH,a
mov TimerL,a
mov TMOD,#019H ;设置工作方式寄存器
mov TL0,#00H
mov TH0,#00H
;;;;测P3.2口方波低电平宽度
jb p3.2, $ ; 等待/INT0变低
setb TR0 ; 启动定时
jnb p3.2, $ ; 一旦/INT0变高,启动定时
jb p3.2, $ ;等待/INT0再变低
clr TR0
mov a,TL0
mov CounterL,a
mov a,TH0
mov CounterH,a
;;;;周期/50 即为:频率*50
sub1:
clr c
mov a,CounterL
subb a,#50d
jnc getTimer
mov a,CounterH
jz readKey
dec CounterH
clr c
mov a,#0ffh
subb a,#50d
setb c
addc a,CounterL
getTimer:
mov CounterL,a
inc TimerL
mov a,TimerL
jnz sub1
inc TimerH
jnz sub1
;;;;read key读开关状态,1ms查询开关状态一次
readKey:
mov TL1,#0FCH ;定时器1赋初值
mov TH1,#18H
setb TR1 ;启动定时器
DLY:
jbc TF0,REP ;查询计数溢出
ajmp DLY
REP:
mov TL1,#0FCH ;定时器1赋初值
mov TH1,#18H
mov a,TimerL
mov Counter1L,a
mov a,TimerH
mov Counter1H,a
mov a,p1
xrl a,#0FH
jz ISK0 ;f*1输出
xrl a,#1FH
jz ISK1 ;f*2输出
xrl a,#2FH
jz ISK2 ;f*3输出
xrl a,#3FH
jz L3
L3: ljmp ISK3 ;f*4输出
xrl a,#4FH
jz L4
L4: ljmp ISK4 ;f*5输出
xrl a,#5FH
jz L5
L5: ljmp ISK5 ;f*6输出
xrl a,#6FH
jz L6
L6: ljmp ISK6 ;f*7输出
xrl a,#7FH
jz L7
L7: ljmp ISK7 ;f*8输出
xrl a,#8FH
jz L8
L8: ljmp ISK8 ;f*9输出
xrl a,#9FH
jz L9
L9: ljmp ISK9 ;f*10输出
xrl a,#0AFH
jz L10
L10: ljmp ISK10 ;f*11输出
xrl a,#0BFH
jz L11
L11: ljmp ISK11 ;f*12输出
xrl a,#0CFH
jz L12
L12: ljmp ISK12 ;f*13输出
xrl a,#0DFH
jz L13
L13: ljmp ISK13 ;f*14输出
xrl a,#0EFH
jz L14
L14: ljmp ISK14 ;f*15输出
xrl a,#0FFH
jz L15
L15: ljmp ISK15 ;f*16输出
ajmp DLY
ISK0:
mov Timer1L,Counter1L
mov Timer1H,Counter1H
ljmp outputWave
ISK1:
clr c
mov a,Counter1H
rrc a
mov Timer1H,a
mov a,Counter1L
rrc a
mov Timer1L,a
ljmp outputWave
ISK2:
clr c
mov a,Counter1L
subb a,#3d
jnc getTimer2
mov a,Counter1H
jz I2
I2: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#3d
setb c
addc a,Counter1L
getTimer2:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK2
inc Timer1H
jnz ISK2
ISK3:
clr c
mov a,Counter1L
subb a,#4d
jnc getTimer3
mov a,Counter1H
jz I3
I3: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#4d
setb c
addc a,Counter1L
getTimer3:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK3
inc Timer1H
jnz ISK3
ISK4:
clr c
mov a,Counter1L
subb a,#5
jnc getTimer4
mov a,Counter1H
jz I4
I4: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#5
setb c
addc a,Counter1L
getTimer4:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK4
inc Timer1H
jnz ISK4
ISK5:
clr c
mov a,Counter1L
subb a,#6d
jnc getTimer5
mov a,Counter1H
jz I5
I5: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#6d
setb c
addc a,Counter1L
getTimer5:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK5
inc Timer1H
jnz ISK5
ISK6:
clr c
mov a,Counter1L
subb a,#7d
jnc getTimer6
mov a,Counter1H
jz I6
I6: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#7d
setb c
addc a,Counter1L
getTimer6:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK6
inc Timer1H
jnz ISK6
ISK7:
clr c
mov a,Counter1L
subb a,#8d
jnc getTimer7
mov a,Counter1H
jz I7
I7: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#8d
setb c
addc a,Counter1L
getTimer7:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK7
inc Timer1H
jnz ISK7
ISK8:
clr c
mov a,Counter1L
subb a,#9d
jnc getTimer8
mov a,Counter1H
jz I8
I8: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#9d
setb c
addc a,Counter1L
getTimer8:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK8
inc Timer1H
jnz ISK8
ISK9:
clr c
mov a,Counter1L
subb a,#10d
jnc getTimer9
mov a,Counter1H
jz I9
I9: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#10d
setb c
addc a,Counter1L
getTimer9:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK9
inc Timer1H
jnz ISK9
ISK10:
clr c
mov a,Counter1L
subb a,#11d
jnc getTimer10
mov a,Counter1H
jz I10
I10: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#11d
setb c
addc a,Counter1L
getTimer10:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK10
inc Timer1H
jnz ISK10
ISK11:
clr c
mov a,Counter1L
subb a,#12d
jnc getTimer11
mov a,Counter1H
jz I11
I11: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#12d
setb c
addc a,Counter1L
getTimer11:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK11
inc Timer1H
jnz ISK11
ISK12:
clr c
mov a,Counter1L
subb a,#13d
jnc getTimer12
mov a,Counter1H
jz I12
I12: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#13d
setb c
addc a,Counter1L
getTimer12:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK12
inc Timer1H
jnz ISK12
ISK13:
clr c
mov a,Counter1L
subb a,#14d
jnc getTimer13
mov a,Counter1H
jz I13
I13: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#14d
setb c
addc a,Counter1L
getTimer13:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK13
inc Timer1H
jnz ISK13
ISK14:
clr c
mov a,Counter1L
subb a,#15d
jnc getTimer14
mov a,Counter1H
jz I14
I14: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#15d
setb c
addc a,Counter1L
getTimer14:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK14
inc Timer1H
jnz ISK14
ISK15:
clr c
mov a,Counter1L
subb a,#16d
jnc getTimer15
mov a,Counter1H
jz I15
I15: ljmp outputWave
dec Counter1H
clr c
mov a,#0ffh
subb a,#16d
setb c
addc a,Counter1L
getTimer15:
mov Counter1L,a
inc Timer1L
mov a,Timer1L
jnz ISK15
inc Timer1H
jnz ISK15
outputWave:
c1: cpl p2.0
mov Timer1L,Timer2L
mov Timer1H,Timer2H
c2: djnz Timer2L,c2
mov Timer2L,0FFH
djnz Timer2H,C2
ajmp C1
end
看看哪里有问题?
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
与电子爱好者谈读图四被打赏50分 | |
与电子爱好者谈读图二被打赏50分 | |
【FRDM-MCXN947评测】Core1适配运行FreeRtos被打赏50分 | |
【FRDM-MCXN947评测】双核调试被打赏50分 | |
【CPKCORRA8D1B评测】---移植CoreMark被打赏50分 | |
【CPKCORRA8D1B评测】---打开硬件定时器被打赏50分 | |
【FRDM-MCXA156评测】4、CAN loopback模式测试被打赏50分 | |
【CPKcorRA8D1评测】--搭建初始环境被打赏50分 | |
【FRDM-MCXA156评测】3、使用FlexIO模拟UART被打赏50分 | |
【FRDM-MCXA156评测】2、rt-thread MCXA156 BSP制作被打赏50分 |