Compare commits
40 Commits
5c00e1633a
...
master
Author | SHA1 | Date | |
---|---|---|---|
5761d5c513 | |||
71a551d028 | |||
ffeea2dfaf | |||
6153bb3fb4 | |||
6c2e631e56 | |||
11db18ee92 | |||
b24da848ac | |||
92144104ec | |||
f1853c097c | |||
20f8a58db0 | |||
9a906c35ad | |||
5930cdc0b5 | |||
ea36658f5e | |||
46444987c3 | |||
253d1af028 | |||
6eefbcfedb | |||
4eae6e7023 | |||
89613a8bec | |||
31066f37f0 | |||
e7b50704d0 | |||
30f410891c | |||
b9a4e2b393 | |||
64210a94ec | |||
151891240d | |||
a2a9256061 | |||
18c6fc5220 | |||
815d9c94ba | |||
7cc46801fb | |||
696ccc30ab | |||
ff95ee6537 | |||
5457e799f5 | |||
384dbcd807 | |||
719e10974f | |||
c73d714dae | |||
d7cd9b8d4d | |||
1dfac0074b | |||
28a6ccc3ee | |||
6ca5f28555 | |||
08477b5f83 | |||
726a76eeff |
71
Makefile
Normal file
71
Makefile
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
-include defs.mak
|
||||||
|
|
||||||
|
|
||||||
|
SDCC ?= sdcc
|
||||||
|
SDAR ?= sdar
|
||||||
|
STCCODESIZE ?= 8192
|
||||||
|
SDCCOPTS ?= -mmcs51
|
||||||
|
SDCCREV ?= -Dstc15f204ea
|
||||||
|
STCGAL ?= stcgal
|
||||||
|
#/stcgal.py
|
||||||
|
STCGALOPTS ?=
|
||||||
|
STCGALPORT ?= /dev/ttyUSB0
|
||||||
|
STCGALPROT ?= auto
|
||||||
|
FLASHFILE ?= main.ihx
|
||||||
|
#SYSCLK ?= 11056
|
||||||
|
#FOSC ?=11056000L
|
||||||
|
CFLAGS ?= -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY
|
||||||
|
|
||||||
|
LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \
|
||||||
|
rotary_encoder_stat.c \
|
||||||
|
sevenseg_dec.c sevenseg_dec_inv.c \
|
||||||
|
int_to_bcd.c getbutton.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 \
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
|
PRGOBJ =$(patsubst %.c,%.rel, $(PRGSRC))
|
||||||
|
|
||||||
|
|
||||||
|
$(LIBNAME): $(LIBOBJ)
|
||||||
|
$(SDAR) -rc $(LIBNAME) $(LIBOBJ)
|
||||||
|
#all:
|
||||||
|
# make uart2.ihx
|
||||||
|
|
||||||
|
%.rel: %.c
|
||||||
|
$(SDCC) $(SDCCOPTS) $(SDCCREV) -DFOSC=$(FOSC) -o $@ -c $<
|
||||||
|
|
||||||
|
#eeprom:
|
||||||
|
# sed -ne '/:..1/ { s/1/0/2; p }' main.hex > eeprom.hex
|
||||||
|
|
||||||
|
flash: $(FLASHFILE)
|
||||||
|
$(STCGAL) -p $(STCGALPORT) -P $(STCGALPROT) -t $(SYSCLK) $(STCGALOPTS) $(FLASHFILE)
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f *.ihx *.hex *.bin *.rst
|
||||||
|
rm -f *.map
|
||||||
|
rm -f *.rel
|
||||||
|
rm -f *.lst
|
||||||
|
rm -f *.sym
|
||||||
|
rm -f *.asm
|
||||||
|
rm -f *.lk
|
||||||
|
rm -f *.mem
|
||||||
|
rm -f *.lib
|
||||||
|
|
||||||
|
cpp: SDCCOPTS+=-E
|
||||||
|
cpp: main
|
16
bcd.h
Normal file
16
bcd.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#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);
|
||||||
|
|
||||||
|
void long_tobcd(__idata uint8_t *binval, __idata uint8_t *bcdval, uint8_t binlen, uint8_t bcdlen) __reentrant;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
26
bcd_9cpl.c
Normal file
26
bcd_9cpl.c
Normal 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
34
bcd_add.c
Normal 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
43
bcd_addbyte.c
Normal 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
10
bcd_getsig.c
Normal 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
11
bcd_invert.c
Normal 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
38
bcd_shr.c
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
16
getbutton.c
Normal file
16
getbutton.c
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
uint8_t getbutton_time = 100;
|
||||||
|
int getbutton(uint8_t pinval, uint8_t *button)
|
||||||
|
{
|
||||||
|
if ( *button & 1 != pinval){
|
||||||
|
*button += 2;
|
||||||
|
if (*button > getbutton_time){
|
||||||
|
*button = pinval;
|
||||||
|
return pinval;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
*button = pinval;
|
||||||
|
return -1;
|
||||||
|
}
|
18
getpin.c
Normal file
18
getpin.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
int getpin(i8051pin_T *pin)
|
||||||
|
{
|
||||||
|
switch(pin->port){
|
||||||
|
case 0:
|
||||||
|
return P0 & (1<<(pin->pin)) ? 1:0;
|
||||||
|
case 1:
|
||||||
|
return P1 & (1<<(pin->pin)) ? 1:0;
|
||||||
|
case 2:
|
||||||
|
return P2 & (1<<(pin->pin)) ? 1:0;
|
||||||
|
case 3:
|
||||||
|
return P3 & (1<<(pin->pin)) ? 1:0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
19
getport.c
Normal file
19
getport.c
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
uint8_t getport(int n)
|
||||||
|
{
|
||||||
|
switch(n){
|
||||||
|
case 0:
|
||||||
|
return P0;
|
||||||
|
case 1:
|
||||||
|
return P1;
|
||||||
|
case 2:
|
||||||
|
return P2;
|
||||||
|
case 3:
|
||||||
|
return P3;
|
||||||
|
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
14
int_to_bcd.c
Normal file
14
int_to_bcd.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
uint16_t int_to_bcd(uint16_t i)
|
||||||
|
{
|
||||||
|
uint16_t b;
|
||||||
|
b = i%10;
|
||||||
|
i/=10;
|
||||||
|
b |= (i%10)<<4;
|
||||||
|
i/=10;
|
||||||
|
b |= (i%10)<<8;
|
||||||
|
i/=10;
|
||||||
|
b |= (i%10)<<12;
|
||||||
|
return b;
|
||||||
|
}
|
120
lcd.h
Normal file
120
lcd.h
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
#ifndef MC8051FUN_LCD_H_
|
||||||
|
#define MC8051FUN_LCD_H
|
||||||
|
|
||||||
|
#ifndef LCD_E
|
||||||
|
#define LCD_E P3_4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LCD_RS
|
||||||
|
#define LCD_RS P3_5
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LCD_RW
|
||||||
|
#define LCD_RW P3_6
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LCD_DATA
|
||||||
|
#define LCD_DATA P0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef LCD_READY
|
||||||
|
#define LCD_READY P0_7
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Clear Display -------------- 0b00000001
|
||||||
|
#define LCD_CLEAR_DISPLAY 0x01
|
||||||
|
|
||||||
|
// Cursor Home ---------------- 0b0000001x
|
||||||
|
#define LCD_CURSOR_HOME 0x02
|
||||||
|
|
||||||
|
// Set Entry Mode ------------- 0b000001xx
|
||||||
|
#define LCD_SET_ENTRY 0x04
|
||||||
|
|
||||||
|
#define LCD_ENTRY_DECREASE 0x00
|
||||||
|
#define LCD_ENTRY_INCREASE 0x02
|
||||||
|
#define LCD_ENTRY_NOSHIFT 0x00
|
||||||
|
#define LCD_ENTRY_SHIFT 0x01
|
||||||
|
|
||||||
|
// Set Display ---------------- 0b00001xxx
|
||||||
|
#define LCD_SET_DISPLAY 0x08
|
||||||
|
|
||||||
|
#define LCD_DISPLAY_OFF 0x00
|
||||||
|
#define LCD_DISPLAY_ON 0x04
|
||||||
|
#define LCD_CURSOR_OFF 0x00
|
||||||
|
#define LCD_CURSOR_ON 0x02
|
||||||
|
#define LCD_BLINKING_OFF 0x00
|
||||||
|
#define LCD_BLINKING_ON 0x01
|
||||||
|
|
||||||
|
// Set Shift ------------------ 0b0001xxxx
|
||||||
|
#define LCD_SET_SHIFT 0x10
|
||||||
|
|
||||||
|
#define LCD_CURSOR_MOVE 0x00
|
||||||
|
#define LCD_DISPLAY_SHIFT 0x08
|
||||||
|
#define LCD_SHIFT_LEFT 0x00
|
||||||
|
#define LCD_SHIFT_RIGHT 0x04
|
||||||
|
|
||||||
|
// Set Function --------------- 0b001xxxxx
|
||||||
|
#define LCD_SET_FUNCTION 0x20
|
||||||
|
|
||||||
|
#define LCD_FUNCTION_4BIT 0x00
|
||||||
|
#define LCD_FUNCTION_8BIT 0x10
|
||||||
|
#define LCD_FUNCTION_1LINE 0x00
|
||||||
|
#define LCD_FUNCTION_2LINE 0x08
|
||||||
|
#define LCD_FUNCTION_5X7 0x00
|
||||||
|
#define LCD_FUNCTION_5X10 0x04
|
||||||
|
|
||||||
|
#define LCD_SOFT_RESET 0x30
|
||||||
|
|
||||||
|
// Set CG RAM Address --------- 0b01xxxxxx (Character Generator RAM)
|
||||||
|
#define LCD_SET_CGADR 0x40
|
||||||
|
|
||||||
|
#define LCD_GC_CHAR0 0
|
||||||
|
#define LCD_GC_CHAR1 1
|
||||||
|
#define LCD_GC_CHAR2 2
|
||||||
|
#define LCD_GC_CHAR3 3
|
||||||
|
#define LCD_GC_CHAR4 4
|
||||||
|
#define LCD_GC_CHAR5 5
|
||||||
|
#define LCD_GC_CHAR6 6
|
||||||
|
#define LCD_GC_CHAR7 7
|
||||||
|
|
||||||
|
// Set DD RAM Address --------- 0b1xxxxxxx (Display Data RAM)
|
||||||
|
#define LCD_SET_DDADR 0x80
|
||||||
|
|
||||||
|
|
||||||
|
#define LCD_GOTO_HOME LCD_SET_DDADR
|
||||||
|
#define LCD_GOTO_LINE1 LCD_GOTO_HOME
|
||||||
|
#define LCD_GOTO_LINE2 LCD_SET_DDADR+0x40
|
||||||
|
|
||||||
|
|
||||||
|
#define lcd_wait_ready()\
|
||||||
|
LCD_E=1; \
|
||||||
|
LCD_RS=0; \
|
||||||
|
LCD_RW=1; \
|
||||||
|
LCD_DATA=0x80; \
|
||||||
|
while((LCD_DATA & 0x80)) \
|
||||||
|
{ \
|
||||||
|
LCD_E=0; \
|
||||||
|
LCD_E=1; \
|
||||||
|
} \
|
||||||
|
LCD_E=1; \
|
||||||
|
LCD_RW=0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#define lcd_cmd(c) \
|
||||||
|
lcd_wait_ready(); \
|
||||||
|
LCD_RS=0; \
|
||||||
|
LCD_DATA=c; \
|
||||||
|
LCD_E=0
|
||||||
|
|
||||||
|
#define lcd_chr(c) \
|
||||||
|
lcd_wait_ready(); \
|
||||||
|
LCD_RS=1; \
|
||||||
|
LCD_DATA=c; \
|
||||||
|
LCD_E=0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
32
long_xadd.c
Normal file
32
long_xadd.c
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Add two longs in xmem zero page
|
||||||
|
*
|
||||||
|
* r0 = ptr to firts arg
|
||||||
|
* r1 = ptr to second arg
|
||||||
|
* r7 = length
|
||||||
|
*
|
||||||
|
* result is in r0*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void long_xadd() __naked
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
.globl long_xadd
|
||||||
|
.globl long_xaddc
|
||||||
|
long_xadd:
|
||||||
|
clr c
|
||||||
|
long_xaddc:
|
||||||
|
movx a,@r1
|
||||||
|
mov b,a
|
||||||
|
movx a,@r0
|
||||||
|
addc a,b
|
||||||
|
movx @r0,a
|
||||||
|
inc r0
|
||||||
|
inc r1
|
||||||
|
djnz r7,long_xaddc
|
||||||
|
ret
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
18
long_xcpy.c
Normal file
18
long_xcpy.c
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void long_xcpy() __naked
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
.globl long_xcpy
|
||||||
|
long_xcpy:
|
||||||
|
movx a,@r1
|
||||||
|
movx @r0,a
|
||||||
|
inc r0
|
||||||
|
inc r1
|
||||||
|
djnz r7,long_xcpy
|
||||||
|
ret
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
69
long_xdiv.c
Normal file
69
long_xdiv.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* r0 = numerator
|
||||||
|
* r1 = denominator
|
||||||
|
* r2 = quotient (result)
|
||||||
|
* r3 = rest
|
||||||
|
* r7 = length in bytes
|
||||||
|
*/
|
||||||
|
void long_xdiv() __naked
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
.globl long_xdiv
|
||||||
|
long_xdiv:
|
||||||
|
|
||||||
|
mov r5,AR7 ;#0x01
|
||||||
|
push AR0
|
||||||
|
mov r0,AR3
|
||||||
|
lcall long_xset_zero
|
||||||
|
pop AR0
|
||||||
|
|
||||||
|
mov r4,AR1
|
||||||
|
clr c
|
||||||
|
mov a,r0
|
||||||
|
addc a,r5 ;#DIGITS-1
|
||||||
|
mov r0,a
|
||||||
|
003$:
|
||||||
|
movx a,@r0
|
||||||
|
mov r6,#8
|
||||||
|
002$:
|
||||||
|
rlc a
|
||||||
|
push ACC
|
||||||
|
push AR0
|
||||||
|
|
||||||
|
mov r0,AR3 ;#_rest
|
||||||
|
mov r7,AR5 ;#DIGITS
|
||||||
|
lcall long_xrlc
|
||||||
|
|
||||||
|
mov r0,AR3 ;#_rest
|
||||||
|
; mov r1,#_val1
|
||||||
|
mov r7,AR5 ;#DIGITS
|
||||||
|
push AR1
|
||||||
|
lcall long_xsub
|
||||||
|
pop AR1
|
||||||
|
|
||||||
|
jnc 001$
|
||||||
|
mov r0,AR3 ;#_rest
|
||||||
|
; mov r1,#_val1
|
||||||
|
mov r7,AR5 ;#DIGITS
|
||||||
|
push AR1
|
||||||
|
lcall long_xadd
|
||||||
|
pop AR1
|
||||||
|
setb c
|
||||||
|
001$:
|
||||||
|
cpl c
|
||||||
|
mov r0,AR2 ; #_result
|
||||||
|
mov r7,AR5 ;#DIGITS
|
||||||
|
lcall long_xrlc
|
||||||
|
|
||||||
|
pop AR0
|
||||||
|
pop ACC
|
||||||
|
djnz r6,002$
|
||||||
|
djnz r0,003$
|
||||||
|
ret
|
||||||
|
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
21
long_xrlc.c
Normal file
21
long_xrlc.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void long_xrlc() __naked
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
.globl long_xrlc
|
||||||
|
|
||||||
|
long_xrlc:
|
||||||
|
movx a,@r0
|
||||||
|
rlc a
|
||||||
|
movx @r0,a
|
||||||
|
inc r0
|
||||||
|
djnz r7,long_xrlc
|
||||||
|
ret
|
||||||
|
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
17
long_xset.c
Normal file
17
long_xset.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
void long_xset() __naked
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
.globl long_xset_zero
|
||||||
|
.globl long_xset
|
||||||
|
|
||||||
|
long_xset_zero:
|
||||||
|
mov a,#0x00
|
||||||
|
long_xset:
|
||||||
|
movx @r0,a
|
||||||
|
djnz r7,long_xset
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
28
long_xsub.c
Normal file
28
long_xsub.c
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @r0=@r0-@r1
|
||||||
|
* r7=len
|
||||||
|
*/
|
||||||
|
void long_xsub() __naked
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
.globl long_xsub
|
||||||
|
.globl long_xsubb
|
||||||
|
long_xsub:
|
||||||
|
clr c
|
||||||
|
long_xsubb:
|
||||||
|
movx a,@r1
|
||||||
|
mov b,a
|
||||||
|
movx a,@r0
|
||||||
|
subb a,b
|
||||||
|
movx @r0,a
|
||||||
|
inc r0
|
||||||
|
inc r1
|
||||||
|
djnz r7,long_xsubb
|
||||||
|
ret
|
||||||
|
|
||||||
|
__endasm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
88
long_xtobcd.c
Normal file
88
long_xtobcd.c
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
|
||||||
|
/*
|
||||||
|
r0 = bin
|
||||||
|
r1 = bcd
|
||||||
|
r7 = len of bin
|
||||||
|
r6 = len of bcd
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
// double dabble
|
||||||
|
|
||||||
|
void long_xtobcd() __naked
|
||||||
|
{
|
||||||
|
__asm
|
||||||
|
.globl long_xtobcd
|
||||||
|
|
||||||
|
long_xtobcd:
|
||||||
|
|
||||||
|
; fill dst with zeroes
|
||||||
|
|
||||||
|
mov r3,AR1 ; save r1 in r3
|
||||||
|
mov r4,AR6 ; use r4 as counter
|
||||||
|
mov a,#0x00
|
||||||
|
|
||||||
|
000$:
|
||||||
|
movx @r1,a
|
||||||
|
inc r1
|
||||||
|
djnz r4,000$
|
||||||
|
|
||||||
|
mov a,r0
|
||||||
|
add a,r7
|
||||||
|
dec a
|
||||||
|
mov r0,a
|
||||||
|
mov r2,AR0 ; save r0 in r2
|
||||||
|
|
||||||
|
006$:
|
||||||
|
movx a,@r0
|
||||||
|
mov r5,#0x08
|
||||||
|
005$:
|
||||||
|
mov r4,AR6 ; use r4 as counter
|
||||||
|
mov r1,AR3
|
||||||
|
|
||||||
|
push ACC
|
||||||
|
004$:
|
||||||
|
movx a,@r1
|
||||||
|
acall 003$
|
||||||
|
acall 003$
|
||||||
|
movx @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_xrlc
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
97
mc8051fun.h
Normal file
97
mc8051fun.h
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#ifndef MC8051FUN_H
|
||||||
|
#define MC8051FUN_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <8052.h>
|
||||||
|
|
||||||
|
#define STC15XX 1 // STC15xx family
|
||||||
|
#define AT89XX 2 // AT89XX family
|
||||||
|
#define AT89XX_6T 3 // AT89C89C52 in 6T mode
|
||||||
|
|
||||||
|
|
||||||
|
void uart_send_chr(char tx_data);
|
||||||
|
void uart_send_str(const char *str);
|
||||||
|
|
||||||
|
void uart_init_(uint8_t timer_init,uint8_t x2);
|
||||||
|
|
||||||
|
#define uart_init_8051(baud,x2) \
|
||||||
|
uart_init_(256L-FOSC/12L/(baud*32L/(1<<x2)),x2)
|
||||||
|
#define uart_init_at89xx_6t_(baud,x2) \
|
||||||
|
uart_init_(256L-FOSC/12L/(baud*16L/(1<<x2)),x2)
|
||||||
|
|
||||||
|
#if MCU==AT89XX_6T
|
||||||
|
#define uart_init(baud,x2) uart_init_at89xx_6t_(baud,x2)
|
||||||
|
#else
|
||||||
|
#define uart_init(baud,x2) uart_init_8051(baud,x2)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define setbits(var,bits) (var|=bits)
|
||||||
|
#define unsetbits(var,bits) (var&=(bits^0xff))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int8_t rotary_encoder_stat(uint8_t b);
|
||||||
|
|
||||||
|
extern uint8_t sevenseg_dec[10];
|
||||||
|
extern uint8_t sevenseg_dec_inv[10];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minimum frequency is 15 Hz @ FOSC of 11 Mhz
|
||||||
|
*/
|
||||||
|
#define default_timer16_init_val(freq) ((65536L)-FOSC/12L/freq)
|
||||||
|
#define default_timer8_init_val(freq) ((256L)-FOSC/12L/freq)
|
||||||
|
|
||||||
|
#define at89xx_6t_timer16_init_val(freq) ((65536L)-FOSC/6L/freq)
|
||||||
|
#define at89xx_6t_timer8_init_val(freq) ((256L)-FOSC/6L/freq)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#if MCU==AT89XX_6T
|
||||||
|
#define timer8_init_val(freq) at89xx_6t_timer8_init_val(freq)
|
||||||
|
#define timer16_init_val(freq) at89xx_6t_timer16_init_val(freq)
|
||||||
|
#else
|
||||||
|
#define timer8_init_val(freq) default_timer8_init_val(freq)
|
||||||
|
#define timer16_init_val(freq) default_timer16_init_val(freq)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
uint16_t int_to_bcd(uint16_t i);
|
||||||
|
int getbutton(uint8_t pinval, uint8_t *button);
|
||||||
|
extern uint8_t getbutton_time;
|
||||||
|
|
||||||
|
|
||||||
|
/* a different representation of pins, which
|
||||||
|
* lets us iteratate over pins.
|
||||||
|
* But its slower, of course */
|
||||||
|
typedef struct {
|
||||||
|
uint8_t port;
|
||||||
|
uint8_t pin;
|
||||||
|
} i8051pin_T;
|
||||||
|
|
||||||
|
|
||||||
|
void setpin_hi(i8051pin_T *pin);
|
||||||
|
void setpin_lo(i8051pin_T *pin);
|
||||||
|
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
|
||||||
|
#define AR3 0x03
|
||||||
|
#define AR4 0x04
|
||||||
|
#define AR5 0x05
|
||||||
|
#define AR6 0x06
|
||||||
|
#define AR7 0x07
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
8
multest.c
Normal file
8
multest.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
uint8_t multest(uint8_t a, uint8_t b)
|
||||||
|
{
|
||||||
|
return a*b;
|
||||||
|
}
|
25
rotary_encoder_stat.c
Normal file
25
rotary_encoder_stat.c
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
|
||||||
|
static uint8_t lastb=0xff;
|
||||||
|
static uint8_t hist=0x00;
|
||||||
|
|
||||||
|
int8_t rotary_encoder_stat(uint8_t b)
|
||||||
|
{
|
||||||
|
if (b==0x00)
|
||||||
|
return 0;
|
||||||
|
if (b==lastb)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
lastb=b;
|
||||||
|
hist = (hist << 2) | b;
|
||||||
|
switch (hist){
|
||||||
|
case 0b11011011:
|
||||||
|
return 1;
|
||||||
|
case 0b11100111:
|
||||||
|
return -1;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
11
setpin.c
Normal file
11
setpin.c
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
|
||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
void setpin(i8051pin_T *pin, uint8_t val)
|
||||||
|
{
|
||||||
|
if (val)
|
||||||
|
setpin_hi(pin);
|
||||||
|
else
|
||||||
|
setpin_lo(pin);
|
||||||
|
|
||||||
|
}
|
21
setpin_hi.c
Normal file
21
setpin_hi.c
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
|
||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
void setpin_hi(i8051pin_T *pin)
|
||||||
|
{
|
||||||
|
switch(pin->port){
|
||||||
|
case 0:
|
||||||
|
P0 |= (1<<pin->pin);
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
P1 |= (1<<pin->pin);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
P2 |= (1<<pin->pin);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
P3 |= (1<<pin->pin);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
20
setpin_lo.c
Normal file
20
setpin_lo.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
void setpin_lo(i8051pin_T *pin)
|
||||||
|
{
|
||||||
|
switch(pin->port){
|
||||||
|
case 0:
|
||||||
|
P0 &= (1<<pin->pin) ^ 0xFF;
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
P1 &= (1<<pin->pin) ^ 0xFF;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
P2 &= (1<<pin->pin) ^ 0xFF;
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
P3 &= (1<<pin->pin) ^ 0xFF;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
14
sevenseg_dec.c
Normal file
14
sevenseg_dec.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
uint8_t sevenseg_dec[10] = {
|
||||||
|
0b11111100,
|
||||||
|
0b01100000,
|
||||||
|
0b11011010,
|
||||||
|
0b11110010,
|
||||||
|
0b01100110,
|
||||||
|
0b10110110,
|
||||||
|
0b10111110,
|
||||||
|
0b11100000,
|
||||||
|
0b11111110,
|
||||||
|
0b11110110
|
||||||
|
};
|
14
sevenseg_dec_inv.c
Normal file
14
sevenseg_dec_inv.c
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
uint8_t sevenseg_dec_inv[10] = {
|
||||||
|
0b00000011,
|
||||||
|
0b10011111,
|
||||||
|
0b00100101,
|
||||||
|
0b00001101,
|
||||||
|
0b10011001,
|
||||||
|
0b01001001,
|
||||||
|
0b01000001,
|
||||||
|
0b00011111,
|
||||||
|
0b00000001,
|
||||||
|
0b00001001
|
||||||
|
};
|
23
uart_init_.c
Normal file
23
uart_init_.c
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
#include <at89c51ed2.h>
|
||||||
|
|
||||||
|
|
||||||
|
void uart_init_(uint8_t timer_init,uint8_t x2)
|
||||||
|
{
|
||||||
|
TMOD |= 0x20; // Timer 1 in Mode 2
|
||||||
|
TH1 = timer_init;
|
||||||
|
TL1 = timer_init;
|
||||||
|
TR1 = 1; // Start Timer 1
|
||||||
|
SCON = 0x50; // 8-bit data, 1 stop bit, REN enabled
|
||||||
|
|
||||||
|
if(x2)
|
||||||
|
setbits(PCON,SMOD);
|
||||||
|
else
|
||||||
|
unsetbits(PCON,SMOD);
|
||||||
|
|
||||||
|
return;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
10
uart_send_chr.c
Normal file
10
uart_send_chr.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
|
||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
void uart_send_chr(char tx_data)
|
||||||
|
{
|
||||||
|
TI = 0; /* Clear TI flag */
|
||||||
|
SBUF = tx_data; /* Load char in SBUF register */
|
||||||
|
while (TI==0); /* Wait until stop bit transmit */
|
||||||
|
}
|
||||||
|
|
8
uart_send_str.c
Normal file
8
uart_send_str.c
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
#include "mc8051fun.h"
|
||||||
|
|
||||||
|
void uart_send_str(const char *str)
|
||||||
|
{
|
||||||
|
while(*str)
|
||||||
|
uart_send_chr(*str++);
|
||||||
|
}
|
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