Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Need help editing my 0-9 up counter to 0-99 up/down counter

Need help editing my 0-9 up counter to 0-99 up/down counter

Need help editing my 0-9 up counter to 0-99 up/down counter

I created a code that can count up from 0 to 9. I have copied it below. It's in .asm
I'm trying to make it into a 0-99 up/down counter by making P1.7 a '1' to count up and '0' to count down. I need help in how to do this and how to make it count up to 99 and down to zero. The inputs are at P0.0-6 from a dip switch. Do I need to list out the Equ and lookup table from 0-99 or is there an easier way to do this? I appreciate any help or advice on this in advance.

; Use this code to setup the I/O and XBAR, and turn off the Watch Dog Timer.
; DESCRIPTION : This code disables the watchdog timer and
; configures the Port I/O crossbar.

$include (c8051f330.inc) ; Include register definition file.


error equ 86H
zero equ 0C0H
one equ 0F9H
two equ 0A4H
three equ 0B0H
four equ 99H
five equ 92H
six equ 82H
seven equ 0F8H
eight equ 80H
nine equ 98H
dp equ 7FH

new equ 00
old equ 01
temp equ 02

ten equ 0AH


; Reset Vector
ORG 0000H
ljmp Main ; Locate a jump to the start of
; code at the reset vector.


; Disable the WDT.
anl PCA0MD, #NOT(040h) ;clear Watchdog Enable bit

; Enable the Port I/O Crossbar
mov XBR1, #0C0h ;enable Crossbar

mov R4,#05h ;Five blink lamp test
call wait ;call subroutine one second delay
mov P1,#10000000B ;common anode display
call wait ;one second delay
mov P1,#11111111B ;blanks the display
djnz R4, Lamptest ;R4 value decremented
sjmp start ;jump to beginning

start: mov B,P0 ;store values of inputs here
anl B,#0FH ;mask high nibble,low nibble in use
mov R0,B ;value of p1 stored in R0
cjne R0,#ten,$+3 ;R0=new
jc lessthan ;less than 9
jnc tenplus ;greater than 9

lessthan: mov A,R1 ;R1=old
cjne A,00,next ;R0=new a=old
jmp lightup ;jump
;new=>old new=>temp
next: mov old,new ;new value into the old
mov temp,new ;new value into the temp
jmp lightup ;jump

;; Seven Segment Display

lightup: mov A,temp
call display ;calls a lookup table
mov P1,A ;move whats in the acc. to outputs
call wait ;call wait
inc temp ;increment temp
;temp greater than 9?
cjne R2,#ten,$+3 ;R2=temp
;temp 9-
jc start
;temp 9+
mov temp,old
jnc start

;number greater than 9
tenplus: mov P1, #10000000B
call wait
setb P0.7
call wait
jmp start

; Simple delay loop.
Loop2: mov R7, #0CH
Loop1: mov R6, #00H
Loop0: mov R5, #00H
djnz R5, $
djnz R6, Loop0
djnz R7, Loop1

;seven segement display
display: inc A
movc A,@A+pc
table: db zero,one,two,three,four,five,six,seven,eight,nine

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close