📄 hal.h
字号:
#ifndef _HAL_H
#define _HAL_H
#include <iom88.h>
#include <ina90.h>
#include "common.h"
#include "ccreg.h"
#define KEY_READ ((~PIND>>PD3)&0x01)
#define SET_LED (PORTC |= 1 << PC2)
#define CLR_LED (PORTC &= ~ (1 << PC2))
#define LED_READ ((PINC>>PC2)&0x01)
#define SET_CSN (PORTD |= 1 << PD5)
#define CLR_CSN (PORTD &= ~ (1 << PD5))
#define SOREAD ((PINB & ((1 << PB4)))>>PB4)
#define SET_SO ((PORTB |= 1 << PB4)
#define CLR_SO (PORTB &=~(1 << PB4))
#define SIREAD ((PINB & ((1 << PB3)))>>PB3)
#define SET_SI (PORTB |= 1 << PB3)
#define CLR_SI (PORTB &=~(1 << PB3))
#define SCKREAD ((PINB & (1 << PB5))>>PB5)
#define SET_SCK (PORTB |= 1 << PB5)
#define CLR_SCK (PORTB &=~(1 << PB5))
#define GDO0READ ((PIND & (1 << PD5))>>PD5)
#define GDO2READ ((PIND>>PD6)&0x01)
#define GDO1READ SOREAD
//===============================================================
//===============================================================
#define WRITE_BURST 0x40
#define READ_SINGLE 0x80
#define READ_BURST 0xC0
#define SPI_ENABLE() (SPCR |= 1<<SPE)
#define SPI_DISABLE() (SPCR &= ~(1<<SPE))
#define SCLK_8_M 0x04
#define SCLK_4_M 0x00
#define SCLK_2_M 0x05
#define SCLK_1_M 0x01
#define SCLK_500_K 0x06
#define SCLK_250_K 0x02//or 0x07
#define SCLK_125_K 0x03
#define SPI_INIT(freq) \
do { \
SPCR=B0101_0000;\
SPCR = (SPCR&(~0x03))|(freq&0x03); \
SPSR = (SPSR&(~0x01))|(freq>>2); \
SPI_ENABLE(); \
} while (0)
#define SPI_WAIT() {while (!(SPSR&(1<<SPIF)));OCR2B=SPDR;}
//===============================================================
#define PCINT2_ENABLE() (PCICR |= 1<<PCIE2)
#define PCINT2_DISABLE() (PCICR &= ~(1<<PCIE2))
#define PCINT1_ENABLE() (PCICR |= 1<<PCIE1)
#define PCINT1_DISABLE() (PCICR &= ~(1<<PCIE1))
#define PCINT0_ENABLE() (PCICR |= 1<<PCIE0)
#define PCINT0_DISABLE() (PCICR &= ~(1<<PCIE0))
//===============================================================
#define IDLE 0x00
#define ADCNR 0x02
#define POWER_DOWN 0x04
#define POWER_SAVE 0x06
#define STANDBY 0x0c
//– – – – SM2 SM1 SM0 SE (SMCR)
#define SLEEP_ENABLE() (SMCR|=1<<SE)
#define SLEEP_DISABLE() (SMCR&=~(1<<SE))
#define SLEEP_MODE_SET(x) (SMCR=x)
//===============================================================
#define EEP_WRITE(D,A) \
do { \
while(EECR & (1<<EEPE));\
EEAR = A;\
EEDR = D;\
_CLI();\
EECR |= (1<<EEMPE);\
EECR |= (1<<EEPE);\
_SEI();\
} while (0)
#define EEP_READ(A) \
do { \
while(EECR & (1<<EEPE));\
EEAR=A;\
EECR |= (1<<EERE);\
} while (0)
//x=EEDR;
#endif
void Hal_init(void);
void Pause_10uS(BYTE delay);
void Pause_1mS(BYTE delay);
void CCxx_init(void);
void CCxx_send(BYTE *buf, BYTE n);
BOOL CCxx_receive(BYTE *buf, BYTE *n);
void SpiWriteBurstReg(BYTE addr, BYTE *buffer, BYTE count);
void SpiWriteReg(BYTE addr, BYTE value);
void SpiStrobe(BYTE strobe);
BYTE SpiReadStatus(BYTE addr);
BYTE SpiReadReg(BYTE addr);
void SpiReadBurstReg(BYTE addr, BYTE *buffer, BYTE count);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -