MyTetra Share
Делитесь знаниями!
definitions.h
Время создания: 30.11.2017 14:56
Раздел: Electronics - Microcontrollers - AVR8 - AVR GCC - C_PROJ - Clock 7sgm (red) - ver.2

#ifndef __DEFINITIONS_H__

#define __DEFINITIONS_H__


#define NOP asm volatile("NOP"::) //NOP

#define SEI asm volatile("sei"::) //enable interrupts

#define CLI asm volatile("cli"::) //disable interrupts


#define SEGM_DDR DDRC

#define SEGM PORTC //PC1..PC4 - 1..4 segment cathodes

#define CATHODE_MASK 0xE1 //1110.0001 - mask for turning off pins [1..4]

#define SEC_DOTS 0x80 //'mask' for switching on central dots on indicator panel

#define SEGM1_ON SEGM |= (1<<1) //PORTC 1

#define SEGM2_ON SEGM |= (1<<2) //PORTC 2

#define SEGM3_ON SEGM |= (1<<3) //PORTC 3

#define SEGM4_ON SEGM |= (1<<4) //PORTC 4

#define SEGM_OFF SEGM &= CATHODE_MASK

//#define SEGM_DDR_OFF SEGM_DDR &= CATHODE_MASK


#define HC595 PORTB

#define DS 0 //data

#define ST 2 //locking

#define SH 1 //clock

#define DATA_HI HC595 |= (1<<DS)

#define DATA_LOW HC595 &= ~(1<<DS)

#define CLK_HI HC595 |= (1<<SH)

#define CLK_LOW HC595 &= ~(1<<SH)

#define LOCK_HI HC595 |= (1<<ST)

#define LOCK_LOW HC595 &= ~(1<<ST)

#define CLEAR_OFF PORTD |= (1<<MR)

#define CLEAR_ON PORTD &= ~(1<<MR)


//PORTD

#define MR 7 //for 74HC595

#define BUTT1 6 //PORTD6 - button #1 //change for pin2 and do interrupt INT0

#define BUTT2 5 //PORTD5 - button #2

#define BUTT3 4 //PORTD4 - button #3 //change for pin6

#define BUTT_MASK 0x70 //0111.0000 //change it after making INT0 interrupt

#define BUTTONS_STATE ((PIND) & (BUTT_MASK))

//BUTTONS_MASK

// 0111.0000

// |||button_3

// ||button_2

// |button_1

// MR (74HC595)


//for indicator with common cathode

//D0..D7 == A,B,C,D,F,G,DP

#define DIG1 0x06;

#define DIG2 0x5B;

#define DIG3 0x4F;

#define DIG4 0x66;

#define DIG5 0x6D;

#define DIG6 0x7D;

#define DIG7 0x07;

#define DIG8 0x7F;

#define DIG9 0x6F;

#define DIG0 0x3F;

#if 0

#define SYM_SPACE 0x08;

#define SYM_o 0x5C;

#define SYM_n 0x54;

#define SYM_f 0x71;

#endif


#define CHECKBIT(BYTE,BIT) (BYTE & (1<<BIT)) //check bit setting

#define INVERTBIT(BYTE,BIT) (BYTE ^= (1<<BIT)) //invert first bit

//#define CHECKBUTTS(BYTE) (BYTE = PIND & BUTT_MASK)


//configuration modes:

#define MOFF 0 //cfg mode turned off (default)

#define MHOUR_H 1 //changing 1st hour digit

#define MHOUR_L 2 //changing 2nd hour digit

#define MMINUTE_H 3 //changing 1st minute digit

#define MMINUTE_L 4 //changing 2nd minute digit

#define MDAY_H 5 //changing day

#define MDAY_L 6 //changing 2nd digit of the day

#define MMONTH_H 7 //changing month

#define MMONTH_L 8 //changing 2nd digit of the month

#define MYEAR_4 9 //changing year

#define MYEAR_3 10 //changing year

#define MYEAR_2 11 //changing year

#define MYEAR_1 12 //changing year

#define MBACK_OFF 13 //end of first configuration list

#define MALARM_H_H 14 //changing 1st alarm hour

#define MALARM_H_L 15 //changing 2nd alarm hour

#define MALARM_M_H 16 //changing 1st alarm minute

#define MALARM_M_L 17 //changing 2nd alarm minute

#define MEND 18 //end of second configuration list

#define TIME_FOR_CONFIG 5 //cfg mode will have been working for 6 second after last button pressing


