|
xyz316 (Programmer) |
4 Nov 08 14:57 |
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.
$NOMOD51 ;----------------------------------------------------------------------------- ; 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. ; ; NOTES: ; ;-----------------------------------------------------------------------------
$include (c8051f330.inc) ; Include register definition file.
;----------------------------------------------------------------------------- ; EQUATES ;-----------------------------------------------------------------------------
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 and INTERRUPT VECTORS ;-----------------------------------------------------------------------------
; Reset Vector ORG 0000H ljmp Main ; Locate a jump to the start of ; code at the reset vector.
;----------------------------------------------------------------------------- ; CODE ;-----------------------------------------------------------------------------
Main: ; 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 Lamptest: 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
;new=old 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. wait: Loop2: mov R7, #0CH Loop1: mov R6, #00H Loop0: mov R5, #00H djnz R5, $ djnz R6, Loop0 djnz R7, Loop1 ret
;seven segement display display: inc A movc A,@A+pc ret table: db zero,one,two,three,four,five,six,seven,eight,nine |
|