diff --git a/Makefile b/Makefile index 7d0d67f..fd352ff 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,8 @@ 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 + int_to_bcd.c getbutton.c \ + getpin.c setpin_lo.c setpin_hi.c setpin.c LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC)) LIBNAME=mc8051fun.lib diff --git a/getpin.c b/getpin.c new file mode 100644 index 0000000..40f3275 --- /dev/null +++ b/getpin.c @@ -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; +} diff --git a/mc8051fun.h b/mc8051fun.h index 857a1aa..7338716 100644 --- a/mc8051fun.h +++ b/mc8051fun.h @@ -62,6 +62,16 @@ typedef struct { } 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); + + + + + + diff --git a/setpin.c b/setpin.c new file mode 100644 index 0000000..1bd49e4 --- /dev/null +++ b/setpin.c @@ -0,0 +1,11 @@ + +#include "mc8051fun.h" + +void setpin(i8051pin_T *pin, uint8_t val) +{ + if (val) + setpin_hi(pin); + else + setpin_lo(pin); + +} diff --git a/setpin_hi.c b/setpin_hi.c new file mode 100644 index 0000000..5a973c7 --- /dev/null +++ b/setpin_hi.c @@ -0,0 +1,21 @@ + +#include "mc8051fun.h" + +void setpin_hi(i8051pin_T *pin) +{ + switch(pin->port){ + case 0: + P0 |= (1<pin); + break; + case 1: + P1 |= (1<pin); + break; + case 2: + P2 |= (1<pin); + break; + case 3: + P3 |= (1<pin); + break; + } +} + diff --git a/setpin_lo.c b/setpin_lo.c new file mode 100644 index 0000000..dd39ce0 --- /dev/null +++ b/setpin_lo.c @@ -0,0 +1,20 @@ +#include "mc8051fun.h" + +void setpin_lo(i8051pin_T *pin) +{ + switch(pin->port){ + case 0: + P0 &= (1<pin) ^ 0xFF; + break; + case 1: + P1 &= (1<pin) ^ 0xFF; + break; + case 2: + P2 &= (1<pin) ^ 0xFF; + break; + case 3: + P3 &= (1<pin) ^ 0xFF; + break; + } +} +