ВходНаше всё Теги codebook 无线电组件 Поиск Опросы Закон Пятница
26 апреля
610254 Топик полностью
VL (21.07.2015 08:03, просмотров: 1) ответил Dingo на Макросы интересные => . Да, не по канонам, но удобно, чёрт побери!
"Дикий народ, дети гор". Еще так можно // Описание портов // name port bit OUTPUT ( PulseWdt , P1 , 0x01u ) OUTPUT ( Backlight , P1 , 0x02u ) OUTPUT ( EmptyError , P1 , 0x04u ) // external error indication INPUT ( EmptyErrorIn , P1 , 0x04u ) OUTPUT ( IrdaTx , P1 , 0x08u ) INPUT ( KeyStIn , ~P1 , 0x10u ) INPUT ( StFreeIn , P1 , 0x10u ) INPUT ( KeyDnIn , ~P1 , 0x20u ) INPUT ( KeyFnIn , ~P1 , 0x40u ) INPUT ( KeyUpIn , ~P1 , 0x80u ) INPUT ( KbdIn , ~P1 , 0xf0u ) INPUT ( FnFreeIn , P1 , 0x40u ) INPUT ( SdaIn , P2 , 0x01u ) OUTPUT ( Sda , P2 , 0x01u ) INPUT ( SclIn , P2 , 0x02u ) OUTPUT ( Scl , P2 , 0x02u ) OUTPUT ( OtherError , P2 , 0x04u ) // external error indication INPUT ( OtherErrorIn , P2 , 0x04u ) OUTPUT ( P2_3 , P2 , 0x08u ) OUTPUT ( PumpB , P2 , 0x10u ) OUTPUT ( P2_5 , P2 , 0x20u ) OUTPUT ( PumpA , P2 , 0x40u ) INPUT ( IrdaRxIn , P2 , 0x80u ) OUTPUT ( P3_0 , P3 , 0x01u ) OUTPUT ( P3_1 , P3 , 0x02u ) OUTPUT ( IrdaSc , P3 , 0x04u ) OUTPUT ( P3_3 , P3 , 0x08u ) OUTPUT ( TxD0 , P3 , 0x10u ) INPUT ( RxD0 , P3 , 0x20u ) OUTPUT ( TxD1 , P3 , 0x40u ) INPUT ( RxD1 , P3 , 0x80u ) INPUT ( Conc2CounterIn , P4 , 0x01u ) INPUT ( ConcCounterIn , P4 , 0x02u ) INPUT ( CountersIn , P4 , 0x03u ) OUTPUT ( Valve , P4 , 0x04u ) OUTPUT ( Ac , P4 , 0x08u ) OUTPUT ( Ac2 , P4 , 0x10u ) OUTPUT ( Sound , P4 , 0x20u ) INPUT ( ExternalHornIn , P4 , 0x40u ) // external horn OUTPUT ( ExternalHorn , P4 , 0x40u ) OUTPUT ( ErrorLed , P4 , 0x80u ) INPUT ( ErrorLedIn , P4 , 0x80u ) INPUT ( Log1In , P5 , 0x01u ) INPUT ( Log2In , P5 , 0x02u ) OUTPUT ( TxDir , P5 , 0x04u ) OUTPUT ( LcdSi , P5 , 0x08u ) OUTPUT ( LcdClk , P5 , 0x10u ) OUTPUT ( LcdCsb , P5 , 0x20u ) OUTPUT ( LcdRs , P5 , 0x40u ) OUTPUT ( LcdReset , P5 , 0x80u ) ADC ( TankFullAdc , ADC12MEM0 , 0x01u ) ADC ( TankEmptyAdc , ADC12MEM1 , 0x02u ) ADC ( CanAdc , ADC12MEM2 , 0x04u ) ADC ( Can2Adc , ADC12MEM3 , 0x08u ) ADC ( A4Adc , (ADC12MEM4>>1), 0x10u ) ADC ( LeakageAdc , ADC12MEM5 , 0x20u ) ADC ( PowerAdc , ADC12MEM6 , 0x40u ) ADC ( A7Adc , ADC12MEM7 , 0x80u ) // port direction start value selection #ifndef WDT_OFF PORT ( P1 , mPulseWdt | mBacklight | mEmptyError | mIrdaTx , 0 , mIrdaTx ) #else PORT ( P1 , mBacklight | mEmptyError | mIrdaTx , 0 , mIrdaTx ) #endif PORT ( P2 , mScl|mOtherError|mP2_3|mPumpB|mP2_5|mPumpA , 0 , 0 ) PORT ( P3 , mP3_0|mP3_1|mIrdaSc|mP3_3|mTxD0|mTxD1 , mTxD0|mTxD1 , mTxD0|mRxD0|mTxD1|mRxD1 ) PORT ( P4 , mValve|mAc|mAc2|mSound| mExternalHorn|mErrorLed , 0 , mAc |mAc2 ) PORT ( P5 , 0xff , 0 , 0 ) PORT ( P6 , 0 , 0 , mTankFullAdc|mTankEmptyAdc|mCanAdc|mCan2Adc|mA4Adc|mLeakageAdc|mPowerAdc|mA7Adc ) //PORT ( P1 , mPulseWdt | mBacklight | mEmptyError | mIrdaTx , 0 , mIrdaTx ) //PORT ( P2 , mScl | mOtherError | mCloseCC | mPumpB | mCloseWC | mPumpA , 0 , 0 ) //PORT ( P3 , mCloseUp | mIrdaSc | mTxD0 | mTxD1 , mTxD0 | mTxD1 , mTxD0 | mRxD0In | mTxD1 | mRxD1In ) //PORT ( P4 , mCloseDn | mValve | mAc | mSound | mChemLed | mWaterLed , 0 , mAc ) //PORT ( P5 , 0xff , 0 , 0 ) //PORT ( P6 , 0 , 0 , mOutputAdc|mInputAdc|mCanAdc|mFlowAdc|mLeakageAdc|mPowerAdc ) FUNCTION ( IrdaTxFunction , P1SEL, mIrdaTx ) FUNCTION ( IrdaRxInterrupt , P2IE, mIrdaRxIn ) FUNCTION ( ValvePWM , P4SEL, mValve ) FUNCTION ( SdaLow , P2DIR, mSda ) FUNCTION ( SclLow , P2DIR, mScl ) // конец файла описания портов #pragma inline=forced unsigned char GetPin(unsigned int name); #pragma inline=forced void OnPin(unsigned int name); #pragma inline=forced void OffPin(unsigned int name); #pragma inline=forced void TogglePin(unsigned int name); #pragma inline=forced void OnFunction(unsigned int name); #pragma inline=forced void OffFunction(unsigned int name); #pragma inline=forced unsigned int GetAdc(unsigned int name); #pragma inline=forced void PortsConfiguration(void); #include "msp430x14x.h" #include "k_def.h" #include "k_typedef.h" #include "k_areas.h" enum { // enumeration of pin signals #define INPUT( name, port, bit) name, #define OUTPUT(name, port, bit) name, #define ADC(name, memory, bit) name, #define FUNCTION(function_name, port, bit_name ) function_name, #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT }; // generation of port bits masks #define INPUT( name, port, bit) enum { m##name=bit}; #define OUTPUT(name, port, bit) enum { m##name=bit}; #define ADC(name, memory, bit) enum { m##name=bit}; #define FUNCTION(function_name, port, bit_name ) #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT // generation of inputs functions unsigned char GetPin( unsigned int name) { switch (name) { #define INPUT( name, port, bit) case name: return (port##IN & bit); #define OUTPUT(name, port, bit) #define ADC(name, memory, bit) #define FUNCTION(function_name, port, bit_name ) #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT default: return 0; } } // generation of ON output and ON function void OnPin( unsigned int name) { switch (name) { #define INPUT( name, port, bit) #define OUTPUT(name, port, bit) case name: port##OUT|=bit; return; #define ADC(name, memory, bit) #define FUNCTION(function_name, port, bit_name ) #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT }} // generation of OFF output functions void OffPin( unsigned int name) { switch (name) { #define INPUT( name, port, bit) #define OUTPUT(name, port, bit) case name: port##OUT&=~bit; return; #define ADC(name, memory, bit) #define FUNCTION(function_name, port, bit_name ) #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT }} // generation of TOGGLE output functions void TogglePin( unsigned int name) { switch (name) { #define INPUT( name, port, bit) #define OUTPUT(name, port, bit) case name: port##OUT^=bit; return; #define ADC(name, memory, bit) #define FUNCTION(function_name, port, bit_name ) #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT }} // generation of Get ADC functions unsigned int GetAdc( unsigned int name) { switch (name) { #define INPUT( name, port, bit) #define OUTPUT(name, port, bit) #define ADC(name, memory, bit) case name: return (memory); #define FUNCTION(function_name, port, bit_name ) #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT default: return 0; }} // generation of ON function void OnFunction(unsigned int name) { switch (name) { #define INPUT( name, port, bit) #define OUTPUT(name, port, bit) #define ADC(name, memory, bit) #define FUNCTION(function_name, port, bit_name ) case function_name: port|=bit_name; return; #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT }} // generation of OFF function void OffFunction(unsigned int name) { switch (name) { #define INPUT( name, port, bit) #define OUTPUT(name, port, bit) #define ADC(name, memory, bit) #define FUNCTION(function_name, port, bit_name ) case function_name: port&=~bit_name; return; #define PORT(port, direction, start_value, selection) #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT }} // generation of Port Configuration void PortsConfiguration(void) { // start values #define INPUT( name, port, bit) #define OUTPUT(name, port, bit) #define ADC(name, memory, bit) #define FUNCTION(function_name, port, bit_name ) #define PORT(port, direction, start_value, selection) port##OUT=start_value; #include PINS_HEADER #undef PORT // start values #define PORT(port, direction, start_value, selection) port##DIR=direction; #include PINS_HEADER #undef PORT // function selection #define PORT(port, direction, start_value, selection) port##SEL=selection; #include PINS_HEADER #undef INPUT #undef OUTPUT #undef ADC #undef FUNCTION #undef PORT } #endif // file // пример установки бита OnPin(LcdRs);