96 lines
2.2 KiB
C
96 lines
2.2 KiB
C
#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;
|
|
|
|
|
|
#endif
|