Compare commits
20 Commits
5c00e1633a
...
30f410891c
Author | SHA1 | Date | |
---|---|---|---|
30f410891c | |||
b9a4e2b393 | |||
64210a94ec | |||
151891240d | |||
a2a9256061 | |||
18c6fc5220 | |||
815d9c94ba | |||
7cc46801fb | |||
696ccc30ab | |||
ff95ee6537 | |||
5457e799f5 | |||
384dbcd807 | |||
719e10974f | |||
c73d714dae | |||
d7cd9b8d4d | |||
1dfac0074b | |||
28a6ccc3ee | |||
6ca5f28555 | |||
08477b5f83 | |||
726a76eeff |
55
Makefile
Normal file
55
Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
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
|
||||
|
||||
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
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;
|
||||
}
|
79
mc8051fun.h
Normal file
79
mc8051fun.h
Normal file
@ -0,0 +1,79 @@
|
||||
#ifndef MC8051FUN_H
|
||||
#define MC8051FUN_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <8052.h>
|
||||
|
||||
|
||||
|
||||
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(baud,x2) \
|
||||
uart_init_(256L-FOSC/12L/(baud*16L/(1<<x2)),x2)
|
||||
|
||||
|
||||
#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)
|
||||
|
||||
|
||||
#define STC15XX 1 // STC15xx family
|
||||
#define AT89XX 2 // AT89XX family
|
||||
#define AT89XX_6T 3 // AT89C89C52 in 6T mode
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
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++);
|
||||
}
|
Reference in New Issue
Block a user