BASIC4MCU | AVR | 컴파일러 | avrstudio의 _BV()를 코드비젼에서 처리 하려면
페이지 정보
작성자 키트 작성일2017-08-25 17:07 조회3,645회 댓글0건본문
Q:안녕하십니까 지금 avr 스튜디오에 있는 twi 헤더파일을 코드비젼에서 쓰려고 하고 있는데요..#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|\_BV(TWS3))이부분에서 막혔습니다 ㅠㅠㅠㅠ찾아보니까 _BV가 ()안에 비트를 1로 set 시키는 명령어라던데(TWS7=1)|....이런식으로 하면 안되는건가요?//------------------------------------------------------------------------------------------------------A:mcu마다 레지스터 구성이 같을 수도 다를 수도 있으니 해당 mcu의 레지스터 헤더파일을 참조해야 합니다.128이라면AVRstudio의 iom128.h 안에 질문의 레지스터가 있습니다./* 2-wire Status Register - TWSR */#define TWS7 7#define TWS6 6#define TWS5 5#define TWS4 4#define TWS3 3#define TWPS1 1#define TWPS0 0TWS비트 번호와 비트번호가 같습니다.//#define TW_STATUS_MASK 0b11111000 //(_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))2진으로 직접 설정해도 되고//#define TW_STATUS_MASK 0xF8 //(_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))16진으로 직접 설정해도 되고//#define TW_STATUS_MASK ((1<<7)|(1<<6)|(1<<5)|(1<<4)|(1<<3)) //(_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))이렇게 설정해도 됩니다.///* TWSR - TWI Status Register */#define I2SR TWSR // For compatibility#define TWPS0 0 // TWI Prescaler#define TWS0 TWPS0 // For compatibility#define I2GCE TWPS0 // For compatibility#define TWPS1 1 // TWI Prescaler#define TWS1 TWPS1 // For compatibility#define TWS3 3 // TWI Status#define I2S3 TWS3 // For compatibility#define TWS4 4 // TWI Status#define I2S4 TWS4 // For compatibility#define TWS5 5 // TWI Status#define I2S5 TWS5 // For compatibility#define TWS6 6 // TWI Status#define I2S6 TWS6 // For compatibility#define TWS7 7 // TWI Status#define I2S7 TWS7 // For compatibility코드비젼의 mega128_bits.h 헤더파일에도 같은 설정이 있으므로#define TW_STATUS_MASK ((1<<TWS7)|(1<<TWS6)|(1<<TWS5)|(1<<TWS4)|(1<<TWS3))이렇게 설정해도 되고//AVRstudio의 sfr_defs.h 헤더 파일 안에 있는#define _BV(bit) (1<<(bit))이 매크로 선언을 소스코드 윗쪽에 선언하면#define TW_STATUS_MASK (_BV(TWS7)|_BV(TWS6)|_BV(TWS5)|_BV(TWS4)|_BV(TWS3))질문의 매크로 선언을 그대로 사용할 수 있습니다,
댓글 0
조회수 3,645등록된 댓글이 없습니다.