Answer the question
In order to leave comments, you need to log in
How can I make the LED light up when a button is pressed?
I made a capacitive touch button based on the MSP430G2744. I learned how to register pressing, but there is no way to make the LED shine when pressed. I only managed to make it blink if I didn't disable the watchdog timer. It seems that it goes into reboot after reaching a certain time, and the LED flashes periodically. How can I make it so that when pressed, the LED is lit constantly, and not blinking? Assembly code is attached. Wrote in IAR.
#include "msp430.h" ; #define controlled include file
#define LED BIT0
#define CPS BIT1
NAME main ; module name
PUBLIC main ; make the main label vissible
; outside this module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG INTVEC ;вектор прерывания
ORG PORT1_VECTOR
DC16 inter
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP ; set up stack
main: NOP ; main program
;MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
JMP meas
inter: mov TAR, r7 ;обработчик прерывания
mov.b #0, P1IE ;сохраняем значение таймера
mov.b #0, P1IES
jmp comp
meas: mov #0, r7
bis.w #MC1, TACTL ;установка таймера, непрерывный счет
bis.w #TASSEL1, TACTL ;SMLCK
mov #0, TACCR0
bis.b #CPS, P1DIR ;устанавливаем пин кнопки на выход
bis.b #CPS, P1OUT
mov #1000, r11
charge: dec r11 ;ждем, пока емкость зарядится
tst r11
jz cont
jmp charge
cont: bis.b #CPS, P1IES ;устанавливаем прерывания по низкому уровню
bis.b #CPS, P1IE ;на пине кнопки
mov #0, TAR
mov.b #0, P1DIR ;устанавливаем пин кнопки на вход для разряда
bis.w #GIE, SR ;разрешаем прерывания
jmp $ ;ждем прерывания
comp: mov.b #0x15, r10 ;сравниваем значение из TAR с заранее измеренным
cmp.b r7, r10 ;значением разряда при касании, 15 я выбрал, так как
jl led ;оно больше значения при касании
jmp meas
led: mov.b #LED, P1DIR ;включаем светодиод
mov.b #LED, P1OUT
mov #65000, r6
jmp delay
delay: dec r6 ;задержка, чтобы увидеть свечение светодиода
tst r6
jz meas
jmp delay
END
Answer the question
In order to leave comments, you need to log in
I only managed to make it blink if I didn't disable the watchdog timer. It seems that it goes into reboot after reaching a certain time, and the LED flashes periodically. How can I make it so that when pressed, the LED is lit constantly, and not blinking?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question