📄 main.h
字号:
// Compiler : IAR EWAVR
// Target : M8
// Crystal: 8Mhz
//the .h file of main.c
#define uchar unsigned char
#define uint unsigned int
#define SET_BIT(x,y) (x |= ( 1 << y )) //set the bit
#define CLR_BIT(x,y) (x &= ~( 1 << y )) //clear the bit
#define GET_BIT(x,y) (x & (1 << y )) //get the bit
#define KEY_PRESSED_TIME 10 //the time to get rid of wobble of key
#define KEY_LONG_PRESSED_TIME 100 //the time judge the long pressing of key
#define ENCODER_SECOND_PIN 7 //the encoder's second signal pin connect to PORTB.7
__regvar __no_init uchar uart_rec_data @ 15; //global variable in register
union udata
{
uchar at_all;
struct sdata
{
unsigned bit0:1;
unsigned bit1:1;
unsigned bit2:1;
unsigned bit3:1;
unsigned bit4:1;
unsigned bit5:1;
unsigned bit6:1;
unsigned bit7:1;
};
}status_flag;
//encoder act flag,each bit has different functin
//bit.0-whether it in effect or not;1 in effect;0 not
//bit.1-whether it acted or not; 1 acted; 0 not acted
//bit.2-it's round in clockwise or anticlocwise;1 clockwise
//bit.3-use to scan,
struct data
{
unsigned bit0:1;
unsigned bit1:1;
unsigned bit2:1;
unsigned bit3:1;
unsigned bit4:1;
unsigned bit5:1;
unsigned bit6:1;
unsigned bit7:1;
};
struct data act_flag = {0,0,0,0,0,0,0,0};
uchar LED_CONTROL_FLAG = 0x00; //
uchar adc_result[4] = {0x00,0x00,0x00,0x00}; //save the ADC result
uchar max = 0x00;
uchar min = 0x00;
uchar result = 0x00;
//EEPROM
unsigned char read_eep(unsigned int address)
{
unsigned char temp;
while(GET_BIT(EECR,EEWE))
;
__disable_interrupt();
EEAR = address;
SET_BIT(EECR,EERE);
temp = EEDR;
__enable_interrupt();
return temp;
}
void write_eep(unsigned int address,unsigned char data)
{
while(GET_BIT(EECR,EEWE))
;
EEAR = address;
EEDR = data;
__disable_interrupt();
SET_BIT(EECR,EEMWE);
SET_BIT(EECR,EEWE);
__enable_interrupt();
}
void delay_adc(uchar time_num);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -