LECTURE 2 LED ¤òÅÀÌǤµ¤»¤ë

¡û ¤Ï¤¸¤á¤Ë

¤³¤³¤Ç¤Ï¤Þ¤º¼ê»Ï¤á¤È¤·¤Æ¡¢LED ¤ò ATmega8535 ¤Ë·Ò¤²¤ÆÅÀÌǤµ¤»¤Æ¤ß¤Þ¤¹¡£

¡û Æþ½ÐÎϥݡ¼¥È

LED ¤ò¸÷¤é¤»¤ë¤¿¤á¤Ë¤Ï¡¢ATmega8535 ¤ÎÆþ½ÐÎϥݡ¼¥È¤Ë LED ¤òÀܳ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ATmega8535 ¤Ï A - D ¤Î 4 ¤Ä¤ÎÆþ½ÐÎϥݡ¼¥È¤òÈ÷¤¨¤Æ¤ª¤ê¡¢³Æ¥Ý¡¼¥È¤Ë¤Ï 8 ¥Ô¥ó¤º¤Ä¤ÎÆþ½ÐÎϥԥ󤬤¢¤ê¤Þ¤¹¡£PDIP ¥Ñ¥Ã¥±¡¼¥¸¤Î¾ì¹ç¡¢³Æ¥Ý¡¼¥È¤Ë°¤¹¤ë¥Ô¥óÈÖ¹æ¤Ï°Ê²¼¤ÎÄ̤ê¤Ç¤¹¡£

  • PORTA : 40 (PA0) - 33 (PA7)
  • PORTB : 01 (PB0) - 08 (PB7)
  • PORTC : 22 (PC0) - 29 (PC7)
  • PORTD : 14 (PD0) - 21 (PD7)
ATmega8535 -PDIP-

¸å½Ò¤Î´ØÏ¢¥ì¥¸¥¹¥¿¤Î½ê¤ÇÆþ½ÐÎÏ¥Ô¥ó¤òɽ¤¹¥Þ¥¯¥í¤òºÜ¤»¤Æ¤¤¤Þ¤¹¤¬¡¢avr-libc ¤Î¾ì¹ç¤ÏÎ㤨¤Ð PORTA0/PA0/PINA0 ¤ÏÁ´¤ÆƱ¤¸ÈÖ¹æ¤È¤·¤ÆÄêµÁ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£PINA0 ¤Î·Á¼°¤ÏÆþÎÏ¥Ô¥ó¤È¤¤¤¦¤³¤È¤òÌÀ¼¨¤¹¤ë¤¿¤á¤Ë»È¤¨¤ë¤È»×¤¤¤Þ¤¹¤¬¡¢PORTA0/PA0 ¤Î»È¤¤Ê¬¤±¤Ï¤É¤¦¤¹¤ë¤Î¤¬°ìÈÖÎɤ¤¤Î¤«¤è¤¯Ê¬¤ê¤Þ¤»¤ó¡£

ËÜʸ½ñ¤Ç¤ÏÆþ½ÐÎÏ¥Ô¥ó¤òɽ¤¹¾ì¹ç¤Ï PINA0/PORTA0 ¤Î·Á¼°¤ò»È¤¤¡¢PA0 ¤Î·Á¼°¤Ï¾åµ­¤Î¿Þ¤Ç»È¤ï¤ì¤Æ¤¤¤ëÍͤ˥ԥ󤽤Τâ¤Î¤òɽ¤·¤¿¤¤¾ì¹ç¤Ë»È¤¦Íͤˤ·¤Þ¤¹¡£

¡û ´ØÏ¢¥ì¥¸¥¹¥¿

