Added bcd files

This commit is contained in:
7u83 2024-06-13 22:07:19 +02:00
parent 9a906c35ad
commit 20f8a58db0
9 changed files with 185 additions and 2 deletions

14
bcd.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef BCD_H_
#define BCD_H
#include <stdint.h>
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

26
bcd_9cpl.c Normal file
View File

@ -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;
}

34
bcd_add.c Normal file
View File

@ -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;
}

43
bcd_addbyte.c Normal file
View File

@ -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;
}

10
bcd_getsig.c Normal file
View File

@ -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;
}

11
bcd_invert.c Normal file
View File

@ -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);
}

38
bcd_shr.c Normal file
View File

@ -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;
}

View File

@ -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);

8
multest.c Normal file
View File

@ -0,0 +1,8 @@
#include "mc8051fun.h"
uint8_t multest(uint8_t a, uint8_t b)
{
return a*b;
}