📄 hexdec-lcd.a51.asm
字号:
MOV R2,#0 ;&column,start from home pos.
CStringSkip2: INC DPTR ;next chacter
AJMP WriteCString
;write a string from ram memory
;R0=address of string in ram memory
;R1=row number
;R2=column number
WriteAString: MOV A,@R0 ;first char from ram position to acc.
CJNE A,#0,WriteASkip1 ;is it the end code?
RET
WriteASkip1: MOV R3,A
MOV A,R0 ;ro save
PUSH ACC
CALL PutCharOnLCD ;display char.
POP ACC ;r0 restore
MOV R0,A
INC R2 ;next column
CJNE R2,#LCDLineLength,AStringSkip2 ;is it max number of column?
MOV R2,#0 ;yes,clear column number
INC R1 ;and go to the next row
CJNE A,#LCDRowsNum,AStringSkip2 ;is it the max number of row?
MOV R1,#0 ;yes,clear row number and
MOV R2,#0 ;go to the first row
AStringSkip2: INC R0 ;increment pointer address
JMP WriteAString
;3 bytes of hex number to decimal convertion routine
;number in r5,r6,r7 (r5-msb,..,r7-lsb), result in r4,r5,r6,r7
;the routine counts, how many times you can subtract the 1000000 from numer, then 100000,10000,1000,100,10,1
;each counter equals position of decimal number f.e.:
; 1E74 hex - you can subtract 1000 seven (7) times, 100 seven (7) times, 10 nine (9) times and the rest
;is six (6), so your result of conversion is 7796 (equals 1E74)
Hex3DecConv: CLR C
MOV R4,#0 ;milion counter clear
Hex3DecLoop1: MOV A,R7 ;how many time we can subtract 10000000 without carry (989680H)
SUBB A,#80H
MOV R7,A
MOV A,R6
SUBB A,#96H
MOV R6,A
MOV A,R5
SUBB A,#98H
MOV R5,A
JC Hex3DecSkip1
INC R4
JMP Hex3DecLoop1
Hex3DecSkip1: MOV A,R4
PUSH ACC ;push counter onto stack
MOV A,R7
ADD A,#80H
MOV R7,A
MOV A,R6
ADDC A,#96H
MOV R6,A
MOV A,R5
ADDC A,#98H
MOV R5,A
CLR C
MOV R4,#0
Hex3DecLoop2: MOV A,R7 ;how many times we can subtract 1000000 (F4240H) without carry
SUBB A,#40H
MOV R7,A
MOV A,R6
SUBB A,#42H
MOV R6,A
MOV A,R5
SUBB A,#0FH
MOV R5,A
JC Hex3DecSkip2
INC R4
JMP Hex3DecLoop2
Hex3DecSkip2: MOV A,R4
PUSH ACC ;push counter onto stack
MOV A,R7
ADD A,#40H
MOV R7,A
MOV A,R6
ADDC A,#42H
MOV R6,A
MOV A,R5
ADDC A,#0FH
MOV R5,A
CLR C
MOV R4,#0
Hex3DecLoop3: MOV A,R7 ;100000 (186A0H)?
SUBB A,#0A0H
MOV R7,A
MOV A,R6
SUBB A,#86H
MOV R6,A
MOV A,R5
SUBB A,#01H
MOV R5,A
JC Hex3DecSkip3
INC R4
JMP Hex3DecLoop3
Hex3DecSkip3: MOV A,R4
PUSH ACC ;onto stack
MOV A,R7
ADD A,#0A0H
MOV R7,A
MOV A,R6
ADDC A,#86H
MOV R6,A
MOV A,R5
ADDC A,#01H
MOV R5,A
Hex2DecConv: MOV R4,#0
CLR C
Hex2DecLoop1: MOV A,R7 ;10000 (2710h)?
SUBB A,#010H
MOV R7,A
MOV A,R6
SUBB A,#27H
MOV R6,A
MOV A,R5
SUBB A,#0
MOV R5,A
JC Hex2DecSkip1
INC R4
JMP Hex2DecLoop1
Hex2DecSkip1: MOV A,R4 ;onto stack
PUSH ACC
MOV A,R7
ADD A,#010H
MOV R7,A
MOV A,R6
ADDC A,#27H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop2: MOV A,R7 ;1000 (3E8h)?
SUBB A,#0E8H
MOV R7,A
MOV A,R6
SUBB A,#03H
MOV R6,A
JC Hex2DecSkip2
INC R4
JMP Hex2DecLoop2
Hex2DecSkip2: MOV A,R4 ;onto satck
PUSH ACC
MOV A,R7
ADD A,#0E8H
MOV R7,A
MOV A,R6
ADDC A,#03H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop3: MOV A,R7 ;100 (64h)?
SUBB A,#064H
MOV R7,A
MOV A,R6
SUBB A,#0H
MOV R6,A
JC Hex2DecSkip3
INC R4
JMP Hex2DecLoop3
Hex2DecSkip3: MOV A,R4 ;onto stack
PUSH ACC
MOV A,R7
ADD A,#064H
MOV R7,A
MOV A,R6
ADDC A,#0H
MOV R6,A
CLR C
MOV R4,#0
Hex2DecLoop4: MOV A,R7 ;10 (0Ah)?
SUBB A,#0AH
MOV R7,A
JC Hex2DecSkip4
INC R4
JMP Hex2DecLoop4
Hex2DecSkip4: MOV A,R4 ;onto stack
PUSH ACC
ADD A,#0AH ;1
MOV A,R7 ;tens & ones in w R7
ADD A,#0AH
MOV R7,A
POP ACC
SWAP A
ADD A,R7
MOV R7,A
POP ACC ;thousands & hundreds in R6
MOV R6,A
POP ACC
SWAP A
ADD A,R6
MOV R6,A
POP ACC ;tens thousands & hundreds thousands in R5
MOV R5,A
POP ACC
SWAP A
ADD A,R5
MOV R5,A
POP ACC ;milins & tens milions in R4
MOV R4,A
POP ACC
SWAP A
ADD A,R4
MOV R4,A
RET
;Decimal to ascii conversion
;decimal in r4(msb),r5,r6,r7(lsb),result in ram buffer LCD_1(0..7)
;note:numbers are in correct order after hex2dec conversion routine
;routine takes each of decimal number (4 bits of 8 bit register) and adds it to 0 ascii code character
;f.e. 15 => '0'+1 -> '1' , '0'+5 -> '5'
Dec2AsciiConv: MOV A,#LCD_1
MOV R0,A ;pointer to lcd_1
MOV A,R4
ANL A,#0F0H
SWAP A
ADD A,#'0'
MOV @R0,A
INC R0
MOV A,R4
ANL A,#0FH
ADD A,#'0'
MOV @R0,A
INC R0
MOV A,R5
ANL A,#0F0H
SWAP A
ADD A,#'0'
MOV @R0,A
INC R0
MOV A,R5
ANL A,#0FH
ADD A,#'0'
MOV @R0,A
INC R0
MOV A,R6
ANL A,#0F0H
SWAP A
ADD A,#'0'
MOV @R0,A
INC R0
MOV A,R6
ANL A,#0FH
ADD A,#'0'
MOV @R0,A
INC R0
MOV A,R7
ANL A,#0F0H
SWAP A
ADD A,#'0'
MOV @R0,A
INC R0
MOV A,R7
ANL A,#0FH
ADD A,#'0'
MOV @R0,A
INC R0 ;put the end of string code
MOV A,#0
MOV @R0,A
RET
;write version procedure,example of writecstring using
WriteVersion: CALL ClearLCD ;clear screen
MOV R1,#0 ;first column & first row
MOV R2,#0
MOV DPTR,#Copyright
CALL WriteCString
RET
;definicje znak體
Char: DB 0AAH,055H,0AAH,055H,0AAH,055H,0AAH,055H ;#
C1: DB 0C0H,0C0H,0FFH,0F1H,0F1H,0F1H,0FFH,0C0H ;blank quadrant
C2: DB 0C0H,0C0H,0FFH,0FFH,0FFH,0FFH,0FFH,0C0H ;blak quadrant
C3: DB 0E0H,0FFH,0FFH,0FFH,0E0H,0E0H,0E0H,0E0H ;near minus
C4: DB 0FFH,0FFH,0F9H,0F3H,0E7H,0F3H,0F9H,0FFH ;Left
C5: DB 0FFH,0FFH,0F3H,0F9H,0FCH,0F9H,0F3H,0FFH ;Right
C6: DB 0FFH,0FFH,0FBH,0F1H,0E4H,0EEH,0FFH,0FFH ;Up
C7: DB 0FFH,0FFH,0FFH,0EEH,0E4H,0F1H,0FBH,0FFH,0 ;Down
Copyright: DB 'LCD 4x40 using example',0
ConvDesc: DB '1E87 hex to decimal=',0
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -