Microcontroller Simulator Task 6 - Electronics Tutorials |
|
Open a new tab or window running the simulator. Click on SWITCHES (B) and HBRIDGE (B) to make the switches and the motor visible. Both are connected to PORTB. If necessary, move the switches and motor so they don't cover each other. Use your mouse to switch off all the switches 0 to 7. Just click on the switches. Copy and paste the example code into the code editing area. Press F8 to assemble the code and run the program. Turn on S4 only. The motor should run forwards. Turn off S4. The motor should freewheel. TASK:Add to this example.
; ===========================================
; H Bridge Motor Control
; ===========================================
MOVW 0XF0 ; 4 Inputs & Outputs
MOVWR TRISB ; Set PORTB direction
START:
MOVRW PORTB ; READ PORTB
ANDW 0X70 ; BIT MASK
SUBW 0X10 ; TEST S4 CLOSED
JPZ FORWARD ; Jump If Closed
JMP COAST ; Freewheel
; ===========================================
FORWARD:
MOVW 0X09 ; Close bits 0 and 3
MOVWR PORTB
JMP START
; ===========================================
COAST:
MOVW 0X0 ; Open all switches
MOVWR PORTB
JMP START
; ===========================================
|