본문 바로가기

Embedded

WinAVR(AVR Studio / ICCAVR)환경에서 PORTx.bit 사용하기

 

coding을 하다 보면 PORT의 bit 단위로 제어가 필요한 경우가 있지요..

WinAVR환경에서는 compat/deprecated.h을 Include해 줌으로써 sbi와 cbi 함수를 사용할 수 있습니다.

sbi(PORTx, bit)            // set the PORTX.bit
ex) sbi(PORTD, 0)          // set the PORTD.0 = 1   ==> PORTD = 0x01
                                 
cbi(PORTx, bit)            // clear the PORTX.bit
ex) cbi(PORTD, 0)          // clear the PORTD.0 = 0   ==> PORTD = 0x00