Æþ½ÐÎϥݡ¼¥È¤Ë´ØÏ¢¤¹¤ë¥ì¥¸¥¹¥¿¤Ï¡¢³Æ¥Ý¡¼¥È¤ËÂФ·¤Æ½ÐÎÏ/Êý¸þ/ÆþÎϤΠ3 ¤Ä¤Î¥ì¥¸¥¹¥¿¤¬¤¢¤ê¤Þ¤¹¡£°Ê²¼¤Ë³Æ¥ì¥¸¥¹¥¿¤ÎÆâÍƤò½ñ¤­¤Þ¤¹¡£X ¤ò A - D ¤ÇÆɤßÂؤ¨¤Æ¤¯¤À¤µ¤¤¡£¥Þ¥¯¥í¤Ë¤Ä¤¤¤Æ¤Ï¡¢avr-libc ¤Ç»ÈÍѤǤ­¤ëÄêµÁ̾¤ò·ÇºÜ¤·¤Æ¤¤¤Þ¤¹¡£

  • ¥Ý¡¼¥È X ½ÐÎϥ쥸¥¹¥¿ (PORTX)

    ¥Ó¥Ã¥ÈÈÖ¹æ 7 6 5 4 3 2 1 0
    ¥Þ¥¯¥í PORTX7 PORTX6 PORTX5 PORTX4 PORTX3 PORTX2 PORTX1 PORTX0
    ½é´üÃÍ 0 0 0 0 0 0 0 0


  • ¥Ý¡¼¥È X Êý¸þ¥ì¥¸¥¹¥¿ (DDRX)

    ¥Ó¥Ã¥ÈÈÖ¹æ 7 6 5 4 3 2 1 0
    ¥Þ¥¯¥í DDX7 DDX6 DDX5 DDX4 DDX3 DDX2 DDX1 DDX0
    ½é´üÃÍ 0 0 0 0 0 0 0 0


  • ¥Ý¡¼¥È X ÆþÎϥ쥸¥¹¥¿ (PINX)

    ¥Ó¥Ã¥ÈÈÖ¹æ 7 6 5 4 3 2 1 0
    ¥Þ¥¯¥í PINX7 PINX6 PINX5 PINX4 PINX3 PINX2 PINX1 PINX0
    ½é´üÃÍ ÉÔÄê ÉÔÄê ÉÔÄê ÉÔÄê ÉÔÄê ÉÔÄê ÉÔÄê ÉÔÄê

Æþ½ÐÎϥݡ¼¥È¤ò»È¤¦¾ì¹ç¤Ï¡¢¤Þ¤º DDRX ¤òÀßÄꤷ¤Þ¤¹¡£¥Ô¥ó¤òÆþÎϤȤ·¤Æ»È¤¦¾ì¹ç¤Ï¡¢DDRX ¤ÎÂбþ¤¹¤ë¥Ó¥Ã¥È¤Ë 0 ¤ò¡¢½ÐÎϤȤ·¤Æ»È¤¦¾ì¹ç¤Ï 1 ¤ò½ñ¤­¹þ¤ß¤Þ¤¹¡£½ÐÎϤ¹¤ë¾ì¹ç¤Ï PORTX ¤ÎÂбþ¤¹¤ë¥Ó¥Ã¥È¤Ë 1/0 ¤ò½ñ¤­¹þ¤ß¤Þ¤¹¡£ÆþÎϤξì¹ç¤Ï¡¢PINX ¤ÎÂбþ¤¹¤ë¥Ó¥Ã¥È¤ò»²¾È¤·¤Þ¤¹¡£

ÆþÎÏ¥Ô¥ó¤ËÂФ·¤Æ 1 ¤ò½ñ¤­¹þ¤à¤ÈÆâÉô¥×¥ë¥¢¥Ã¥×Äñ¹³¤¬Í­¸ú¤È¤Ê¤ê¡¢Ì¤»ÈÍÑ»þ/̤Àܳ»þ¤Î²áÂçÅÅή¾ÃÈñ¤òËɤ°¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¡û ²óÏ©¿Þ

