Counting on the 7-segment display




This experiment uses the push-button 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.
Additional experiments on the website include a count-down routine, a 00 to 99 counter using a single display and others.
The Table: The first value in a table is accessed when the 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.

7-segment display

                    ;Expt4.asm
;Project: Counting on 7-segment display
List P = 16F84
#include <p16F84.inc>
__CONFIG 1Bh    ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC

SetUp

Table

Delay

Del1

Main
Main1

Main2

ORG 0
BSF 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 

;This is the start of memory for the program.
;Go to Bank 1
;Make all port B output
;Load W with 0000 0001
;Make RA0 input
;Go to Bank 0 – the program memory area.
;
;Put “0” on display at reset
;Clear the count file
;Clear the button-press file

;Add W to the Program Counter to create a jump.
;    format= gfedcba
;1    If any table value has a leading letter, it must be
;2    preceded with a “0.”   E.g: 0A3h, 0FFh, 0CCh
;3
;4
;5
;6
;7
;8
;9
;0

;Create 1mS debounce delay

;1E holds the count-value. Next increment: file=1
;Test the input line on port A
;Button not pressed
;Debounce the button
;Button pressed first time?
;Button already pressed
;First time button pressed. Increment count.
;Has count reached eleven?
;Compare file 1E with eleven
;Check the zero flag in Status file
;
;Copy count into W
;W will return with display-value
;Output display value
;Set button-press flag
;Loop Main1
;Button not pressed. Call Delay
;Clear button-press flag
;Loop Main1

;Tells assembler end of program

EXPERIMENT 4a
Binary Counting

This experiment produces a binary count on the 8 LEDs.  The output will always show the content of file 06. File 06 can be incremented, decremented, and shifted, etc just like any of the other files. The program increments the count in file 06 and shows it for 0.5sec, before incrementing to the next value. A files will show values in binary, from 00 to 127, making a total of 128 for each cycle of the file. 

                    ;Expt4a.asm
;Project: Binary Counting
List P = 16F84
#include <p16F84.inc>
__CONFIG 1Bh    ;_CP_OFF & _PWRTE_ON & _WDT_OFF & _RC_OSC

SetUp

Delay

Main

ORG 0
BSF 03,5
CLRF 06
BCF 03,5
CLRF 06
GOTO Main

NOP
DECFSZ 1A,1
GOTO Delay
DECFSZ 1B,1
GOTO Delay
RETURN

CALL Delay
CALL Delay
INCF 06
GOTO Main

END

;This is the start of memory for the program.
;Go to Bank 1
;Make all port B output
;Go to Bank 0 – the program memory area.
;Turn off all LEDs

;Create approx 250mS delay

;Show LEDs for 250mS
;Show LEDs for 250mS
;Increment the count in file 6
;Loop

;Tells assembler end of program

EXPERIMENT 4b
Binary Counting – up/down

This experiment counts up and down in binary. A push button reverses the count.
It is very interesting to see how a file increments and decrements. This will help you understand binary numbers. The numbers increment at 4 counts per second. At the same time you will see all combinations of segments on the 7-segment display. 

 

For more detail: Counting on the 7-segment display




Current Project / Post can also be found using:

  • pic16f690 7 segment display program tutorial
  • 7 segment push button controller
  • how to start counting 7segment using push button code proteus
  • lookup table in pic16f84a in assembly

Leave a Comment

*
= 3 + 8

Read previous post:
Seven segment display 4 digit For CSS Compiler

#include <16F877.h> #device adc=8 #fuses NOWDT,HS, NOPUT, NOPROTECT, BROWNOUT, NOLVP, NOCPD, NOWRT, NODEBUG #use delay(clock=4000000) #define sw_up pin_a0 // SWITCH...

Close
Scroll to top