getpin and setpin functions added
This commit is contained in:
parent
151891240d
commit
64210a94ec
3
Makefile
3
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
|
||||
|
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;
|
||||
}
|
10
mc8051fun.h
10
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);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user