LECTURE 1 ATmega8535 ¤ª¤è¤Ó»ÈÍѴĶ­¤Ë¤Ä¤¤¤Æ ¤Ë·ÇºÜ¤·¤Æ¤¢¤ëÁ´ÂβóÏ©¿Þ¤ËÂФ·¤Æ¡¢ÅÀÌǤµ¤»¤ë LED Éôʬ¤òÀÖÏȤǰϤó¤À¿Þ¤ò¤³¤Á¤é¤ËÃÖ¤¤¤Æ¤ª¤­¤Þ¤¹¡£

PORTB ¤Î PB0 ¥Ô¥ó¤Ë LED ¤òÀܳ¤·¡¢ÊݸîÄñ¹³¤ò²ð¤·¤Æ GND ¤ËÀܳ¤·¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ë¤è¤ê¡¢PB0 ¤¬ H ¤Î¾ì¹ç¤Ë LED ¤¬ÅÀÅô¤·¤Þ¤¹¡£

¡û ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ÈÀâÌÀ

LED ¤òÅÀÌǤµ¤»¤ë¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò 02led.tar.gz ¤«¤é¥À¥¦¥ó¥í¡¼¥É¤Ç¤­¤Þ¤¹¡£¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤«¤é¡¢Á´¤Æ¤Î¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤ò ¸Ç¤á¤¿ tar ¥Õ¥¡¥¤¥ë¤ò¥À¥¦¥ó¥í¡¼¥É¤¹¤ë¤³¤È¤â¤Ç¤­¤Þ¤¹¡£

Ãæ¤Ë¤Ï

  • Makefile
  • util.h
  • util.c
  • main.c

¤¬³ÊǼ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£¤½¤ì¤¾¤ì¤Ë¤Ä¤¤¤Æ°Ê²¼¤ËºÜ¤»¤Þ¤¹¡£¤Ê¤ª¡¢°Ê²¼¤Ë·ÇºÜ¤·¤Æ¤¤¤ë¥½¡¼¥¹¥³¡¼¥É¤Ë¤Ï½¤Àµ BSD ¥é¥¤¥»¥ó¥¹¾ò¹à¤ò´Þ¤á¤Æ¤¤¤Þ¤»¤ó¤¬¡¢¥½¡¼¥¹¥³¡¼¥ÉÇÛÉۤϽ¤Àµ BSD ¥é¥¤¥»¥ó¥¹¤Ë½¾¤¤¤Þ¤¹¡Ê¤Ï¤¸¤á¤Ë ¤Î¥Ú¡¼¥¸¤ÎÌÈÀÕ»ö¹à¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡Ë¡£

¤³¤ì¤Þ¤Ç¤Ë¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤ÎÀßÄê¤ò¹Ô¤Ã¤¿¤³¤È¤¬°ìÅÙ¤â̵¤¤¾ì¹ç¤Ï¡¢¤Þ¤ººÇ½é¤Ë make fuse ¤ò¼Â¹Ô¤·¤Æ¤¯¤À¤µ¤¤¡£º£¸å¤Î¥µ¥ó¥×¥ë¤Ë¤ª¤±¤ë Makefile ¤Ç¤â fuse ¥¿¡¼¥²¥Ã¥È¤¬ÍÑ°Õ¤µ¤ì¤Æ¤¤¤Þ¤¹¡£fuse ¥¿¡¼¥²¥Ã¥È¤Ï

uisp -dprog=dapa -dlpt=0x378 --wr_fuse_l=0xff

