How the CPU reads a button and lights an LED, one bit at a time. Cómo la CPU lee un botón y enciende un LED, bit a bit.
Santi Scagliusi, PhD
The same instruction that writes RAM writes a port. The address decides.La misma instrucción que escribe RAM escribe un puerto. La dirección decide.
Writing a 1 into address 0x0202 puts a voltage on physical pin P1.0. Escribir un 1 en la dirección 0x0202 pone tensión en el pin físico P1.0.
PxDIR steers the pin in or out. The others drive it or read it.PxDIR decide si el pin es entrada o salida. Los demás lo accionan o lo leen.
P1 to P10 are 8-bit. Pairs combine into 16-bit word ports PA to PE.P1 a P10 son de 8 bits. Las parejas forman puertos de 16 bits PA a PE.
Only P1, P2, P3, P4 have edge-interrupt logic. P5 to P10 and PJ do not. Solo P1, P2, P3, P4 tienen lógica de interrupción por flanco. P5 a P10 y PJ no.
EXP430FR6989: two LEDs, two buttons, fixed pins.EXP430FR6989: dos LEDs, dos botones, pines fijos.
LEDs are active-high. A pressed button ties the pin to ground, so it reads 0: active-low. Los LEDs son activos a nivel alto. Un botón pulsado lleva el pin a masa, así que lee 0: lógica negativa.
Direction first, then drive the level. P1.0 = LED1.Primero la dirección, luego el nivel. P1.0 = LED1.
Same start byte, same mask #BIT2|BIT0. Only the named bits change.Mismo byte inicial, misma máscara #BIT2|BIT0. Solo cambian los bits nombrados.
The .B suffix keeps it byte-wide. Bits 7-3, never named, stay exactly as they were. El sufijo .B lo mantiene en un byte. Los bits 7-3, nunca nombrados, quedan igual.
Configure P1.0 as output, then flip it with XOR.Configura P1.0 como salida y la invierte con XOR.
No loop, no delay: step it and watch P1OUT bit 0 flip each XOR. Sin bucle ni retardo: avanza paso a paso y mira cómo el bit 0 de P1OUT cambia en cada XOR.
Pull-up to Vcc, button to ground. Pressed wins and pulls the pin to 0.Pull-up a Vcc, botón a masa. Pulsado gana y lleva el pin a 0.
PxIN is read-only. Test for zero, not for one.PxIN es solo lectura. Comprueba el cero, no el uno.
A button to ground needs three writes before it reads cleanly.Un botón a masa necesita tres escrituras para leerse bien.
One press, several edges in the first milliseconds.Una pulsación, varios flancos en los primeros milisegundos.
An edge sets the flag. If the gates are open, the CPU jumps to the ISR.Un flanco pone la bandera. Si las puertas están abiertas, la CPU salta a la ISR.
Same dispatch as Module 7. Here the source is a pin edge on P1 to P4. Mismo despacho que el Módulo 7. Aquí la fuente es un flanco en un pin de P1 a P4.
One vector serves all eight pins of the port. PxIV decodes the highest priority.Un vector sirve a los ocho pines del puerto. PxIV decodifica el de mayor prioridad.
The CPU sleeps. Each press wakes it and toggles the LED.La CPU duerme. Cada pulsación la despierta y conmuta el LED.
Click "LaunchPad" in the I/O panel first: P1.0 = LED1, P1.1 = S1, P1.2 = S2.Pulsa "LaunchPad" en el panel de E/S primero: P1.0 = LED1, P1.1 = S1, P1.2 = S2.
Step it: P1OUT bit 0 flips on each XOR.Avanza paso a paso: el bit 0 de P1OUT cambia en cada XOR.
Run, then press and hold S1 to light the LED.Ejecuta y mantén pulsado S1 para encender el LED.
Masks drive several bits of the port at once.Las máscaras manejan varios bits del puerto a la vez.
Digital I/O is just reads and writes to memory-mapped bits.La E/S digital son solo lecturas y escrituras de bits mapeados en memoria.
Set PxDIR first. Write PxOUT, read PxIN. Reset leaves every pin an input.Pon PxDIR primero. Escribe PxOUT, lee PxIN. Tras reset todo pin es entrada.
A byte mask and the .B suffix change one pin and leave the rest of the port intact.Una máscara de byte y el sufijo .B cambian un pin y dejan el resto del puerto intacto.
Pull-up holds high, pressed reads 0. P1 to P4 can interrupt on the edge.El pull-up mantiene alto, pulsado lee 0. P1 a P4 interrumpen en el flanco.