NEWTC



  • HOME
  • Customer Center
  • FAQ


hit : 3,365
title [Related with AVR source] TIP to easily control (GPIO) I/O of port.
name admin 11-08-29 21:48

Hello?
I have observed many persons were ill at ease because 8051 and the like had functions control each bit but AVR has not such the function. For example, if we set P1.0 = 1 in 8051; you could use 0 bit in port 1 as I bit. It was so comfortable. But, ICCAVR had such the function as hexa code got bigger if we did so. We have to fabricate it for ourselves to use.

 

For this reason, we used to make as below. The below is definition relevant to input-output controlling bit. We used to make it function but it is convenient and fast if we make it define text as below: That’s because we are involved in function. We can save the time to be involved in function. Please consider above.

- Below 1-  


   #define sbi(port, bit)        (port) |= (1 << (bit))
   #define cbi(port, bit)        (port) &= ~(1 << (bit))

- Below 2 -

   #define        OUTPORT                        PORTC
   #define        BIT_4                                0x10
   #define        BIT_5                                0x20

   #define        BIT4(m)                m?(OUTPORT|=BIT_4):(OUTPORT&=~BIT_4)
   #define        BIT5(m)                m?(OUTPORT|=BIT_5):(OUTPORT&=~BIT_5)

If you follow below 2, it is convenient for you of its own. But, below 1 usually is used a lot.
For gaining input


 #define        INPORT                        PINC  
 
   unsigned char test4, test5;
   test4=INPORT&(0x10);
   test5=INPORT&(0x20)

follow this.  

Thank you.