Exercise 1 Figure I below shows an HCS12 microcontroller connected to a pushbutt
ID: 3725225 • Letter: E
Question
Exercise 1 Figure I below shows an HCS12 microcontroller connected to a pushbutton switch (to Port A-bit 5) and to a 7-segment display (to Port B-bits from 6 to 0). Design an assembly program that increments the seven segment display every time the push button is pressed and then released. Assume that the initial value of the 7-segment is 0 and that the maximal value to be displayed is 9 5 VDC PB6 PB6 PAS PB4 PB2 PB1 PBO R= Figure 1 PIC18 You may need to use the Table below which shows the configuration of each segment of the 7- segment display for displaying number 0 to 9. Also assume that values 0x7E to 0x7B are stored in the PIC18's RAM memory at addressed 0x20 to Ox29. 030 058Explanation / Answer
Here push-button used to increment the count on the 7-segment display. The count value is stored in a file and this value is incremented by the program each time the push button is pressed. The count value is used to look-up a table to pick up the display-value for the 7-segment display.
First value in table is accessed when the PC - Program Counter has an addition of “0” because it naturally increments to the next location in memory. In the routines below, the number if items in the table are counted and used to determine “end of table.” The reason is the jump-value is incremented before it is compared.
Table
Delay
Del1
Main
Main1
Main2
ADDWF 02h,1
NOP
RETLW 06h
RETLW 5Bh
RETLW 4Fh
RETLW 66h
RETLW 6Dh
RETLW 7Dh
RETLW 07h
RETLW 7Fh
RETLW 6Fh
RETLW 3Fh
MOVLW 0A
MOVWF 1B
NOP
DECFSZ 1A,1
GOTO Del1
DECFSZ 1B,1
GOTO Del1
RETURN
Main CLRF 1E
BTFSS 05,0
GOTO Main2
CALL Delay
BTFSC 1F,0
GOTO Main1
INCF 1E,1
MOVLW 0B
XORWF 1E,0
BTFSC 03,2
GOTO Main
MOVF 1E,0
CALL Table
MOVWF 06
BSF 1F,0
GOTO Main1
CALL Delay
BCF 1F,0
GOTO Main1
END
;Project: Counting on 7-segment displayList P = 16F84
#include <p16.inc>
__CONFIG 1Bh ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC
SetUp
Table
Delay
Del1
Main
Main1
Main2
ORG 0BSF 03,5
CLRF 06
MOVLW 01
MOVWF 05
BCF 03,5
MOVLW 3Fh
MOVWF 06
CLRF 1E
CLRF 1F
GOTO Main
ADDWF 02h,1
NOP
RETLW 06h
RETLW 5Bh
RETLW 4Fh
RETLW 66h
RETLW 6Dh
RETLW 7Dh
RETLW 07h
RETLW 7Fh
RETLW 6Fh
RETLW 3Fh
MOVLW 0A
MOVWF 1B
NOP
DECFSZ 1A,1
GOTO Del1
DECFSZ 1B,1
GOTO Del1
RETURN
Main CLRF 1E
BTFSS 05,0
GOTO Main2
CALL Delay
BTFSC 1F,0
GOTO Main1
INCF 1E,1
MOVLW 0B
XORWF 1E,0
BTFSC 03,2
GOTO Main
MOVF 1E,0
CALL Table
MOVWF 06
BSF 1F,0
GOTO Main1
CALL Delay
BCF 1F,0
GOTO Main1
END
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.