PORTx, TRISx, MOVW, MOVWR

Simulator LEDsOpen a browser window or tab containing the microcontroller simulator.

Copy and paste this program into the code editing area. Press F8 to assemble the code.

Click the LEDs button on the highlighted "B" to connect the LEDs to PORTB.
If necessary, drag the LEDs to a more visible position.

Step the program and watch the LEDs. Answer the reviseOmatic questions on this task.

This program should also run unaltered on the PICAXE 28X1 chip
but so fast that the LEDs will appear to be continuously lit.
You will need to add time delays to see the LEDs flashing.
Remember to use resistors to limit the current to each LED.


  • The microcontroller has three eight bit I/O ports called PORTA, PORTB and PORTC.
  • The microcontroller has three data direction registers called TRISA, TRISB and TRISC.
     
  • TRISA/B/C is a register controlling the tristate logic for PORTA/B/C.
  • If TRISB bits are set to zero, the corresponding PORTB bits are outputs.
  • If TRISB bits are set to one, the corresponding PORTB bits are inputs.
     
  • MOVW is a command used to move a number into the Working Register (W)
  • MOVWR TRISB is a command used to copy a number from (W) into the named register (TRISB)
  • MOVWR 0x55 copies from (W) into the register with address 55.
  • MOVWR PORTB is a command used to copy a number from (W) into the named register (PORTB)
  • 0x55 is a hexadecimal number.

TASK: Alter the program to repeatedly flash each LED in turn going from right to left.

; ===== CONNECT LEDs TO PORTB =====
        MOVW    0x00
        MOVWR   TRISB
START: 
        MOVW    0x55
        MOVWR   PORTB
   
        MOVW    0xAA
        MOVWR   PORTB
 
        JMP     START