his is the starter code I used, and I need to implement these changes. How can I do so? This is the mplabx v.5.35 ;Blink LED with Loop Timer Delay ASM ; PIC16F1829 Configuration Bit Settings ; Assembly source line config statements #include "p16f1829.inc" ; CONFIG1 ; __config 0xC9E4  __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF ; CONFIG2 ; __config 0xFEFF  __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_ON  list p =16F1829, R=DEC     CBLOCK 0x30     VarA     VarB     Loop  DLAY  LOOPcount         ENDC         ORG 0     goto Start         ORG 4     RETFIE     call Delay      Start  BANKSEL OSCCON  movlw 0x6A  movwf OSCCON    BANKSEL TRISA  clrf TRISA  BANKSEL LATA  clrf LATA      goto Loop       BANKSEL LATA     BCF LATA,5     call Delay     goto Loop     Delay     call Delay     BANKSEL VarA     movlw 0xFF     movwf VarA  Outside     decfsz VarA     goto Goon     return  Goon     decfsz VarB     goto Inside     goto Outside      Inside     decfsz VarB     goto Inside     goto Outside END

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Topic Video
Question

This is the starter code I used, and I need to implement these changes. How can I do so? This is the mplabx v.5.35

;Blink LED with Loop Timer Delay ASM

; PIC16F1829 Configuration Bit Settings

; Assembly source line config statements


#include "p16f1829.inc"

; CONFIG1
; __config 0xC9E4
 __CONFIG _CONFIG1, _FOSC_INTOSC & _WDTE_OFF & _PWRTE_OFF & _MCLRE_ON & _CP_OFF & _CPD_OFF & _BOREN_OFF & _CLKOUTEN_OFF & _IESO_OFF & _FCMEN_OFF
; CONFIG2
; __config 0xFEFF
 __CONFIG _CONFIG2, _WRT_OFF & _PLLEN_OFF & _STVREN_ON & _BORV_LO & _LVP_ON


 list p =16F1829, R=DEC
    CBLOCK 0x30
    VarA
    VarB
    Loop

 DLAY
 LOOPcount
 

 
    ENDC
   
    ORG 0
    goto Start
   
    ORG 4
    RETFIE
    call Delay
   
 Start
 BANKSEL OSCCON
 movlw 0x6A
 movwf OSCCON
 
 BANKSEL TRISA
 clrf TRISA
 BANKSEL LATA
 clrf LATA
 
 
 goto Loop
 
    BANKSEL LATA
    BCF LATA,5
    call Delay
    goto Loop
 
  Delay
    call Delay
    BANKSEL VarA
    movlw 0xFF
    movwf VarA
 Outside
    decfsz VarA
    goto Goon
    return
 Goon
    decfsz VarB
    goto Inside
    goto Outside
   
 Inside
    decfsz VarB
    goto Inside
    goto Outside
END

