공부/C언어
25. 구조체_구조체 함수_구조체 포인트
유저라인
2019. 7. 26. 10:59
728x90
반응형
main.c
#include "head.h"
#include "sub1_head.h"
static TS_DrvTypeDef *TsDrv;
void main(void)
{
if (stmpe811_ts_drv.ReadID(0x0811) == 0x0811) {
TsDrv = &stmpe811_ts_drv;
}
TsDrv->Init(0x0811);
}
sub1.c
#include "sub1_head.h"
TS_DrvTypeDef stmpe811_ts_drv =
{
stmpe811_Init,
stmpe811_ReadID,
};
void stmpe811_Init(int DeviceAddr) {
printf("Device_addr=0x%x\r\n", DeviceAddr);
}
int stmpe811_ReadID(int DeviceAddr) {
printf("Read_ID=0x%x\r\n", DeviceAddr);
return (DeviceAddr);
}
head.h
#include <stdio.h>
ts.h
#include <stdio.h>
typedef struct
{
void(*Init)(int);
int(*ReadID)(int);
}TS_DrvTypeDef;
sub1_head.h
#include "ts.h"
void stmpe811_Init(int DeviceAddr);
int stmpe811_ReadID(int DeviceAddr);
extern TS_DrvTypeDef stmpe811_ts_drv;
결과 화면
728x90
반응형