Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that bounces the LED lights back and forth as follows: P1.7 to P

ID: 3568715 • Letter: W

Question

Write a program that bounces the LED lights back and forth as follows: P1.7 to P1.0 to P1.6 to P1.1 to

P1.5 to P1.2 to P1.4 to P1.3 to P1.3 to P1.4 to P1.2 to P1.5 to P1.1 to P1.6 to P1.0 to P1.7 & start over

again.

Use the RR and RL instructions to program the bouncing lights. As the light bounces, a user can

sound a bell for 100 msec by pressing a button . The timing should be as close

as possible. Moreover, use a different timing delay (your choice) for the LED lights. Use the

hardware interrupt to turn on the bell and a timer interrupt to turn off the bell.

Explanation / Answer

LIST p=16F628 ;tell assembler what chip we are using include "P16F628.inc" ;include the defaults for the chip __config 0x3D18 ;sets the configuration settings (oscillator type etc.) cblock 0x20 ;start of general purpose registers count1 ;used in delay routine counta ;used in delay routine countb ;used in delay routine endc LEDPORT Equ PORTB ;set constant LEDPORT = 'PORTB' LEDTRIS Equ TRISB ;set constant for TRIS register org 0x0000 ;org sets the origin, 0x0000 for the 16F628, ;this is where the program starts running movlw 0x07 movwf CMCON ;turn comparators off (make it like a 16F84) bsf STATUS, RP0 ;select bank 1 movlw b'00000000' ;set PortB all outputs movwf LEDTRIS bcf STATUS, RP0 ;select bank 0 clrf LEDPORT ;set all outputs low Loop movlw b'10000000' movwf LEDPORT call Delay ;this waits for a while! movlw b'01000000' movwf LEDPORT call Delay ;this waits for a while! movlw b'00100000' movwf LEDPORT call Delay ;this waits for a while! movlw b'00010000' movwf LEDPORT call Delay ;this waits for a while! movlw b'00001000' movwf LEDPORT call Delay ;this waits for a while! movlw b'00000100' movwf LEDPORT call Delay ;this waits for a while! movlw b'00000010' movwf LEDPORT call Delay ;this waits for a while! movlw b'00000001' movwf LEDPORT call Delay ;this waits for a while! movlw b'00000010' movwf LEDPORT call Delay ;this waits for a while! movlw b'00000100' movwf LEDPORT call Delay ;this waits for a while! movlw b'00001000' movwf LEDPORT call Delay ;this waits for a while! movlw b'00010000' movwf LEDPORT call Delay ;this waits for a while! movlw b'00100000' movwf LEDPORT call Delay ;this waits for a while! movlw b'01000000' movwf LEDPORT call Delay ;this waits for a while! goto Loop ;go back and do it again Delay movlw d'250' ;delay 250 ms (4 MHz clock) movwf count1 d1 movlw 0xC7 movwf counta movlw 0x01 movwf countb Delay_0 decfsz counta, f goto $+2 decfsz countb, f goto Delay_0 decfsz count1 ,f goto d1 retlw 0x00 end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote