Ich habe ein Problem über "Stroage Größe eines ist nicht bekannt". Ich habe den Stackoverflow überprüft und einige Antworten gefunden. Aber diese Lösungen haben nicht funktioniert oder ich konnte diese Antworten nicht sehr gut verwenden.stroage Größe von 'Variable' ist nicht bekannt
Bitte helfen Sie mir, mein Problem zu lösen. Danke für Ihre Hilfe und einen schönen Tag.
main.c Datei
#include <avr/io.h>
#include <PORT.h>
int main(void)
{
// Insert code
PORT a;
while(1)
;
return 0;
}
PORT.h Datei
#ifndef PORT_H_INCLUDED
#define PORT_H_INCLUDED
#include <config.h>
typedef enum PORT_TYPE{
// All port in ATmega328P
PORT_B,
PORT_C,
PORT_D
}PORT_TYPE;
typedef enum PORT_PIN{
// All pins in ATmega328P
PIN_0,
PIN_1,
PIN_2,
PIN_3,
PIN_4,
PIN_5,
PIN_6,
PIN_7
}PORT_PIN;
typedef struct PORT PORT;
void PORT_init(PORT * const me,
void (* setDirectionFunction)(PORT * const me, PORT_PIN pinNumber),
void (* setStatusFunction)(PORT * const me, PORT_PIN pinNumber),
void (* enablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* disablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* notifyPinChangeFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPINFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPortFunction)(PORT * const me));
void PORT_setDirection(PORT * const me, PORT_PIN pinNumber);
void PORT_setStatus(PORT * const me, PORT_PIN pinNumber);
void PORT_enablePullResistor(PORT * const me, PORT_PIN pinNumber);
void PORT_disablePullResistor(PORT * const me, PORT_PIN pinNumber);
void PORT_notifyPinChange(PORT * const me, PORT_PIN pinNumber);
unsigned char PORT_readPIN(PORT * const me, PORT_PIN pinNumber);
unsigned char PORT_readPort(PORT * const me);
PORT * PORT_create(PORT_TYPE whichPort);
void PORT_destroy(PORT * const me);
#endif // PORT_H_INCLUDED
PORT.c Datei
#include <avr/io.h>
#include <PORT.h>
#define ADDR_PORTB (0x0023)
#define ADDR_PORTC (0x0026)
#define ADDR_PORTD (0x0029)
typedef volatile struct{
// it is used for manipulating registers.
unsigned char pin;
unsigned char ddr;
unsigned char port;
}PORT_hw;
struct PORT{
unsigned char changePIN;
PORT_hw volatile *p_hw;
void (* setDirection)(PORT * const me, PORT_PIN pinNumber);
void (* setStatus)(PORT * const me, PORT_PIN pinNumber);
void (* enablePullResistor)(PORT * const me, PORT_PIN pinNumber);
void (* disablePullResistor)(PORT * const me, PORT_PIN pinNumber);
void (* notifyPinChange)(PORT * const me, PORT_PIN pinNumber);
unsigned char (*readPIN)(PORT * const me, PORT_PIN pinNumber);
unsigned char (*readPort)(PORT * const me);
};
static PORT g_PORT[3];
g_PORT[0].p_hw = (PORT_hw volatile *)ADDR_PORTB;
g_PORT[1].p_hw = (PORT_hw volatile *)ADDR_PORTC;
g_PORT[2].p_hw = (PORT_hw volatile *)ADDR_PORTD;
void PORT_init(PORT * const me,
void (* setDirectionFunction)(PORT * const me, PORT_PIN pinNumber),
void (* setStatusFunction)(PORT * const me, PORT_PIN pinNumber),
void (* enablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* disablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* notifyPinChangeFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPINFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPortFunction)(PORT * const me)){
me->changePIN = 0x00;
me->pinStatus = 0x00;
me->setDirection = setDirectionFunction;
me->setStatus = setStatusFunction;
me->enablePullResistor = enablePullResistorFunction;
me->disablePullResistor = disablePullResistorFunction;
me->notifyPinChange = notifyPinChangeFunction;
me->readPIN = readPINFunction;
me->readPort = readPortFunction;
}
void PORT_setDirection(PORT * const me, PORT_PIN pinNumber){}
void PORT_setStatus(PORT * const me, PORT_PIN pinNumber){}
void PORT_enablePullResistor(PORT * const me, PORT_PIN pinNumber){}
void PORT_disablePullResistor(PORT * const me, PORT_PIN pinNumber){}
void PORT_notifyPinChange(PORT * const me, PORT_PIN pinNumber){}
unsigned char PORT_readPIN(PORT * const me, PORT_PIN pinNumber){}
unsigned char PORT_readPort(PORT * const me){}
PORT * PORT_create(PORT_TYPE whichPort){
PORT *p_PORT = &(g_PORT[whichPort]);
PORT_init(p_PORT, PORT_setDirection, PORT_setStatus, PORT_enablePullResistor, PORT_disablePullResistor, PORT_notifyPinChange, PORT_readPIN, PORT_readPort);
return p_PORT;
}
void PORT_destroy(PORT * const me){}