Compare commits
8 Commits
f1853c097c
...
master
Author | SHA1 | Date | |
---|---|---|---|
5761d5c513 | |||
71a551d028 | |||
ffeea2dfaf | |||
6153bb3fb4 | |||
6c2e631e56 | |||
11db18ee92 | |||
b24da848ac | |||
92144104ec |
12
Makefile
12
Makefile
@ -23,7 +23,17 @@ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \
|
||||
getpin.c setpin_lo.c setpin_hi.c setpin.c getport.c \
|
||||
long_xadd.c long_xsub.c long_xset.c long_xrlc.c long_xdiv.c long_xcpy.c long_xtobcd.c \
|
||||
multest.c \
|
||||
bcd_add.c bcd_getsig.c bcd_invert.c bcd_9cpl.c bcd_addbyte.c bcd_shr.c
|
||||
bcd_add.c bcd_getsig.c bcd_invert.c bcd_9cpl.c bcd_addbyte.c bcd_shr.c \
|
||||
long_rrc__.c long_rlc__.c \
|
||||
long_tobcd__.c long_tobcd.c \
|
||||
bcd_tolong__.c bcd_tolong.c \
|
||||
long_addbyte__.c long_addbyte.c \
|
||||
long_add__.c long_add.c \
|
||||
long_1cpl__.c long_invert__.c long_invert.c \
|
||||
long_sub__.c \
|
||||
long_div__.c long_div.c \
|
||||
long_fill__.c long_mul__.c long_mul.c
|
||||
|
||||
|
||||
LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC))
|
||||
LIBNAME=mc8051fun.lib
|
||||
|
2
bcd.h
2
bcd.h
@ -10,5 +10,7 @@ void bcd_invert(__idata uint8_t *v1, uint8_t len);
|
||||
void bcd_addbyte(__idata uint8_t *v1, uint8_t len, uint8_t b) __reentrant;
|
||||
uint8_t bcd_getsig(__idata uint8_t*v, uint8_t len);
|
||||
|
||||
void long_tobcd(__idata uint8_t *binval, __idata uint8_t *bcdval, uint8_t binlen, uint8_t bcdlen) __reentrant;
|
||||
|
||||
#endif
|
||||
|
||||
|
33
bcd_tolong.c
Normal file
33
bcd_tolong.c
Normal file
@ -0,0 +1,33 @@
|
||||
#include "mc8051fun.h"
|
||||
|
||||
/*
|
||||
* C-Wrapper for bcd_tolong
|
||||
*/
|
||||
|
||||
void bcd_tolong(__idata uint8_t *bcdval, __idata uint8_t *binval, uint8_t bcdlen, uint8_t binlen) __reentrant
|
||||
{
|
||||
(void)binval;
|
||||
(void)bcdval;
|
||||
(void)binlen;
|
||||
(void)bcdlen;
|
||||
|
||||
__asm
|
||||
mov a,_bp
|
||||
add a,#0xfd
|
||||
mov r0,a
|
||||
mov a,@r0 ; binval
|
||||
mov r1,a
|
||||
dec r0
|
||||
mov a,@r0 ; bcdlen
|
||||
mov r7,a
|
||||
dec r0
|
||||
mov a,@r0 ; binlen
|
||||
mov r6,a
|
||||
mov r0,dpl ; bcdval
|
||||
lcall bcd_tolong
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
||||
|
67
bcd_tolong__.c
Normal file
67
bcd_tolong__.c
Normal file
@ -0,0 +1,67 @@
|
||||
#include "usebank0.h"
|
||||
/*
|
||||
r0 = bcd
|
||||
r1 = bin
|
||||
r7 = len of bcd
|
||||
r6 = len of bin
|
||||
|
||||
|
||||
reverse double dabble
|
||||
*/
|
||||
|
||||
static void bcd_tolong__() __naked
|
||||
{
|
||||
|
||||
__asm
|
||||
|
||||
.globl bcd_tolong
|
||||
bcd_tolong:
|
||||
mov a,AR6 ; use r4 as counter
|
||||
mov b,#0x08
|
||||
mul ab
|
||||
mov r4,a
|
||||
|
||||
|
||||
000$:
|
||||
push AR0
|
||||
push AR7
|
||||
clr c
|
||||
|
||||
lcall long_rrc
|
||||
mov r0,AR1
|
||||
mov r7,AR6
|
||||
|
||||
lcall long_rrc
|
||||
pop AR7
|
||||
pop AR0
|
||||
push AR0
|
||||
push AR7
|
||||
|
||||
001$:
|
||||
mov a,@r0
|
||||
acall 003$
|
||||
acall 003$
|
||||
mov @r0,a
|
||||
|
||||
inc r0
|
||||
djnz r7,001$
|
||||
pop AR7
|
||||
pop AR0
|
||||
djnz r4,000$
|
||||
ret
|
||||
003$:
|
||||
swap a
|
||||
clr c
|
||||
subb a,#0x80
|
||||
jc 002$
|
||||
subb a,#0x30
|
||||
002$:
|
||||
add a,#0x80
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
22
long_1cpl__.c
Normal file
22
long_1cpl__.c
Normal file
@ -0,0 +1,22 @@
|
||||
|
||||
#include "mc8051fun.h"
|
||||
|
||||
static void long_1cpl__() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_1cpl
|
||||
|
||||
long_1cpl:
|
||||
|
||||
clr c
|
||||
001$:
|
||||
mov a,#0xff
|
||||
subb a,@r0
|
||||
mov @r0,a
|
||||
inc r0
|
||||
djnz r7,001$
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
28
long_add.c
Normal file
28
long_add.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include "mc8051fun.h"
|
||||
#include "bcd.h"
|
||||
|
||||
#pragma disable_warning 59 // Disable "must return a value" warning
|
||||
|
||||
uint8_t long_add(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len) __reentrant
|
||||
{
|
||||
(void)v1; (void)v2; (void)len;
|
||||
__asm
|
||||
mov a,_bp
|
||||
add a,#0xfd
|
||||
mov r0,a
|
||||
mov a,@r0 ; *v2
|
||||
dec r0
|
||||
mov r1,a
|
||||
mov a,@r0 ; len
|
||||
mov r7,a
|
||||
mov r0,dpl
|
||||
lcall long_invert
|
||||
mov dpl,#0x00
|
||||
jnc $002
|
||||
inc dpl
|
||||
$002:
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
||||
|
27
long_add__.c
Normal file
27
long_add__.c
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* @r0 = @r0+@r1
|
||||
* r7=len
|
||||
*/
|
||||
|
||||
static void long_add__() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_add
|
||||
.globl long_addc
|
||||
long_add:
|
||||
clr c
|
||||
long_addc:
|
||||
001$:
|
||||
mov a,@r0
|
||||
addc a,@r1
|
||||
mov @r0,a
|
||||
inc r0
|
||||
inc r1
|
||||
djnz r7,001$
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
||||
|
26
long_addbyte.c
Normal file
26
long_addbyte.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "mc8051fun.h"
|
||||
|
||||
/**
|
||||
* C wrapper for long_addbyte
|
||||
*/
|
||||
|
||||
static void long_addbyte(__idata uint8_t * val, uint8_t len, uint8_t b) __reentrant
|
||||
{
|
||||
(void)val;
|
||||
(void)b;
|
||||
|
||||
__asm
|
||||
mov a,_bp
|
||||
add a,#0xfd
|
||||
mov r0,a
|
||||
mov a,@r0 ; len
|
||||
mov r7,a
|
||||
dec r0
|
||||
mov a,@r0 ; b
|
||||
mov r0,dpl
|
||||
lcall long_addbyte
|
||||
|
||||
__endasm;
|
||||
|
||||
}
|
||||
|
23
long_addbyte__.c
Normal file
23
long_addbyte__.c
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* a = byte to add
|
||||
* @r0 = long val
|
||||
* r7 = length
|
||||
*
|
||||
*/
|
||||
static void long_addbyte__() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_addbyte
|
||||
long_addbyte:
|
||||
clr c
|
||||
ajmp 002$
|
||||
001$:
|
||||
mov a,#0x00
|
||||
002$:
|
||||
addc a,@r0
|
||||
mov @r0,a
|
||||
inc r0
|
||||
djnz r7,001$
|
||||
ret
|
||||
__endasm;
|
||||
}
|
34
long_div.c
Normal file
34
long_div.c
Normal file
@ -0,0 +1,34 @@
|
||||
#include "mc8051fun.h"
|
||||
#include "bcd.h"
|
||||
|
||||
#pragma disable_warning 59 // Disable "must return a value" warning
|
||||
|
||||
|
||||
void long_div(__idata uint8_t *v1, __idata uint8_t *v2,
|
||||
__idata uint8_t *result, __idata uint8_t *rest, uint8_t len) __reentrant
|
||||
{
|
||||
|
||||
(void)v1; (void)v2; (void)len;
|
||||
(void)result; (void)rest;
|
||||
|
||||
__asm
|
||||
mov a,_bp
|
||||
add a,#0xfd
|
||||
mov r0,a
|
||||
mov a,@r0 ; *v2
|
||||
dec r0
|
||||
mov r1,a
|
||||
mov a,@r0 ; *result
|
||||
dec r0
|
||||
mov r2,a
|
||||
mov a,@r0 ; *rest
|
||||
dec r0
|
||||
mov r3,a
|
||||
mov a,@r0 ; len
|
||||
mov r7,a
|
||||
mov r0,dpl ; *v1
|
||||
lcall long_div
|
||||
__endasm;
|
||||
|
||||
}
|
||||
|
67
long_div__.c
Normal file
67
long_div__.c
Normal file
@ -0,0 +1,67 @@
|
||||
#include "mc8051fun.h"
|
||||
|
||||
/*
|
||||
* r0 = numerator
|
||||
* r1 = denominator
|
||||
* r2 = quotient (result)
|
||||
* r3 = rest
|
||||
* r7 = length in bytes
|
||||
*/
|
||||
static void long_div__() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_div
|
||||
long_div:
|
||||
|
||||
mov r5,AR7 ;#0x01
|
||||
push AR0
|
||||
mov r0,AR3
|
||||
; lcall long_xset_zero
|
||||
pop AR0
|
||||
|
||||
|
||||
mov r4,AR1
|
||||
mov a,r0
|
||||
add a,r5 ;#DIGITS-1
|
||||
mov r0,a
|
||||
003$:
|
||||
mov a,@r0
|
||||
mov r6,#8
|
||||
002$:
|
||||
rlc a
|
||||
push ACC
|
||||
push AR0
|
||||
|
||||
mov r0,AR3 ;#_rest
|
||||
mov r7,AR5 ;#DIGITS
|
||||
lcall long_rlc
|
||||
|
||||
mov r0,AR3 ;#_rest
|
||||
mov r7,AR5 ;#DIGITS
|
||||
push AR1
|
||||
lcall long_sub
|
||||
pop AR1
|
||||
|
||||
jnc 001$
|
||||
mov r0,AR3 ;#_rest
|
||||
mov r7,AR5 ;#DIGITS
|
||||
push AR1
|
||||
lcall long_add
|
||||
pop AR1
|
||||
setb c
|
||||
001$:
|
||||
cpl c
|
||||
mov r0,AR2 ; #_result
|
||||
mov r7,AR5 ;#DIGITS
|
||||
lcall long_rlc
|
||||
|
||||
pop AR0
|
||||
pop ACC
|
||||
djnz r6,002$
|
||||
djnz r0,003$
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
19
long_fill__.c
Normal file
19
long_fill__.c
Normal file
@ -0,0 +1,19 @@
|
||||
|
||||
|
||||
void long_fill() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_fill_zero
|
||||
.globl long_fill
|
||||
|
||||
long_fill_zero:
|
||||
mov a,#0x00
|
||||
long_fill:
|
||||
mov @r0,a
|
||||
inc r0
|
||||
djnz r7,long_fill
|
||||
ret
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
21
long_invert.c
Normal file
21
long_invert.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include "mc8051fun.h"
|
||||
|
||||
void long_invert(__idata uint8_t *val, uint8_t len) __reentrant
|
||||
{
|
||||
(void)val;
|
||||
(void)len;
|
||||
|
||||
__asm
|
||||
|
||||
mov a,_bp
|
||||
add a,#0xfd
|
||||
mov r0,a
|
||||
mov a,@r0 ; len
|
||||
mov r7,a
|
||||
mov r0,dpl
|
||||
lcall long_invert
|
||||
__endasm;
|
||||
|
||||
|
||||
}
|
||||
|
22
long_invert__.c
Normal file
22
long_invert__.c
Normal file
@ -0,0 +1,22 @@
|
||||
#include "mc8051fun.h"
|
||||
|
||||
static void long_invert__() __naked
|
||||
{
|
||||
__asm
|
||||
|
||||
.globl long_invert
|
||||
long_invert:
|
||||
push AR0
|
||||
push AR7
|
||||
|
||||
lcall long_1cpl
|
||||
|
||||
pop AR7
|
||||
pop AR0
|
||||
|
||||
mov a,#0x01
|
||||
lcall long_addbyte
|
||||
ret
|
||||
__endasm;
|
||||
|
||||
}
|
28
long_mul.c
Normal file
28
long_mul.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include "mc8051fun.h"
|
||||
|
||||
uint8_t long_mul(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len, __idata uint8_t *result) __reentrant
|
||||
{
|
||||
(void)v1; (void)v2; (void)len,(void)result;
|
||||
__asm
|
||||
mov a,_bp
|
||||
add a,#0xfd
|
||||
mov r0,a
|
||||
mov a,@r0 ; *v2
|
||||
dec r0
|
||||
mov r1,a
|
||||
mov a,@r0 ; len
|
||||
mov r7,a
|
||||
dec r0
|
||||
mov a,@r0 ; result
|
||||
mov r2,a
|
||||
mov r0,dpl
|
||||
lcall long_mul
|
||||
mov dpl,#0x00
|
||||
jnc $002
|
||||
inc dpl
|
||||
$002:
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
||||
|
55
long_mul__.c
Normal file
55
long_mul__.c
Normal file
@ -0,0 +1,55 @@
|
||||
#include "mc8051fun.h"
|
||||
|
||||
/*
|
||||
* val0,val1 = r0,r1
|
||||
* r2 = result
|
||||
* r7 = len of val0,val1
|
||||
*/
|
||||
void long_mul__() __naked
|
||||
{
|
||||
|
||||
__asm
|
||||
.globl long_mul
|
||||
|
||||
long_mul:
|
||||
push AR0
|
||||
push AR7
|
||||
mov r0,AR2
|
||||
lcall long_fill_zero
|
||||
pop AR7
|
||||
pop AR0
|
||||
|
||||
mov r6,#8
|
||||
mov a,@r1
|
||||
000$:
|
||||
rrc a
|
||||
jnc 001$
|
||||
|
||||
push ACC
|
||||
push AR0
|
||||
push AR1
|
||||
push AR7
|
||||
mov r1,AR0
|
||||
mov r0,AR2
|
||||
lcall long_add
|
||||
pop AR7
|
||||
pop AR1
|
||||
pop AR0
|
||||
pop ACC
|
||||
|
||||
001$:
|
||||
push ACC
|
||||
push AR7
|
||||
push AR0
|
||||
clr c
|
||||
lcall long_rlc
|
||||
pop AR0
|
||||
pop AR7
|
||||
pop ACC
|
||||
|
||||
djnz r6,000$
|
||||
ret
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
24
long_rlc__.c
Normal file
24
long_rlc__.c
Normal file
@ -0,0 +1,24 @@
|
||||
|
||||
/*
|
||||
* @r0 = number
|
||||
* r7 = len
|
||||
*
|
||||
* modyfies: r0,r7,a
|
||||
*/
|
||||
static void long_rlc__() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_rlc
|
||||
|
||||
long_rlc:
|
||||
mov a,@r0
|
||||
rlc a
|
||||
mov @r0,a
|
||||
inc r0
|
||||
djnz r7,long_rlc
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
29
long_rrc__.c
Normal file
29
long_rrc__.c
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
/*
|
||||
* @r0 = number
|
||||
* r7 = len
|
||||
*
|
||||
* modyfies: r0,r7,a
|
||||
*/
|
||||
static void long_rrc__() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_rrc
|
||||
long_rrc:
|
||||
push PSW
|
||||
mov a,r0
|
||||
add a,r7
|
||||
mov r0,a
|
||||
pop PSW
|
||||
001$:
|
||||
dec r0
|
||||
mov a,@r0
|
||||
rrc a
|
||||
mov @r0,a
|
||||
djnz r7,001$
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
25
long_sub__.c
Normal file
25
long_sub__.c
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
/**
|
||||
* @r0=@r0-@r1
|
||||
* r7=len
|
||||
*/
|
||||
static void long_sub() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_sub
|
||||
.globl long_subb
|
||||
long_sub:
|
||||
clr c
|
||||
long_subb:
|
||||
mov a,@r0
|
||||
subb a,@r1
|
||||
mov @r0,a
|
||||
inc r0
|
||||
inc r1
|
||||
djnz r7,long_xsubb
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
33
long_tobcd.c
Normal file
33
long_tobcd.c
Normal file
@ -0,0 +1,33 @@
|
||||
|
||||
#include "mc8051fun.h"
|
||||
|
||||
/*
|
||||
* C-Wrapper for long_tobcd
|
||||
*/
|
||||
|
||||
void long_tobcd(__idata uint8_t *binval, __idata uint8_t *bcdval, uint8_t binlen, uint8_t bcdlen) __reentrant
|
||||
{
|
||||
(void)binval;
|
||||
(void)bcdval;
|
||||
(void)binlen;
|
||||
(void)bcdlen;
|
||||
|
||||
__asm
|
||||
mov a,_bp
|
||||
add a,#0xfd
|
||||
mov r0,a
|
||||
mov a,@r0
|
||||
mov r1,a
|
||||
dec r0
|
||||
mov a,@r0
|
||||
mov r7,a
|
||||
dec r0
|
||||
mov a,@r0
|
||||
mov r6,a
|
||||
mov r0,dpl
|
||||
lcall long_tobcd
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
92
long_tobcd__.c
Normal file
92
long_tobcd__.c
Normal file
@ -0,0 +1,92 @@
|
||||
|
||||
/*
|
||||
r0 = bin
|
||||
r1 = bcd
|
||||
r7 = len of bin
|
||||
r6 = len of bcd
|
||||
*/
|
||||
|
||||
#include "mc8051fun.h"
|
||||
|
||||
#include "usebank0.h"
|
||||
|
||||
// double dabble
|
||||
|
||||
void long_tobcd__() __naked
|
||||
{
|
||||
__asm
|
||||
.globl long_tobcd
|
||||
|
||||
long_tobcd:
|
||||
|
||||
; fill dst with zeroes
|
||||
|
||||
mov r3,AR1 ; save r1 in r3
|
||||
mov r4,AR6 ; use r4 as counter
|
||||
; mov a,#0x00
|
||||
|
||||
000$:
|
||||
mov @r1,#0x0
|
||||
inc r1
|
||||
djnz r4,000$
|
||||
|
||||
|
||||
|
||||
mov a,r0
|
||||
add a,r7
|
||||
dec a
|
||||
mov r0,a ; r0 points to last byte of bin
|
||||
mov r2,AR0 ; save r0 in r2
|
||||
|
||||
006$:
|
||||
mov a,@r0
|
||||
mov r5,#0x08
|
||||
005$:
|
||||
mov r4,AR6 ; use r4 as counter
|
||||
mov r1,AR3
|
||||
|
||||
push ACC
|
||||
004$:
|
||||
mov a,@r1
|
||||
acall 003$
|
||||
acall 003$
|
||||
mov @r1,a
|
||||
inc r1
|
||||
djnz r4,004$
|
||||
|
||||
pop ACC
|
||||
|
||||
|
||||
rlc a
|
||||
push ACC
|
||||
push AR0
|
||||
push AR7
|
||||
mov r7,AR6
|
||||
mov r0,AR3
|
||||
lcall long_rlc
|
||||
pop AR7
|
||||
pop AR0
|
||||
pop ACC
|
||||
djnz r5,005$
|
||||
|
||||
|
||||
dec r0
|
||||
djnz r7,006$
|
||||
ret
|
||||
|
||||
|
||||
003$:
|
||||
swap a
|
||||
clr c
|
||||
subb a,#0x50
|
||||
jc 002$
|
||||
add a,#0x30
|
||||
002$:
|
||||
add a,#0x50
|
||||
ret
|
||||
|
||||
__endasm;
|
||||
}
|
||||
|
||||
|
||||
|
@ -88,6 +88,10 @@ uint8_t getport(int n);
|
||||
|
||||
uint8_t multest(uint8_t a, uint8_t b);
|
||||
|
||||
void bcd_tolong(__idata uint8_t *bcdval, __idata uint8_t *binval, uint8_t bcdlen, uint8_t binlen) __reentrant;
|
||||
void long_invert(__idata uint8_t *val, uint8_t len) __reentrant;
|
||||
uint8_t long_add(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len) __reentrant;
|
||||
uint8_t long_mul(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len, __idata uint8_t *result) __reentrant;
|
||||
|
||||
|
||||
#endif
|
||||
|
21
usebank0.h
Normal file
21
usebank0.h
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
#undef AR0
|
||||
#undef AR1
|
||||
#undef AR2
|
||||
#undef AR3
|
||||
#undef AR4
|
||||
#undef AR5
|
||||
#undef AR6
|
||||
#undef AR7
|
||||
|
||||
|
||||
#define AR0 0x00
|
||||
#define AR1 0x01
|
||||
#define AR2 0x02
|
||||
#define AR3 0x03
|
||||
#define AR4 0x04
|
||||
#define AR5 0x05
|
||||
#define AR6 0x06
|
||||
#define AR7 0x07
|
||||
|
||||
|
Reference in New Issue
Block a user