如何在按下按钮3次后创建一个程序点亮LED 30秒? [英] How do I create a program t light an LED for 30 seconds after a button has been pressed 3 times?

查看:84
本文介绍了如何在按下按钮3次后创建一个程序点亮LED 30秒?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的代码,我有很多研究,但我没有得到它!我把那些看起来模糊相似的东西组合在一起,但它们不会在一起!



; ********* ************************************************** ***************************************** 
;定义
; ******************************************** ************************************************** ******

列表P = PIC16F84A,R = D;定义PIC类型和基数
;(H =十六进制,D =十进制)。十六进制数字必须为
;形式为0xAA或0AAh
包括P16F84A.INC4; P16F84A.INC是包含
的文件; PIC寄存器的定义

; ******寄存器使用******

;对于PIC16C84,用户RAM从0Ch开始。以下定义
;(名称是任意的)将在许多程序中发挥作用。

count equ 0Ch;计数器寄存器
flag equ 0Dh; Counter Flag
msloop equ 0Eh;微秒延迟循环寄存器
tenloop equ 0Fh;十分之一秒延迟循环寄存器
secloop equ 10h;一秒延迟循环寄存器


; ************************ ************************************************** **************************
;矢量
; ******************************************** ************************************************** ******

; PIC16C84向量位于存储器底部(0000h-0007h)

org 0000h; PIC16C84的复位向量位于0000h
转到开始;转到主程序启动
org 0004h; PIC16C84的中断向量为0004h
转到inter;转到中断服务程序的开始
org 0008h;第一个位置可用于程序

; ****************************************** ************************************************** ********
; SUBROUTINES
; ******************************************** ************************************************** ******

;按照惯例,子程序放在向量之后,使得
;位于内存的底部。这避免了
的小型程序的内存库切换。


;给出1微秒延迟

onems movlw 248;将数字248移动到工作寄存器
movwf msloop;将数字从工作寄存器移到msloop
loop1 nop;用于填充
decfsz msloop,1;将msloop减少1,如果为零则跳过下一条指令
goto loop1;继续循环直到msloop达到零
nop;用于填充
返回

;给出0.1秒延迟

第十个movlw 100;将数字100移动到工作寄存器
movwf tenloop;移动数字从工作寄存器到tenloop
loop2调用onems;调用1微秒延迟子程序
decfsz tenloop,1;将tenloop减1,如果为零则跳过下一条指令
goto loop2;继续调用微秒延迟直到tenloop达到零
返回

;给出1秒延迟

sec movlw 10;将数字10移动到工作寄存器
movwf secloop; Moves从工作注册到tenloop的数字
loop3 call tenth;调用十分之一秒延迟子程序
decfsz secloop,1;将secloop减少1,如果为零则跳过下一条指令
转到loop3;继续调用0.1秒延迟直到secloop到达零
返回

;预设闪烁输出序列

outseq bsf PORTB,1;设置输出端口的第1位
call sec;调用一个第二个延迟子程序
bcf PORTB,1;清除输出端口的第1位
调用秒;调用一秒延迟子程序
转到outseq;继续闪存输出位1直到中断
返回


; ************************************ ************************************************** **************
;主程序
; ******************************************* ************************************************** *******

; ****** INITIALISATION ******

;在使用I / O端口之前,数据方向寄存器必须设置
; up。状态寄存器中的位RP0选择正常寄存器
;设置为0时,或者设置为1时的特殊寄存器。数据方向
;将TRISA和TRISB寄存在特殊寄存器组中。
中的'1';这些寄存器将相应的端口线设置为Input,并将
设置为'0',使相应的线成为输出。

start bsf STATUS,RP0;选择特殊寄存器设置

movlw b'11111';将PORTA上的每个引脚设置为输入
movwf TRISA
movlw b'00000000';将PORTA上的每个引脚设置为输出
movwf TRISB

bcf状态,RP0;选择正常寄存器设置


; ****** MAIN PROGRAM ******

;复位计数和标志寄存器和清除输出
clrf count;清除计数寄存器中的值
movlw b'00000000';将二进制值00000000复制到工作寄存器
movwf PORTB;将值从工作寄存器复制到输出端口
clrf标志;清除标志寄存器

;用标志计数
等待btfsc PORTA,0;测试输入端口的第0位跳过下一条指令,如果为零,则
转到;如果位0,则程序转到标签向上
bcf标志,0;清除第0位标志寄存器
转到等待
up btfsc flag,0
goto wait
bsf flag,0;设置标志寄存器的第0位
incf count ,1;计数值增加1

; EXOR计数寄存器100
movlw 100;将数字100移动到工作寄存器
xorwf count,0; EXOR计数数字在工作寄存器中
btfss STATUS,Z;检查状态位Z以查看工作寄存器中的所有位是否都设置为
goto wait
bsf PORTB,0;如果是EXOR,则设置输出端口的位0成功

; EXOR计数寄存器200
movlw 200;将数字200移动到工作寄存器
xorwf count,0; EXOR计数工作寄存器中的数字
btfss STATUS,Z;检查状态位Z以查看工作寄存器中的所有位是否都设置为
转到等待
调用outseq;调用输出序列

你能做些什么来帮助我?谢谢

解决方案

你不要用看似模糊的相似的东西进行编码,因为他们他们不会在一起



相反,你应该知道事情,学习东西,并尝试自己做事。



从中抓取随机的代码互联网,将它们放在一起并希望它们能够协同工作在开发任何形式时都不是一个成功的策略,绝对不是在处理汇编代码时。



现在回到开头,尝试从第一原理开始研究如何做到这一点 - 我个人首先按常规顺序打开和关闭LED,然后每次按下按钮时切换它。

最后我会处理多次按下。


也许你的方法是错误的。开始使用新设备的最佳方法是找到一些可用的代码并尝试了解它是如何工作的。然后进行小的修改,确保代码继续工作。这就是我们所有人都这样做的经验,即使是经验丰富的人。



试试例如:



http://www.talkingelectronics.com/projects/PIC_LAB-1/PicLab1_experiments-P2.html [ ^ ]



或:



http://www.micro-examples.com/public/microex-navig/doc/100-led-blinking.html [ ^ ]



和:



http://www.talkingelectronics.com/projects/Elektor/Gooligum%20PIC%20Tutorials /PIC_Base_A_2.pdf [ ^ ]

Below is my code, I have lots of research but I don't get it! I have cobined things that look vaguely similar but they won't go together!

;****************************************************************************************************
;					DEFINITIONS						     
;****************************************************************************************************
 
		list    P=PIC16F84A, R=D	;Define PIC type and radix
				;(H=Hex, D=Decimal). Hex numbers must
				;be of the form 0xAA or 0AAh
		include "P16F84A.INC"4	;P16F84A.INC is a file containing
				;definitions of PIC registers
 
;****** REGISTER USAGE ******
 
;For PIC16C84, user RAM starts at 0Ch. The following definitions
;(the names are arbitrary) will be found useful in many programs.
 
count   equ	0Ch		;Counter register
flag    equ    	0Dh		;Counter Flag
msloop	equ    	0Eh		;Microsecond delay loop register
tenloop	equ	0Fh		;Tenth of second delay loop register
secloop	equ	10h		;One Second delay loop register
 
 
;****************************************************************************************************
;					VECTORS							     
;****************************************************************************************************
 
;The PIC16C84 vectors live at the bottom of memory (0000h-0007h)
 
		org	0000h		;Reset vector for PIC16C84 is at 0000h
        	goto    start		;Go to main program start
		org	0004h		;Interrupt vector for PIC16C84 is at 0004h
		goto	inter		;Go to start of interrupt service routine
		org	0008h		;first location available to programs
 
;****************************************************************************************************
;					SUBROUTINES 						     
;****************************************************************************************************
 
;By convention, subroutines are placed after the vectors so that they
;are at the bottom of memory. This avoids memory bank-switching for
;small programs.
 
 
;Gives a 1 microsecond delay

onems	movlw	248		;Moves number 248 into the working register
	movwf	msloop		;Moves number from working register to msloop
loop1	nop			;Used for padding
	decfsz 	msloop,1	;Decrements msloop by 1, skips next instruction if zero
	goto    loop1		;Continues to loop until msloop reaches zero
	nop			;Used for padding
	return
 
;Gives a 0.1 Second Delay

tenth   movlw	100		;Moves number 100 into the working register
	movwf	tenloop		;Moves number from working register to tenloop
loop2	call	onems		;Calls the 1 microsecond delay subroutine
	decfsz	tenloop,1	;Decrements tenloop by 1, skips next instruction if zero
	goto	loop2		;Continues to call microsecond delay until tenloop reaches zero
	return
 
;Gives a 1 Second Delay

sec	movlw	10		;Moves number 10 into the working register
	movwf	secloop		;Moves number from working register to tenloop
loop3	call	tenth		;Calls the tenth of a second delay subroutine
	decfsz	secloop,1	;Decrements secloop by 1, skips next instruction if zero
	goto	loop3		;Continues to call 0.1 second delay until secloop reaches zero
	return

;Preset Flashing Output Sequence

outseq	bsf	PORTB,1		;Sets bit 1 of output port
	call	sec		;Calls the one second delay subroutine
	bcf	PORTB,1		;Clears bit 1 of output port
	call	sec		;Calls the one second delay subroutine
	goto	outseq		;Continues to flash output bit 1 until interrupted
	return
 
 
;****************************************************************************************************
;					MAIN PROGRAM						     
;****************************************************************************************************
 
;****** INITIALISATION ******
 
;Before using the I/O ports, the data direction registers must be set
;up. Bit RP0 in the status register selects either the normal register
;set when 0, or the special register set when 1. The data direction
;registers TRISA and TRISB live in the special register set. A '1' in
;these registers sets the corresponding port line to an Input, and a
;'0' makes the corresponding line an output.
 
start	bsf	STATUS,RP0		;Select special register set
 
		movlw	b'11111'	;Set every pin on PORTA to be an Input
		movwf	TRISA
		movlw	b'00000000'	;Set every pin on PORTA to be an Ouput
		movwf	TRISB
 
		bcf		STATUS,RP0	;Select normal register set
 

;****** MAIN PROGRAM ******
 
;Reset Count and Flag Registers and Clear Outputs
		clrf	count		;Clears value in count register
		movlw	b'00000000'	;Copies binary value 00000000 into working register
 		movwf	PORTB		;Copies value from working register to Output Port 
		clrf	flag		;Clear flag register

;Counting with a flag
wait	btfsc	PORTA,0			;Tests bit 0 of Input Port skips next instruction if zero 
		goto	up		;If bit 0 on then program goes to label up
		bcf	flag,0		;Clears bit 0 of the flag register
		goto	wait		
up		btfsc	flag,0		
		goto 	wait
		bsf	flag,0		;Sets bit 0 of the flag register
		incf	count,1		;Increments value in count by 1
	
;EXOR count register with 100
		movlw	100		;Moves number 100 into working register
		xorwf	count,0		;EXORs count with the number in the working register
		btfss 	STATUS,Z	;Checks Status Bit Z to see if all bits in working register are set
		goto	wait
		bsf	PORTB,0		;Sets bit 0 of Output Port if EXOR is successful

;EXOR count register with 200	
		movlw	200		;Moves number 200 into working register
		xorwf	count,0		;EXORs count with the number in the working register
		btfss 	STATUS,Z	;Checks Status Bit Z to see if all bits in working register are set		
		goto	wait
		call	outseq		;Calls ouput sequence 

What can you do to help me? Thanks

解决方案

You don't code by "cobined things that look vaguely similar" because they "they won't go together"

Instead you are expected to know things, and learn things, and try to actually do things yourself.

Grabbing random bits of code from the internet, throwing them together and hoping they will work together is not a successful tactic when it comes to development of any form, and definitely not when dealing with assembly code.

Now go back to the beginning, and try to work out how to do it from first principles - personally I would start by turning the LED on and of in a regular sequence, then switching it each time the button way pressed when that worked.
Then finally I'd handle the multiple presses.


Perhaps your approach is wrong. The best way to start with a new device is to find some working code and try to understand how it does things. Then make small modifications ensuring that the code continues to work. This is how we all do it even experienced guys.

Try for example:

http://www.talkingelectronics.com/projects/PIC_LAB-1/PicLab1_experiments-P2.html[^]

or:

http://www.micro-examples.com/public/microex-navig/doc/100-led-blinking.html[^]

and:

http://www.talkingelectronics.com/projects/Elektor/Gooligum%20PIC%20Tutorials/PIC_Base_A_2.pdf[^]


这篇关于如何在按下按钮3次后创建一个程序点亮LED 30秒?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