¤ò¼Â¹Ô¤¹¤ë¤¿¤á¤Î¥¿¡¼¥²¥Ã¥È¤Ç¤¹¡£¤³¤ì¤Ë¤è¤ê¡¢ATmega8535 ¤Î¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤È¸Æ¤Ð¤ì¤ëÀßÄêÃͤβ¼°Ì¥Ð¥¤¥È¤ò 0xff 0xef 0xff ¤ËÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£ATMega8535 ¤Ï¥Ç¥Õ¥©¥ë¥È¤Ç¤Ï 1MHz ¤ÎÆâ¡ RC ȯ¿¶´ï¤¬¥¯¥í¥Ã¥¯¸µ¤È¤Ê¤ê¤Þ¤¹¡£º£²ó¤Î²óÏ©¤Ç¤Ï¡¢8MHz ¤Î³°Éô¿å¾½¿¶Æ°»Ò¤òÀܳ¤·¤Æ¤¤¤ë¤¿¤á¡¢¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤òÀßÄꤹ¤ë¤³¤È¤Ç¿å¾½¿¶Æ°»Ò¤ò¥¯¥í¥Ã¥¯¸µ¤È¤·¤Æ»ÈÍѤ¹¤ëÍͤˤ·¤Æ¤¤¤Þ¤¹¡£

¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤Î²¼°Ì¥Ð¥¤¥È¤ÎÀßÄê¤ò 0xff ¤«¤é 0xef ¤ËÊѤ¨¤Þ¤·¤¿¡£¤È¤¤¤¦¤Î¤â¡¢LECTURE 1 ATmega8535 ¤ª¤è¤Ó»ÈÍѴĶ­¤Ë¤Ä¤¤¤Æ ¤Î¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤Î½ê¤Ë½ñ¤­¤Þ¤·¤¿¤¬¡¢SUT1 - 0 ¥Ó¥Ã¥È¤ÎÀßÄêÃͤò¸í¤Ã¤Æ¤¤¤Þ¤·¤¿¡£¼«Ê¬¤Î´Ä¶­¤ÇÆ°ºî³Îǧ¤·¤Æ¤ß¤¿½ê¡¢Æ°ºî¤Ë±Æ¶Á¤Ï̵¤«¤Ã¤¿ÍͤǤ¹¤¬¡Ä

¾åµ­¤Î½¤Àµ¼«ÂΤ¬´Ö°ã¤Ã¤Æ¤¤¤Þ¤·¤¿¡Ä¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤Î²¼°Ì¥Ð¥¤¥È¤ÎÀßÄê¤Ï 0xff ¤Î¤Þ¤Þ¤Ç O.K. ¤Ç¤¹¡£LECTURE 1 ATmega8535 ¤ª¤è¤Ó»ÈÍѴĶ­¤Ë¤Ä¤¤¤Æ ¤Î¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤Î½ê¤â»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£

ËÜÀßÄê¤Ï°ìÅټ¹Ԥ¹¤ì¤Ðµ­²±¤µ¤ì¤Þ¤¹¤Î¤Ç¡¢º£²ó¼Â¹Ô¤·¤¿¾ì¹ç¤Ïº£¸å¤Î¥µ¥ó¥×¥ë¥³¡¼¥É¼Â¹Ô¤ÎÅ٤˹Ԥ¦É¬ÍפϤ¢¤ê¤Þ¤»¤ó¡£¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤Ë¤Ä¤¤¤Æ¤Ï LECTURE 1 ATmega8535 ¤ª¤è¤Ó»ÈÍѴĶ­¤Ë¤Ä¤¤¤Æ ¤ò»²¾È¤·¤Æ¤¯¤À¤µ¤¤¡£

¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤ÎÀßÄ꤬½ª¤ï¤ê¤Þ¤·¤¿¤é

make
make uisp

¤Ç¡¢¥³¥ó¥Ñ¥¤¥ë¤ª¤è¤Ó ATmega8535 ¤Ø¤Î½ñ¤­¹þ¤ß¤ò¼Â¹Ô¤·¤Þ¤¹¡£uisp ¥¿¡¼¥²¥Ã¥È¤Ç¤Ï

uisp --dprog=dapa -dlpt=0x378 --erase --upload --verify