//timers

#define ONE_SECOND 0x7A12

#define HALF_SECOND 0x3D09

#define SEC_FOR_TIME 45 //how long will be displayed clock

#define SEC_FOR_DATE 5 //how long will be displayed date


//EEPROM addresses for variables

#define DAY_ADR 0x00

#define MON_ADR 0x01

#define YEARH_ADR 0x02

#define YEARL_ADR 0x03

#define ALRM_H_ADR 0x04 //alarm hours

#define ALRM_M_ADR 0x05 //alarm minutes

#define ALRM_ST_ADR 0x06 //address for state


//bits of register of changes (for EEPROM writing)

#define CH_DAY 0 //day

#define CH_MONTH 1 //month

#define CH_YEARH 2 //years (high)

#define CH_YEARL 3 //years (low)

#define CH_ALRM_H 4 //alarm hours

#define CH_ALRM_M 5 //alarm minutes

#define CH_ALRM_ST 6 //alarm state



//ALARM PREFERENCES

#define ALARM_REPEATS 3

#define ALARM_REPEAT0 0 //bit for checking pause between alarm signals

#define ALARM_REPEAT 2 //bit for checking pause between alarm signals

#define ALARM_STATE 4 //bit of global alarm state (alarm on/off)

#define ALARM_SIGNAL 5 //is it time for wake up?

#define ALARM_NO_REPEAT 6 //if alarm triggered


//INDICATORS

#define INDICATION indic

#define TIME_INDICAT 3 //current display - time

#define DATE_INDICAT 2 //current display - date

#define YEAR_INDICAT 1 //current display - year

#define ALARM_INDICAT 0 //alarm is turned on

#define INDICATION_MASK 0xF0 //1111.0000

//#define INDICATION_OFF (INDICATION &= INDICATION_MASK)


#define TIME_INDICAT_ON (INDICATION |= (1 << TIME_INDICAT))

#define DATE_INDICAT_ON (INDICATION |= (1 << DATE_INDICAT))

#define YEAR_INDICAT_ON (INDICATION |= (1 << YEAR_INDICAT))

#define ALARM_INDICAT_ON (INDICATION |= (1 << ALARM_INDICAT))

//#define ALARM_INDICAT_OFF (INDICATION &= ~(1 << ALARM_INDICAT))


#define NIGHT_ON 0


#define LIGHT_PIN PIND

#define LIGHT_SENSOR 3

#define EN_DDR_LIGHT_SENSOR (DDRD &= ~(1 << LIGHT_SENSOR))

#define EN_PORT_LIGHT_SENSOR (PORTD &= ~(1 << LIGHT_SENSOR))

#define SENSOR_POWER 0

#define SENSOR_POWER_PORT PORTC

#define SENSOR_POWER_ENABLE SENSOR_POWER_PORT |= 1 << SENSOR_POWER

#define SENSOR_POWER_DISABLE SENSOR_POWER_PORT &= ~(1 << SENSOR_POWER)

#define NIGHTMODE_OFF 0

#define NIGHTMODE_WAIT 1

#define NIGHTMODE_HALF 2

#define NIGHTMODE_ON 3


#define ZUMMER_DDR DDRC

#define ZUMMER_PORT PORTC

#define ZUMMER 5

#define ZUMMER_EN ZUMMER_PORT |= 1 << ZUMMER

#define ZUMMER_DIS ZUMMER_PORT &= ~(1 << ZUMMER)

#define ZUMMER_INVERT (ZUMMER_PORT ^= (1 << ZUMMER))


//Microphone

#ifdef MICROPHONE

#define MICRO_DDR DDRD

#define MICRO_PORT PORTD

#define MICRO 2

#define MICRO_DDR_CLR MICRO_DDR &= ~(1 << MICRO)

#define MICRO_PORT_SET MICRO_PORT |= 1 << MICRO

#define MICRO_PORT_CLR MICRO_PORT &= ~(1 << MICRO)

#endif


#define INT0_ENABLE GICR |= 1 << INT0

#define INT0_DISABLE GICR &= ~(1 << INT0)

#define INT0_CLR_FLAG GIFR &= ~(1 << INTF0)


//#define RAZR16

#ifndef RAZR16

#define RAZR 8

#else

#define RAZR 16

#endif



#endif

Так же в этом разделе:
 
MyTetra Share v.0.53
Яндекс индекс цитирования