1. BANSEL TRISB
2. bsf TRISB, 7
STEP 1: Push Button Declaration
Set the pin RB7 to be an input, don't be confused with the LED on RA5 which is a totally different port
and is configured in TRISA as an output. Since the push button is connected to RB7 on your PIC. To
configure RB7 to an input do the following.
1. BANKSEL ANSELC
2.
bcf ANSELC, 2
IN M&in 6700
STEP 2: Turn off Analog Input
Whenever you want to use a pin as a digital input you must make sure it's analog select bit is cleared in
the related ANSELx register. We need to add the following code or the button will not work correctly:
Note: You only have to do this when in input mode. Also, it is true that a few of the pins do not have
analog functions (RB7 is one) and thus no associated ANSEL bit so in those few cases, can skip this step.
1. BANKSEL OPTION_REG
2. MOVLW 0X87;1000 0111
3. MOVWF OPTION_REG
2.
STEP 3: Timer 0 Options Reg
1. Delay2
9.
10.
11.
STEP 4: Timer O
Here is the code for the timer O delay. It is similar to the variable delay we made before in lab 1. The
main difference is that we are using a dedicated timer here instead of variables. Place this at the
bottom of your code before END.
3.
4.
5.
6.
7.
8. Tloop
BANKSEL INTCON
BCF INTCON, 2 ;make sure flag is cleared at start
BANKSEL TMR0
MOVLW 0x01
MOVWF TMRO
BANKSEL INTCON
BTFSC INTCON, 2 ;wait till timer overflows
RETURN
GOTO Tloop
Transcribed Image Text:1. BANSEL TRISB 2. bsf TRISB, 7 STEP 1: Push Button Declaration Set the pin RB7 to be an input, don't be confused with the LED on RA5 which is a totally different port and is configured in TRISA as an output. Since the push button is connected to RB7 on your PIC. To configure RB7 to an input do the following. 1. BANKSEL ANSELC 2. bcf ANSELC, 2 IN M&in 6700 STEP 2: Turn off Analog Input Whenever you want to use a pin as a digital input you must make sure it's analog select bit is cleared in the related ANSELx register. We need to add the following code or the button will not work correctly: Note: You only have to do this when in input mode. Also, it is true that a few of the pins do not have analog functions (RB7 is one) and thus no associated ANSEL bit so in those few cases, can skip this step. 1. BANKSEL OPTION_REG 2. MOVLW 0X87;1000 0111 3. MOVWF OPTION_REG 2. STEP 3: Timer 0 Options Reg 1. Delay2 9. 10. 11. STEP 4: Timer O Here is the code for the timer O delay. It is similar to the variable delay we made before in lab 1. The main difference is that we are using a dedicated timer here instead of variables. Place this at the bottom of your code before END. 3. 4. 5. 6. 7. 8. Tloop BANKSEL INTCON BCF INTCON, 2 ;make sure flag is cleared at start BANKSEL TMR0 MOVLW 0x01 MOVWF TMRO BANKSEL INTCON BTFSC INTCON, 2 ;wait till timer overflows RETURN GOTO Tloop
Challenge Help: Button Test
Then you must insert code in your main blink loop to skip the loop when the button is pressed. You
could do this several different ways, but the one way would be to use the "btfss" instruction which
should skip the next instruction if the button is not pressed (it will be set when not pressed). Thus,
when not pressed it will skip the branch instruction which you add right after the btfss instruction. By
skipping the branch, the loop will work in the normal mode, but when the button is pressed, that results
in taking the branch back to the top of the loop, thus skipping part of the loop. If you put this at the top
of the loop before the bcf instruction, the LED will appear to be always off when you press the button
and if you put it in the middle of the loop, after the bcf but before the bsf instruction, the LED will
always appear on when you hold the button in. If you put it both places it will depend when you push
the button whether the LED is on or off continuously while you hold the button down. As suggested
above, you should follow the "btfss" instruction with a "bra" to your Loop Label. You could also use the
"btfsc" instruction, but then you will have to push the button to get the LED to blink. Here is an example
of the code:
1.
BANKSEL PORTB
2. btfss PORTB, 7
3. bra Loop Name; Where Loop_Name is the name of your loop(it was called 'Loop' in lab 1)
Challenge
1. Update Loop from Lab 1
a. Call Delay2 instead of Delay
i. Hint: replace Delay with Delay 2 in Loop
b. Add in Push Button check into loop
i. Hint: use BTFSS on RB7
ii. Hint: use BRA to Loop (Look at Challenge Help above)
c. Make sure the toggle code for RA5 (or which ever color you want) is still there after
the branch. Note: you can skip extra banksel if you use PORTX instead of LATX, why?
BRA
Syntax:
Operands:
Operation:
Status Affected:
Description:
Relative Branch
[label] BRA label
[label] BRA $+k
-256 ≤ label - PC + 1 ≤ 255
-256 ≤ k ≤ 255
(PC) + 1+k→ PC
None
Add the signed 9-bit literal 'k' to the
PC. Since the PC will have incre-
mented to fetch the next instruction,
the new address will be PC + 1 + k.
This instruction is a two-cycle instruc-
tion. This branch has a limited range.
BTFSS
Syntax:
Operands:
Operation:
Status Affected:
Description:
Bit Test f, Skip if Set
[label] BTFSS f,b
0sfs 127
0<b<7
skip if (f<b>) = 1
None
If bit 'b' in register 'f is '0', the next
instruction is executed.
If bit 'b' is '1', then the next
instruction is discarded and a NOP is
executed instead, making this a
2-cycle instruction.
If successful, the Hello World LED will blink until you press the button, once you let go it will start to
blink again. When pressed the button skips the toggle loop written in Lab 1. Note: it turns out that
this will work also even if you forget to change the jumper, because pushing the MasterClr button
holds the cpu in reset/halt mode, so no blinking would occur. But, it's a false solution, see if you
Transcribed Image Text:Challenge Help: Button Test Then you must insert code in your main blink loop to skip the loop when the button is pressed. You could do this several different ways, but the one way would be to use the "btfss" instruction which should skip the next instruction if the button is not pressed (it will be set when not pressed). Thus, when not pressed it will skip the branch instruction which you add right after the btfss instruction. By skipping the branch, the loop will work in the normal mode, but when the button is pressed, that results in taking the branch back to the top of the loop, thus skipping part of the loop. If you put this at the top of the loop before the bcf instruction, the LED will appear to be always off when you press the button and if you put it in the middle of the loop, after the bcf but before the bsf instruction, the LED will always appear on when you hold the button in. If you put it both places it will depend when you push the button whether the LED is on or off continuously while you hold the button down. As suggested above, you should follow the "btfss" instruction with a "bra" to your Loop Label. You could also use the "btfsc" instruction, but then you will have to push the button to get the LED to blink. Here is an example of the code: 1. BANKSEL PORTB 2. btfss PORTB, 7 3. bra Loop Name; Where Loop_Name is the name of your loop(it was called 'Loop' in lab 1) Challenge 1. Update Loop from Lab 1 a. Call Delay2 instead of Delay i. Hint: replace Delay with Delay 2 in Loop b. Add in Push Button check into loop i. Hint: use BTFSS on RB7 ii. Hint: use BRA to Loop (Look at Challenge Help above) c. Make sure the toggle code for RA5 (or which ever color you want) is still there after the branch. Note: you can skip extra banksel if you use PORTX instead of LATX, why? BRA Syntax: Operands: Operation: Status Affected: Description: Relative Branch [label] BRA label [label] BRA $+k -256 ≤ label - PC + 1 ≤ 255 -256 ≤ k ≤ 255 (PC) + 1+k→ PC None Add the signed 9-bit literal 'k' to the PC. Since the PC will have incre- mented to fetch the next instruction, the new address will be PC + 1 + k. This instruction is a two-cycle instruc- tion. This branch has a limited range. BTFSS Syntax: Operands: Operation: Status Affected: Description: Bit Test f, Skip if Set [label] BTFSS f,b 0sfs 127 0<b<7 skip if (f<b>) = 1 None If bit 'b' in register 'f is '0', the next instruction is executed. If bit 'b' is '1', then the next instruction is discarded and a NOP is executed instead, making this a 2-cycle instruction. If successful, the Hello World LED will blink until you press the button, once you let go it will start to blink again. When pressed the button skips the toggle loop written in Lab 1. Note: it turns out that this will work also even if you forget to change the jumper, because pushing the MasterClr button holds the cpu in reset/halt mode, so no blinking would occur. But, it's a false solution, see if you
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Instruction Format
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education