Calculadora 8051
Exames: Calculadora 8051. Pesquise 862.000+ trabalhos acadêmicosPor: Penha52 • 25/5/2014 • 5.272 Palavras (22 Páginas) • 804 Visualizações
;4 FUNCTION CALCULATOR PROGRAM
;Assumes 1.2MHz Clock for scan timing.
; TODO : Custom Character for the 'M' sign
; Check instances of multiple decimal point presses ( all covered ?)
;Reset vector
org 0000h
jmp start
;Start of the program
org 0100h
start: mov A,#030h ;1 line, 8 bits
call wrcmd
mov A,#LCD_SETVISIBLE + 4
call wrcmd
mov A,#LCD_SETDDADDR+15 ; Start at right hand side of the display
call wrcmd
mov A,#LCD_SETMODE + 3 ; Automatic Increment - Display shift left.
call wrcmd
mov 025h,#00h ; Set output mode (floating point).
call boundsbuffer ; Initialise the bounds buffer - used for error checking.
mov mode,#4 ; Initialise the constant buffer to 100. Primarily used for % ops.
mov digitcode,#031h
call storedigit
mov digitcode,#030h
call storedigit
mov digitcode,#030h
call storedigit
mov status,#00h ; variable used to determine the first key press after an operation.
mov bufferctr,#00h
mov opcounter,#00h
mov decimalcnt,#00h
call waitkey
halt: mov PCON,#1 ;Halt
;***********************************************************
;**** Floating Point Package ****
;********************************
$INCLUDE (FP52.ASM)
;Routine to peek arg at DPTR
argout: mov R0,#FP_NUMBER_SIZE
aoloop: movx A,@DPTR
anl A,#0F0h
rr a
rr a
rr a
rr a
add A,#aodata-$-3
movc A,@A+PC
call sndchr
movx A,@DPTR
anl A,#0Fh
add A,#aodata-$-3
movc A,@A+PC
call sndchr
inc DPTR
djnz R0, aoloop
ret
aodata: db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
;Routine to output character in A, preserving all but A.
sndchr: push R0B0
push R1B0
call getmode
mov digitcode,A
call storedigit
pop R1B0
pop R0B0
ret
;Routine to print error message at DPTR.
prterr: jmp wrstr
;Routine to handle input parameter error.
badprm: mov DPTR,#bpmsg
jmp wrstr
bpmsg: db 'Bad Parameter',0
;***********************************************************
;**** LCD Display Routines ****
;******************************
;LCD Registers addresses
LCD_CMD_WR equ 00h
LCD_DATA_WR equ 01h
LCD_BUSY_RD equ 02h
LCD_DATA_RD equ 03h
LCD_PAGE equ 80h
;LCD Commands
LCD_CLS equ 1
LCD_HOME equ 2
LCD_SETMODE equ 4
LCD_SETVISIBLE equ 8
LCD_SHIFT equ 16
LCD_SETFUNCTION equ 32
LCD_SETCGADDR equ 64
LCD_SETDDADDR equ 128
;Sub routine to write null terminated string at DPTR in program ram.
wrstr: mov P2,#LCD_PAGE
mov R0,#LCD_DATA_WR
wrstr1: clr A
movc A,@A+DPTR
jz wrstr2
movx @R0,A
call wtbusy
inc DPTR
jmp wrstr1
wrstr2: ret
;Sub routine to write null terminated string at DPTR in program ram.
wrstrslow: mov P2,#LCD_PAGE
mov R0,#LCD_DATA_WR
wrstr1s: clr A
movc
...