2024-05-17 23:51:40 +02:00
|
|
|
#ifndef MC8051FUN_H
|
|
|
|
#define MC8051FUN_H
|
|
|
|
|
2024-05-19 01:00:51 +02:00
|
|
|
#include <stdint.h>
|
2024-05-17 23:51:40 +02:00
|
|
|
#include <8052.h>
|
|
|
|
|
2024-05-30 19:24:40 +02:00
|
|
|
#define STC15XX 1 // STC15xx family
|
|
|
|
#define AT89XX 2 // AT89XX family
|
|
|
|
#define AT89XX_6T 3 // AT89C89C52 in 6T mode
|
2024-05-18 02:14:50 +02:00
|
|
|
|
2024-05-19 01:00:51 +02:00
|
|
|
|
2024-05-18 02:14:50 +02:00
|
|
|
void uart_send_chr(char tx_data);
|
|
|
|
void uart_send_str(const char *str);
|
|
|
|
|
2024-05-25 19:15:01 +02:00
|
|
|
void uart_init_(uint8_t timer_init,uint8_t x2);
|
|
|
|
|
2024-05-30 19:24:40 +02:00
|
|
|
#define uart_init_8051(baud,x2) \
|
|
|
|
uart_init_(256L-FOSC/12L/(baud*32L/(1<<x2)),x2)
|
|
|
|
#define uart_init_at89xx_6t_(baud,x2) \
|
2024-05-25 19:15:01 +02:00
|
|
|
uart_init_(256L-FOSC/12L/(baud*16L/(1<<x2)),x2)
|
|
|
|
|
2024-05-30 19:24:40 +02:00
|
|
|
#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
|
2024-05-25 19:15:01 +02:00
|
|
|
|
|
|
|
#define setbits(var,bits) (var|=bits)
|
|
|
|
#define unsetbits(var,bits) (var&=(bits^0xff))
|
|
|
|
|
|
|
|
|
2024-05-19 01:00:51 +02:00
|
|
|
|
|
|
|
int8_t rotary_encoder_stat(uint8_t b);
|
|
|
|
|
|
|
|
extern uint8_t sevenseg_dec[10];
|
|
|
|
extern uint8_t sevenseg_dec_inv[10];
|
|
|
|
|
2024-05-23 22:48:41 +02:00
|
|
|
/**
|
|
|
|
* 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
|
2024-05-19 21:02:33 +02:00
|
|
|
|
|
|
|
|
|
|
|
uint16_t int_to_bcd(uint16_t i);
|
2024-05-23 22:48:41 +02:00
|
|
|
int getbutton(uint8_t pinval, uint8_t *button);
|
|
|
|
extern uint8_t getbutton_time;
|
|
|
|
|
|
|
|
|
2024-05-25 19:15:01 +02:00
|
|
|
/* 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;
|
|
|
|
|
|
|
|
|
2024-05-25 19:52:43 +02:00
|
|
|
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);
|
2024-05-26 15:33:06 +02:00
|
|
|
uint8_t getport(int n);
|
2024-05-25 19:52:43 +02:00
|
|
|
|
2024-06-05 08:20:17 +02:00
|
|
|
#define AR0 0x00
|
|
|
|
#define AR1 0x01
|
|
|
|
#define AR2 0x02
|
|
|
|
#define AR3 0x03
|
|
|
|
#define AR4 0x04
|
|
|
|
#define AR5 0x05
|
|
|
|
#define AR6 0x06
|
|
|
|
#define AR7 0x07
|
2024-05-25 19:52:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2024-06-13 22:07:19 +02:00
|
|
|
uint8_t multest(uint8_t a, uint8_t b);
|
2024-05-25 19:15:01 +02:00
|
|
|
|
2024-07-01 22:31:49 +02:00
|
|
|
void bcd_tolong(__idata uint8_t *bcdval, __idata uint8_t *binval, uint8_t bcdlen, uint8_t binlen) __reentrant;
|
2024-07-03 06:54:47 +02:00
|
|
|
void long_invert(__idata uint8_t *val, uint8_t len) __reentrant;
|
2024-07-03 07:06:33 +02:00
|
|
|
uint8_t long_add(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len) __reentrant;
|
2024-07-14 23:43:05 +02:00
|
|
|
uint8_t long_mul(__idata uint8_t *v1, __idata uint8_t *v2,uint8_t len, __idata uint8_t *result) __reentrant;
|
2024-05-25 19:15:01 +02:00
|
|
|
|
2024-05-19 21:02:33 +02:00
|
|
|
|
2024-05-17 23:51:40 +02:00
|
|
|
#endif
|