diff --git a/bcd.h b/bcd.h new file mode 100644 index 0000000..279a076 --- /dev/null +++ b/bcd.h @@ -0,0 +1,14 @@ +#ifndef BCD_H_ +#define BCD_H + +#include + +uint8_t bcd_add(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len) __reentrant; +void bcd_9cpl(__idata uint8_t *v1, uint8_t len) __reentrant; +void bcd_shr(__idata uint8_t *v, uint8_t len, uint8_t d) __reentrant; +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); + +#endif + diff --git a/bcd_9cpl.c b/bcd_9cpl.c new file mode 100644 index 0000000..5135bc4 --- /dev/null +++ b/bcd_9cpl.c @@ -0,0 +1,26 @@ + +#include "bcd.h" + + +void bcd_9cpl(__idata uint8_t *v1, uint8_t len) __reentrant +{ + __asm + + mov a,_bp + add a,#0xfd + mov sp,a + mov r0,dpl + pop ar7 + + clr c +001$: + mov a,#0x99 + subb a,@r0 + mov @r0,a + inc r0 + djnz r7,001$ + mov sp,_bp + + __endasm; +} + diff --git a/bcd_add.c b/bcd_add.c new file mode 100644 index 0000000..113a994 --- /dev/null +++ b/bcd_add.c @@ -0,0 +1,34 @@ +#include "mc8051fun.h" +#include "bcd.h" + +#pragma disable_warning 59 // Disable "must return a value" warning + +uint8_t bcd_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 sp,a + pop ar1 + pop ar7 + mov ar0,dpl + clr c +001$: + mov a,@r0 + addc a,@r1 + da a + mov @r0,a + inc r0 + inc r1 + djnz r7,001$ + mov dpl,#0x00 + jnc $002 + inc dpl +$002: + mov sp,_bp + __endasm; +} + + + diff --git a/bcd_addbyte.c b/bcd_addbyte.c new file mode 100644 index 0000000..ab1dc92 --- /dev/null +++ b/bcd_addbyte.c @@ -0,0 +1,43 @@ + +#include "bcd.h" + +#pragma disable_warning 59 // Disable "must return a value" warning + +void bcd_addbyte(__idata uint8_t *v1, uint8_t len, uint8_t ab) __reentrant +{ + (void)v1; (void)len; (void)ab; + + __asm + mov a,_bp + add a,#0xfd + mov sp,a + + mov r0,dpl + pop ar7 + pop ACC + mov r6,a + add a,#0xb0 ; carry will be set if a>=5 + jc 001$ + mov b,#0x00 + ajmp 004$ +001$: + mov b,#0x99 +004$: + mov a,@r0 + add a,r6 + da a + mov @r0,a + sjmp 002$ +000$: + inc r0 + mov a,@r0 + addc a,#0x00 + da a + mov @r0,a +002$: + djnz r7,000$ + mov sp,_bp + __endasm; +} + + diff --git a/bcd_getsig.c b/bcd_getsig.c new file mode 100644 index 0000000..af36c15 --- /dev/null +++ b/bcd_getsig.c @@ -0,0 +1,10 @@ + +#include "bcd.h" + +#pragma opt_code_size +uint8_t bcd_getsig(__idata uint8_t*v, uint8_t len) +{ + return v[len-1]>=0x50; +} + + diff --git a/bcd_invert.c b/bcd_invert.c new file mode 100644 index 0000000..d214f47 --- /dev/null +++ b/bcd_invert.c @@ -0,0 +1,11 @@ +#include "bcd.h" + + +void bcd_invert(__idata uint8_t *v1, uint8_t len) +{ + bcd_9cpl(v1,len); + bcd_addbyte(v1,len,1); +} + + + diff --git a/bcd_shr.c b/bcd_shr.c new file mode 100644 index 0000000..f9d9989 --- /dev/null +++ b/bcd_shr.c @@ -0,0 +1,38 @@ +#include "bcd.h" + + +#pragma disable_warning 59 // Disable "must return a value" warning + +void bcd_shr(__idata uint8_t *v, uint8_t len, uint8_t d) __reentrant +{ + (void)v; (void)len, (void)d; + + __asm + mov a,_bp + add a,#0xfd + mov sp,a + + pop ar7 ; r7 = len + pop B ; + mov a,dpl + add a,r7 + mov r0,a +001$: + dec r0 + mov a,@r0 + swap a + mov r6,a + anl a,#0x0f + orl a,b + mov @r0,a + mov a,r6 + anl a,#0xf0 + mov b,a + djnz r7,001$ + + mov sp,_bp + + __endasm; +} + + diff --git a/mc8051fun.h b/mc8051fun.h index d481c63..ef94b70 100644 --- a/mc8051fun.h +++ b/mc8051fun.h @@ -75,8 +75,6 @@ int getpin(i8051pin_T *pin); void setpin(i8051pin_T *pin, uint8_t val); uint8_t getport(int n); - - #define AR0 0x00 #define AR1 0x01 #define AR2 0x02 @@ -88,6 +86,7 @@ uint8_t getport(int n); +uint8_t multest(uint8_t a, uint8_t b); diff --git a/multest.c b/multest.c new file mode 100644 index 0000000..6447540 --- /dev/null +++ b/multest.c @@ -0,0 +1,8 @@ + + +#include "mc8051fun.h" + +uint8_t multest(uint8_t a, uint8_t b) +{ + return a*b; +}