In: Electrical Engineering
For the mspfr6989 write program #2
1(b) Write a program that will make LED1 blink 5 times when S1 is pressed, and then stop.
Program #2 – Using both S1 and S2 1 Write a program like 1(b) above, but the LED1 will blink until S2 is pressed. 2 Write a program that simulates a motor coming up to speed. When S1 is pressed, LED1 blinks at 50% duty cycle for 10 cycles (indicating a motor coming up to speed). After that time, LED2 comes on (indicating the motor is at speed), and can be turned off by pressing S2. 3 Create a flexible program for 2(b) that will reverse the operation of the LEDs if S2 is pressed first (LED2 shows ramp-up, and LED1 shows motor at full speed). Must use functions to control all timing, LED access, etc… Main program should just have loops and function calls.
;blink_led.asm
list P = 16F877A
include P16F877A.inc
STATUS EQU 0x03
PORTB EQU 0x06
TRISB EQU 0x86
PORTD EQU 0x08
TRISD EQU 0x88
CBLOCK 0x20
Kount120us ;Delay count (number of instr cycles for Delay)
Kount100us
Kount1ms
Kount10ms
Kount1s
Kount10s
Kount1m
ENDC
org 0x0000 ;line 1
goto START ;line 2 ($0000)
org 0x05
START
banksel TRISD
movlw 0x00
movwf TRISD
movwf TRISB
banksel PORTB
clrf PORTB
clrf PORTD
call Delay100ms
repeat movlw 0xFF
movwf PORTB
Call Delay1s
movlw 0x00
movwf PORTB
Call Delay1s
goto repeat
;==========================================================
;DELAY SUBROUTINES
Delay120us
banksel Kount120us
movlw H'C5' ;D'197'
movwf Kount120us
R120us
decfsz Kount120us
goto R120us
return
;
Delay100us
banksel Kount100us
movlw H'A4'
movwf Kount100us
R100us
decfsz Kount100us
goto R100us
return
;
;1ms Delay
Delay1ms
banksel Kount1ms
movlw 0x0A ;10
movwf Kount1ms
R1ms
call Delay100us
decfsz Kount1ms
goto R1ms
return
;
;10ms Delay
; call 100 times of 100 us Delay (with some time discrepancy)
Delay10ms
banksel Kount10ms
movlw H'64' ;100
movwf Kount10ms
R10ms
call Delay100us
decfsz Kount10ms
goto R10ms
return
;;
;1 sec Delay
;call 100 times of 10ms Delay
Delay1s
banksel Kount1s
movlw H'64'
movwf Kount1s
R1s
call Delay10ms
decfsz Kount1s
goto R1s
return
;;
;10 s Delay
;call 10 tiems of 1 s Delay
Delay10s
banksel Kount10s
movlw H'0A' ;10
movwf Kount10s
R10s
call Delay1s
decfsz Kount10s
goto R10s
return
;
;1 min Delay
;call 60 times of 1 sec Delay
Delay1m
banksel Kount1m
movlw H'3C' ;60
movwf Kount1m
R1m
call Delay1s
decfsz Kount1m
goto R1m
return
;;
;100 msec Delay
;call 10 times of 10ms Delay
Delay100ms
banksel Kount1s
movlw H'0A' ;10
movwf Kount1s
R100ms
call Delay10ms
decfsz Kount1s
goto R100ms
return
;;
;======================================================
END
;Increase delay at instw and dataw to 100ms and start up to 100ms
(2014-1-7)