Hi Folks,
It has been some time since I been around on these forums and recently just started coding again for the AVRs. I making a small HVAC controller to use at work, it's basically pushbuttons to control functions of a HVAC. I used some of my old coding from another project which was never put in use. From what I can recalled, the coding worked great. I basically trying to make better. I used CPUSHBUTTON_CONTROL for each LED/Button and another called CPUSHBUTTON_UI in a set, the UI mainly controls the LED/Buttons. Here's a updated version of the CONTROL Class.
#include "CPUSHBUTTON_CONTROL.h" typedef struct { volatile uint8_t* PORT; volatile uint8_t* DDR; volatile uint8_t MASK; volatile uint8_t* PIN; } sPORT_INFO; class CPUSHBUTTON_CONTROL { private: volatile sPORT_INFO mSW_PRIMARY_LED; volatile sPORT_INFO mSW_SECONDARY_LED; volatile sPORT_INFO mSW; volatile sPORT_INFO mPOWER_RELAY; /*volatile uint8_t* mSW_PRIMARY_LED_PORT; volatile uint8_t* mSW_PRIMARY_LED_DDR; volatile uint8_t mSW_PRIMARY_LED_MASK; volatile uint8_t* mSW_PRIMARY_LED_PIN; volatile uint8_t* mSW_SECONDARY_LED_PORT; volatile uint8_t* mSW_SECONDARY_LED_DDR; volatile uint8_t mSW_SECONDARY_LED_MASK; volatile uint8_t* mSW_SECONDARY_LED_PIN; volatile uint8_t* mSW_PORT; volatile uint8_t* mSW_DDR; volatile uint8_t mSW_MASK; volatile uint8_t* mSW_PIN; volatile uint8_t* mPOWER_RELAY_PORT; volatile uint8_t* mPOWER_RELAY_DDR; volatile uint8_t mPOWER_RELAY_MASK; volatile uint8_t* mPOWER_RELAY_PIN;*/ public: CPUSHBUTTON_CONTROL(); void SETUP_SW_PRIMARY_LED(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN); void SETUP_SW_SECONDARY_LED(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN); void SETUP_SW(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN); void SETUP_POWER_RELAY(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN); void INIT(); int READ_SW(uint8_t auto_reset_function = YES); }; CPUSHBUTTON_CONTROL::CPUSHBUTTON_CONTROL() { } void CPUSHBUTTON_CONTROL::SETUP_SW_PRIMARY_LED(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN) { this->mSW_PRIMARY_LED.PORT = PORT; this->mSW_PRIMARY_LED.DDR = DDR; this->mSW_PRIMARY_LED.MASK = MASK; this->mSW_PRIMARY_LED.PIN = PIN; /*this->mSW_PRIMARY_LED_PORT = PORT; this->mSW_PRIMARY_LED_DDR = DDR; this->mSW_PRIMARY_LED_MASK = MASK; this->mSW_PRIMARY_LED_PIN = PIN;*/ } void CPUSHBUTTON_CONTROL::SETUP_SW_SECONDARY_LED(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN) { this->mSW_SECONDARY_LED.PORT = PORT; this->mSW_SECONDARY_LED.DDR = DDR; this->mSW_SECONDARY_LED.MASK = MASK; this->mSW_SECONDARY_LED.PIN = PIN; /*this->mSW_SECONDARY_LED_PORT = PORT; this->mSW_SECONDARY_LED_DDR = DDR; this->mSW_SECONDARY_LED_MASK = MASK; this->mSW_SECONDARY_LED_PIN = PIN;*/ } void CPUSHBUTTON_CONTROL::SETUP_SW(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN) { this->mSW.PORT = PORT; this->mSW.DDR = DDR; this->mSW.MASK = MASK; this->mSW.PIN = PIN; /*this->mSW_PORT = PORT; this->mSW_DDR = DDR; this->mSW_MASK = MASK; this->mSW_PIN = PIN;*/ } void CPUSHBUTTON_CONTROL::SETUP_POWER_RELAY(volatile uint8_t* PORT, volatile uint8_t* DDR, volatile uint8_t MASK, volatile uint8_t* PIN) { this->mPOWER_RELAY.PORT = PORT; this->mPOWER_RELAY.DDR = DDR; this->mPOWER_RELAY.MASK = MASK; this->mPOWER_RELAY.PIN = PIN; /*this->mPOWER_RELAY_PORT = PORT; this->mPOWER_RELAY_DDR = DDR; this->mPOWER_RELAY_MASK = MASK; this->mPOWER_RELAY_PIN = PIN;*/ } void CPUSHBUTTON_CONTROL::INIT() { //Let Make Sure Our Pullup Is Turn Off *this->mSW.PORT &= ~(this->mSW.MASK); //Set Our Pushbutton To Input *this->mSW.DDR &= ~(this->mSW.MASK); //Let Make Sure Our Primary LED is Turn Off *this->mSW_PRIMARY_LED.PORT &= ~(this->mSW_PRIMARY_LED.MASK); //Set Our Primary LED To Output *this->mSW_PRIMARY_LED.DDR |= (this->mSW_PRIMARY_LED.MASK); //Let Make Sure Our Secondary LED is Turn Off *this->mSW_SECONDARY_LED.PORT &= ~(this->mSW_SECONDARY_LED.MASK); //Set Our Secondary LED To Output *this->mSW_SECONDARY_LED.DDR |= (this->mSW_SECONDARY_LED.MASK); //Let Make Sure Our Power Relay Is Turn Off *this->mPOWER_RELAY.PORT &= ~(this->mPOWER_RELAY.MASK); //Set Our Power Relay To Output *this->mPOWER_RELAY.DDR |= (this->mPOWER_RELAY.MASK); } int CPUSHBUTTON_CONTROL::READ_SW(uint8_t auto_reset_function) { }
As you can see, I updated the PORT info into a struct and this one has dual color LEDs, the old one didn't. As you can see SW, LEDs, Power Relay has the same struct. I wanted a way to use one setup function to setup each LEDs, SW, Relays without having four functions to setup each one. Trying to find ways to reduce the program size. Anyone has any tips?
PS: What is the different between .hex and .elf files? I noticed that the .hex is smaller than the .elf. .elf is becoming big. Which file are you suppose to use when uploading into a AVR?