getpin and setpin functions added

This commit is contained in:
7u83 2024-05-25 19:52:43 +02:00
parent 151891240d
commit 64210a94ec
6 changed files with 82 additions and 1 deletions

View File

@ -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 \ LIBSRC = uart_init_.c uart_send_chr.c uart_send_str.c \
rotary_encoder_stat.c \ rotary_encoder_stat.c \
sevenseg_dec.c sevenseg_dec_inv.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)) LIBOBJ =$(patsubst %.c,%.rel, $(LIBSRC))
LIBNAME=mc8051fun.lib LIBNAME=mc8051fun.lib

18
getpin.c Normal file
View 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;
}

View File

@ -62,6 +62,16 @@ typedef struct {
} i8051pin_T; } 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);

11
setpin.c Normal file
View 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
View 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
View 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;
}
}