¤ò¼Â¹Ô¤·¤Þ¤¹¡£¥Õ¥é¥Ã¥·¥å¥á¥â¥ê¤Î¾Ãµî¡¢¥×¥í¥°¥é¥à¤Î¥¢¥Ã¥×¥í¡¼¥É¤ª¤è¤Ó¸¡¾Ú¤ò¹Ô¤¤¤Þ¤¹¡£¥¨¥é¡¼¤¬É½¼¨¤µ¤ì¤Ê¤±¤ì¤Ð¥¢¥Ã¥×¥í¡¼¥É¤ÏÀ®¸ù¤Ç¤¹¡£LED ¤¬Ìó 250ms Ëè¤Ë¡Ê1 ÉÃ´Ö¤Ë 4 ²óÄø¡ËON/OFF ¤ò·«¤êÊÖ¤·¤Þ¤¹¡£

¢­ÀÖÏÈÆ⤬ PB0 ¥Ô¥ó¤ËÀܳ¤·¤¿ LED ¤Ç¤¹¡£
LED ÅÀÅô¤ÎÍÍ»Ò

¤³¤Á¤é¤Ï LED ÅÀÌǤÎÆ°²è¤Ç¤¹¡Ê10Éá£YouTube ¤ËÀܳ¤·¤Þ¤¹¡Ë¡£

  • Makefile
        1    CC = avr-gcc
        2    OBJCOPY = avr-objcopy
        3    
        4    UISP = uisp -dprog=dapa -dlpt=0x378 --erase --upload --verify
        5    FUSE = uisp -dprog=dapa -dlpt=0x378 --wr_fuse_l=0xff
        6    
        7    MCU = atmega8535
        8    FORMAT = ihex
        9    F_CPU = 8000000
       10    
       11    CFLAGS = -Wall -std=gnu99 -mmcu=$(MCU) -Os -DF_CPU=$(F_CPU)
       12    
       13    %.o: %.c; $(CC) -c $(CFLAGS) -o $@ $<
       14    %.hex: %.elf; $(OBJCOPY) -O $(FORMAT) $< $@
       15    
       16    OBJS = main.o util.o
       17    ELFS = main.elf
       18    TARGET=main.hex
       19    
       20    all: $(TARGET)
       21    main.hex: main.elf
       22    
       23    main.elf: $(OBJS)
       24        $(CC) $(CFLAGS) -o $@ $^
       25    
       26    main.o: main.c util.h
       27    util.o: util.c util.h
       28    
       29    uisp: main.hex
       30        $(UISP) if=$<
       31    
       32    fuse:
       33        $(FUSE)
       34    
       35    clean:
       36        rm -f $(TARGET) $(ELFS) $(OBJS) *~
    
    
  • util.h
        1    #ifndef ___UTIL_H_INCLUDED_
        2    #define ___UTIL_H_INCLUDED_
        3    
        4    #include <avr/io.h>
        5    
        6    
        7    #define pullup() {\
        8            PORTA = 0xff; \
        9            PORTB = 0xff; \
       10            PORTC = 0xff; \
       11            PORTD = 0xff; \
       12    }
       13    
       14    void delay_250ms(void);
       15    
       16    
       17    #endif
       18    
       19    /* End of util.h */
    
    
    • 7 ¡Á 12 ¹ÔÌÜ (pullup())

      pullup() ¥Þ¥¯¥í¤Ç¤Ï¡¢ATmega8535 ¤¬È÷¤¨¤ëÁ´¤Æ¤ÎÆþ½ÐÎϥݡ¼¥È¤ÎÁ´¤Æ¤Î¥Ô¥ó¤ò High ¤ËÀßÄꤷ¤Æ¤¤¤Þ¤¹¡Ê³Æ¥Ó¥Ã¥È¤ò1¤ËÀßÄê¡Ë¡£Ì¤Àܳ¤ÎÆþ½ÐÎϥݡ¼¥È¤ò¤½¤Î¤Þ¤Þ¤Ë¤·¤Æ¤ª¤¯¤È ²áÂç¤ÊÅÅή¤¬Î®¤ì¤ë¾ì¹ç¤¬¤¢¤ë¤¿¤á¡¢ÆþÎÏÊý¸þ¤ËÀßÄꤵ¤ì¤Æ¤¤¤ë¤³¤È¤òÁ°Äó¤È¤·¤Æ¡¢ Á´¤Æ¤Î¥Ô¥ó¤ÎÆâÉô¥×¥ë¥¢¥Ã¥×Äñ¹³¤òÍ­¸ú¤Ë¤¹¤ë¤¿¤á¤ËÍÑ°Õ¤·¤Æ¤¤¤Þ¤¹¡£

  • util.c
        1    #include <util/delay.h>
        2    #include "util.h"
        3    
        4    
        5    void
        6    delay_250ms(void)
        7    {
        8            int i;
        9    
       10            for (i = 0; i < 25; i ++) {
       11                    _delay_ms(10);
       12            }
       13    }
       14    
       15    /* End of util.c */
    
    
    • 5 ¡Á 13 ¹ÔÌÜ (delay_250ms())

      250ms ¤ò·×¬¤¹¤ë¤¿¤á¤Î´Ø¿ô delay_250ms() ¤Ç¤¹¡£avr-libc ¤Ë _delay_ms() ¤¬ÄêµÁ¤µ¤ì¤Æ¤¤¤ë¤Î¤Ç¡¢ ¤½¤ì¤ò´ð¤Ë¤·¤Æ¤¤¤Þ¤¹¡£

      void _delay_ms(double _ms);
      _ms : Ãٱ䤹¤ë¥ß¥êÉÃ
      

      _delay_ms() ¤ò»È¤¦¤¿¤á¤Ë¤Ï¡¢F_CPU ¥Þ¥¯¥í¤òÄêµÁ¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ËÜ¥µ¥ó¥×¥ë¤Ç¤Ï Makefile ¤Ë¤Æ

      F_CPU = 8000000
      

      ¤È¤·¤Æ¤¤¤Þ¤¹¡Ê8MHz ¤Ê¤Î¤Ç¡Ë¡£avr-libc ¤Î¥É¥­¥å¥á¥ó¥È¤Ë¤è¤ë¤È¡¢²Äǽ¤ÊºÇÂç¤ÎÃÙ±ä»þ´Ö¤Ï 262.14ms / F_CPU(MHz) = Ìó 38ms ¤Þ¤Ç¤È¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡£¤³¤ì¤Ë¤è¤ê¡¢_delay_ms(10) ¤ò 25 ²ó¼Â¹Ô¤¹¤ë¤³¤È¤Ç 250ms ¤ÎÃÙ±ä¤ò¼Â¸½¤·¤Æ¤¤¤Þ¤¹¡£

  • main.c
        1    #include <avr/io.h>
        2    #include "util.h"
        3    
        4    
        5    int
        6    main(void)
        7    {
        8            /* PB0 ¥Ô¥ó¤Î¤ß½ÐÎÏÀßÄê */
        9            DDRB = _BV(PORTB0);
       10            pullup();
       11    
       12            while (1){
       13                    PORTB ^= _BV(PORTB0);
       14                    delay_250ms();
       15            }
       16    
       17            return 0; /* ·Ù¹ð¤òÈò¤±¤ë¤¿¤á */
       18    }
       19    
       20    /* End of main.c */
    
    
    • 1 ¹ÔÌÜ

      ³Æ¼ï¥ì¥¸¥¹¥¿¤ä¥Ó¥Ã¥ÈÅù¤Î¥Þ¥¯¥í(PORTB0 ¤ä DDRB Åù) ¤ò»È¤¦¤¿¤á¤Ë¡¢avr/io.h ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤·¤Æ¤¤¤Þ¤¹¡£ ¤Û¤È¤ó¤É¤Î¥×¥í¥°¥é¥à¤Ç avr/io.h ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤³¤È¤Ë¤Ê¤ë¤È»×¤¤¤Þ¤¹¡£

    • 5 ¡Á 18 ¹ÔÌÜ (main())

      LED ÅÀÌǽèÍý¤Î main ´Ø¿ô¤Ç¤¹¡£

      9 ¹ÔÌܤǡ¢PORTB0 ¥Ô¥ó¤ò½ÐÎÏÊý¸þ¤ËÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£DDRB ¤Ï¥Ý¡¼¥È B ¤ÎÊý¸þ¥ì¥¸¥¹¥¿¤Ç¤¹¡£ _BV() ¥Þ¥¯¥í¤Ï¡¢ÈÖ¹æ¤ò»ØÄꤹ¤ë¤È¤½¤Î¥Ó¥Ã¥È¤Î¤ß¤ò 1 ¤Ë¤·¤¿ÃͤòÊÖ¤·¤Æ¤¯¤ì¤Þ¤¹¡£ avr/io.h ¤ò¥¤¥ó¥¯¥ë¡¼¥É¤¹¤ë¤È»È¤¨¤Þ¤¹¡£PORTB0 = 0 ¤Î¤¿¤á¡¢_BV(PORTB0) ¤Ë¤è¤Ã¤Æ¥Ó¥Ã¥È 0 ¤Î¤ß¤¬ 1 ¤È¤Ê¤Ã¤¿Ãͤò DDRB ¤ËÀßÄꤹ¤ë¤³¤È¤Ë¤Ê¤ê¤Þ¤¹¡£

      10 ¹ÔÌܤǡ¢PORTB0 °Ê³°¤ÎÆâÉô¥×¥ë¥¢¥Ã¥×¤òÍ­¸ú¤Ë¤·¤Þ¤¹¡£PORTB0 ¤Ï½ÐÎÏ¥Ô¥ó¤Î¤¿¤á High ¤¬½ÐÎϤµ¤ì¤Þ¤¹¡£¤³¤ì¤Ë¤è¤ê¡¢PORTB0 ¤ËÀܳ¤·¤¿ LED ¤¬ÅÀÅô¤·¤Þ¤¹¡£

      12 ¡Á 15 ¹ÔÌܤΥ롼¥×¤ÇÅÀÌǽèÍý¤ò¹Ô¤Ã¤Æ¤¤¤Þ¤¹¡£13 ¹ÔÌܤÎ

      PORTB ^= _BV(PORTB0);
      

      ¤Ë¤è¤Ã¤Æ¡¢PORTB0 ¤Î¾õÂÖ¤òȿž¤·¤Æ¤¤¤Þ¤¹¡£^= ¤ÏÇÓ¾ŪÏÀÍýÏ¤Τ¿¤á¡¢PORTB0 ¤¬ 1 ¤Ç¤¢¤ì¤Ð·ë²Ì¤Ï 0 ¤Ë¡¢PORTB0 ¤¬ 0 ¤Ç¤¢¤ì¤Ð·ë²Ì¤Ï 1 ¤Ë¤Ê¤ê¤Þ¤¹¡£LED ¤Î¾õÂÖ¤òȿž¤·¤¿¸å¡¢ delay_250ms() ¤Ë¤è¤Ã¤Æ 250ms ÂԤ俸塢¾õÂÖȿž½èÍý¤ËÌá¤ê¤Þ¤¹¡£

°Ê¾å¤Ç²òÀâ¤Ï½ª¤ï¤ê¤Ç¤¹¡£¥×¥í¥°¥é¥à¤Ï¤«¤Ê¤ê´Êñ¤Ë´¶¤¸¤¿¤Î¤Ç¤Ï¤Ê¤¤¤Ç¤·¤ç¤¦¤«¡©¤â¤Ã¤È®¤¯ÅÀÌǤµ¤»¤¿¤ê¤È¡¢¤¤¤í¤¤¤í¤ä¤Ã¤Æ¤ß¤Æ¤¯¤À¤µ¤¤¡£