LECTURE 1 ATmega8535 ¤ª¤è¤Ó»ÈÍѴĶ­¤Ë¤Ä¤¤¤Æ

¡û ¤Ï¤¸¤á¤Ë

ËÜʸ½ñ¤Ç¤Ï¡¢Atmel ¼Ò ¤¬À½Â¤¤·¤Æ¤¤¤ë 8 ¥Ó¥Ã¥È¥Þ¥¤¥³¥ó¤Î¤¦¤Á¡¢ATmega8535 ¤È¤¤¤¦¥Þ¥¤¥³¥ó¤ò»È¤¤¤Þ¤¹¡£¤³¤³¤Ç¤Ï°Ê¹ß¤Î¥Ú¡¼¥¸¤Ç¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤òÀâÌÀ¤¹¤ëÁ°¤Ë¡¢ATmega8535 ¤Îµ¡Ç½³µÍפäËÜʸ½ñ¤Ç»ÈÍѤ¹¤ë¥Ï¡¼¥É¥¦¥§¥¢¡¿¥½¥Õ¥È¥¦¥§¥¢¤Ë¤Ä¤¤¤Æ´Êñ¤ËÀâÌÀ¤·¤Þ¤¹¡£

¡û µ¡Ç½³µÍ×

ATmega8535 ¤Î¼ç¤ÊÆÃħ¤ª¤è¤Óµ¡Ç½¤Ï°Ê²¼¤ÎÍͤˤʤê¤Þ¤¹¡ÊÁ´¤Æ¤Ç¤Ï¤¢¤ê¤Þ¤»¤ó¡Ë¡£

  • RISC ¥¢¡¼¥­¥Æ¥¯¥Á¥ã
  • 32 ¸Ä¤ÎÈÆÍѥ쥸¥¹¥¿
  • 8K ¥Ð¥¤¥È¤Î¥×¥í¥°¥é¥àÍÑ¥Õ¥é¥Ã¥·¥å¥á¥â¥ê
  • 512 ¥Ð¥¤¥È¤Î¥Ç¡¼¥¿ÊݸÍÑ EEPROM
  • 512 ¥Ð¥¤¥È¤Î¥Ç¡¼¥¿ÍÑ SRAM
  • 2 ¤Ä¤Î 8 ¥Ó¥Ã¥È¥¿¥¤¥Þ/¥«¥¦¥ó¥¿¤ª¤è¤Ó 1 ¤Ä¤Î 16 ¥Ó¥Ã¥È¥¿¥¤¥Þ/¥«¥¦¥ó¥¿
  • 4 ¤Ä¤Î PWM ½ÐÎÏ
  • 10 ¥Ó¥Ã¥È A/D ÊÑ´¹´ï
  • ¥·¥ê¥¢¥ë USART
  • ¥¦¥©¥Ã¥Á¥É¥Ã¥°¥¿¥¤¥Þ
  • ¥¢¥¤¥É¥ëÅù¤ÎÄã¾ÃÈñÅÅÎÏÆ°ºî¥â¡¼¥É
  • Æ°ºîÅÅ°µ 4.5 ¡Á 5.5V
  • Æ°ºî®ÅÙ 0 ¡Á 16 MHz

¡û ¥Ò¥å¡¼¥º¥Ó¥Ã¥È

¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤È¤Ï¡¢´ðËÜŪ¤ÊÀßÄêÃͤò³ÊǼ¤¹¤ë¤¿¤á¤ÎÎΰè¤Ç¤¹¡Ê¥Ï¡¼¥É¥¦¥§¥¢Åª¤Ë¤É¤³¤ËÍÑ°Õ¤µ¤ì¤Æ¤¤¤ë¤Î¤«Ê¬¤«¤Ã¤Æ¤¤¤Þ¤»¤ó¡Ä¡Ë¡£ËÜʸ½ñ¤ÎÈϰϤǤϤۤȤó¤ÉɬÍפʤ¤¤Î¤Ç¤¹¤¬¡¢Í£°ì³°Éô¥¯¥í¥Ã¥¯¤ÇÆ°ºî¤µ¤»¤ë¤¿¤á¤ËÀßÄê¤ò¹Ô¤¦¤¿¤á¤³¤³¤ÇÀâÌÀ¤·¤Þ¤¹¡£

¥Ò¥å¡¼¥º¾å°Ì¥Ð¥¤¥È¤È²¼°Ì¥Ð¥¤¥È¤¬¤¢¤ê¡¢ËÜʸ½ñ¤Ç¤Ï²¼°Ì¥Ð¥¤¥È¤òÀßÄꤷ¤Þ¤¹¡ÊÄɵ­Åù¤Ç¾å°Ì¥Ð¥¤¥È¤¬É¬Íפˤʤ俾ì¹ç¤Ï¡¢ÀâÌÀ¤òÄɵ­¤·¤Þ¤¹¡Ë¡£²¼°Ì¥Ð¥¤¥È¤ÎÆâÍƤϰʲ¼¤ÎÄ̤ê¤Ç¤¹¡£

̾¾Î ¥Ó¥Ã¥ÈÈÖ¹æ ÆâÍÆ ¥Ç¥Õ¥©¥ë¥ÈÃÍ
BODLEVEL 7 ÄãÅÅ°µ¸¡½Ð´ï¡ÊBOD¡Ë¸¡½ÐÅÅ°µÁªÂò 1
BODEN 6 ÄãÅÅ°µ¸¡½Ð´ï¡ÊBOD¡ËÍ­¸ú/̵¸ú 1¡ÊBOD̵¸ú¡Ë
SUT1 5 µ¯Æ°»þ´ÖÁªÂò 1
SUT0 4 0
CKSEL3 3 ¥¯¥í¥Ã¥¯¼ïÊÌÁªÂò 0
CKSEL2 2 0
CKSEL1 1 0
CKSEL0 0 1

SUT1 - 0 ¤Ïµ¯Æ°»þ¤ÎÃÙ±ä»þ´Ö¤òÁªÂò¤·¤Þ¤¹¡£¸å½Ò¤Î CKSEL3 - 0 ¤ÎÀâÌÀ¤Ë¤Æµ­½Ò¤·¤Æ¤¤¤Þ¤¹¤¬¡¢ËÜʸ½ñ¤Ç¤Ï SUT1 - 0 = 11 ¤È¤·¤Þ¤·¤¿¡£¥¯¥í¥Ã¥¯¼ïÊ̤ϡ¢CKSEL3 - 0 ¤ÎÁȤ߹ç¤ï¤»¤Ë¤è¤Ã¤Æ°Ê²¼¤ÎÍͤ˷è¤Þ¤ê¤Þ¤¹¡£É½Ãæ¤Ëµ­½Ò¤·¤Æ¤¤¤ëÄ̤ꡢËÜʸ½ñ¤Ç¤Ï CKSEL3 - 0 = 1111 ¤È¤·¤Þ¤·¤¿¡£

CKSEL3 - 0 ¥¯¥í¥Ã¥¯¼ïÊÌ
0000 ³°Éô¥¯¥í¥Ã¥¯¿®¹æ
0100 - 0001 ¹»ÀµÉÕ¤­Æâ¡RCȯ¿¶´ï¡Ê¥Ç¥Õ¥©¥ë¥È¤Ï 0001 ¤Ç 1.0MHz Æâ¡RCȯ¿¶´ï¤Î»ÈÍѤȤʤê¤Þ¤¹¡Ë
1000 - 0101 ³°ÉôRCȯ¿¶´ï
1001 ³°ÉôÄã¼þÇÈ¿ô¿å¾½¿¶Æ°»Ò
1111 - 1010 ³°Éô¿å¾½¿¶Æ°»Ò/¥»¥é¥ß¥Ã¥¯È¯¿¶»Ò¡£¥Ò¥å¡¼¥º¾å°Ì¥Ð¥¤¥È¤Î CKOPT ¥Ó¥Ã¥È¡Ê¥Ç¥Õ¥©¥ë¥ÈÃÍ1¡Ë¤ÎÃÍ¤È CKSEL3 - 1 ¤Ë±þ¤¸¤Æ¡¢°Ê²¼¤ÎÍͤËÆ°ºî²Äǽ¼þÇÈ¿ôÈϰϤ¬·è¤Þ¤ê¤Þ¤¹

CKOPT CKSEL3 - 1 ¼þÇÈ¿ôÈÏ°Ï
1 101 0.4 - 0.9MHz
110 0.9 - 3.0MHz
111 3.0 - 8.0MHz
0 111 - 101 1.0MHz °Ê¾å

ËÜʸ½ñ¤Î²óÏ©¤Ç¤Ï 8MHz ¤Î³°Éô¿å¾½¿¶Æ°»Ò¤ò»È¤¤¡¢¥Ò¥å¡¼¥º¾å°Ì¥Ð¥¤¥È¤Ï¥Ç¥Õ¥©¥ë¥ÈÀßÄê¡ÊCKOPT = 1¡Ë¤Ç°·¤¦¤³¤È¤Ë¤¹¤ë¤¿¤á¡¢CKSEL3 - 1 = 111 ¤È¤·¤Þ¤¹¡£

¤Þ¤¿¡¢³°Éô¿¶Æ°»Ò¤Î¼ïÎà¤È¡¢Äã¾ÃÈñÅÅÎÏÆ°ºî¥â¡¼¥É¤«¤é¤Îµ¯Æ°ÃÙ±ä»þ´Ö¤¢¤ë¤¤¤Ï¥ê¥»¥Ã¥È¤«¤é¤ÎÃÙ±ä»þ´Ö¤Ë±þ¤¸¤Æ CKSEL0 ¤È SUT1 - 0 ¤òÁªÂò¤¹¤ëɬÍפ¬¤¢¤ê¤Þ¤¹¡£ËÜʸ½ñ¤Ç¤Ï¡¢³°Éô¿å¾½¿¶Æ°»Ò¡ÜÄã®Ω¤Á¾å¤¬¤êÅŸ»»ÈÍÑ»þ¤ÎÁȤ߹ç¤ï¤»¤Ç¤¢¤ë CKSEL0 = 1¡¢SUT1 - 0 = 11 SUT1 - 0 = 10 SUT1 - 0 = 11 ¤È¤·¤Þ¤·¤¿¡£ÅŸ»¤ÎΩ¤Á¾å¤¬¤ê»þ´Ö¤Ï¼Â¤ÏÉÔÌÀ¤Ê¤Î¤Ç¤¹¤¬Í¾Íµ¤¬¤¢¤ëÊý¤òÁª¤Ó¤Þ¤·¤¿¡£

2008/05/25 Äɵ­¡£±ÑÌõ¤·¤è¤¦¤È»×¤Ã¤Æ¥Ç¡¼¥¿¥·¡¼¥È¤ò¤¢¤é¤¿¤á¤Æ¸«¤Æ¤ß¤¿¤Î¤Ç¤¹¤¬¡¢Äã®Ω¤Á¾å¤¬¤êÅŸ»»ÈÍÑ»þ¤Î SUT1 - 0 ¤Ï 10 ¤È¤¹¤Ù¤­¤Ç¤·¤¿¡£SUT1 - 0 ¤ÎÁȤ߹ç¤ï¤»¤Ï¡¢BOD¡ÊÄãÅÅ°µ¸¡½Ð¥ê¥»¥Ã¥È¡ËÍ­¸ú»þ¤Ï 00¡¢¹â®Ω¤Á¾å¤¬¤êÅŸ»»ÈÍÑ»þ¤Ï 01¡Ê¥ê¥»¥Ã¥È»þ¤Ë 4.1ms ÃÙ±ä¡Ë¡¢Äã®Ω¤Á¾å¤¬¤êÅŸ»»ÈÍÑ»þ¤Ï 10¡Ê¥ê¥»¥Ã¥È»þ¤Ë 65ms ÃÙ±ä¡Ë¤¬¿ä¾©¤µ¤ì¤Æ¤¤¤Þ¤¹¡£11 ¤ÏͽÌóÃͤǤ·¤¿¡Ä¥µ¥ó¥×¥ë¤Î Makfile ¤Ï½¤Àµ¤·¤Æ¤ª¤­¤Þ¤·¤¿¡£

2008/05/26 ºÆ½¤Àµ¤Ç¤¹¡£ºòÆü¤Î½¤Àµ¼«ÂΤ¬´Ö°ã¤Ã¤Æ¤¤¤Þ¤·¤¿¡Ä³°Éô¿å¾½¿¶Æ°»Ò¡ÜÄã®Ω¤Á¾å¤¬¤êÅŸ»»ÈÍÑ»þ¤Ï¡¢SUT1 - 0 = 11 ¤Î¤Þ¤Þ¤Ç O.K. ¤Ç¤·¤¿¡£Àª¤¤Í¾¤Ã¤Æ³°Éô¥¯¥í¥Ã¥¯¿®¹æ»ÈÍÑ»þ¤ÎÀßÄê¤ò¸«¤Æ¤Þ¤·¤¿¡£¤´ÌÂÏǤò¤ª¤«¤±¤·¤Æ¤¹¤ß¤Þ¤»¤ó¡£¥µ¥ó¥×¥ë¤ÏºÆ½¤Àµ¤·¤Æ¤ª¤­¤Þ¤·¤¿¡£

¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤ÎÀßÄê¤Ï¡¢¸å½Ò¤¹¤ë uisp ¤È¤¤¤¦¥ª¡¼¥×¥ó¥½¡¼¥¹¥½¥Õ¥È¤òÍѤ¤¤Æ¹Ô¤¤¤Þ¤¹¡£

¡û »ÈÍѤ¹¤ë¥Ï¡¼¥É¥¦¥§¥¢

ËÜʸ½ñ¤Ç¤Ï¡¢PDIP ¥Ñ¥Ã¥±¡¼¥¸¤Î ATmega8535 ¤ò»ÈÍѤ·¤Þ¤¹¡£

ATmega8535(PDIP)

¢­¤¬¼Â¸³ÍѤ˺îÀ®¤·¤¿²óÏ©¤Ç¤¹¡£

¼Â¸³ÍѲóÏ©¤Î¼Ì¿¿

¢¬¤Î²óÏ©¿Þ¤Ï ¤³¤Á¤é ¤ËÃÖ¤¤¤Æ¤ª¤­¤Þ¤¹¡£Ëܼ¸³ÍѲóÏ©¤Ç¤Ï¡¢8MHz ¤Î³°Éô¿å¾½¿¶Æ°»Ò¤ò»ÈÍѤ·¤Þ¤¹¡£É®¼ÔºîÀ®¤Î²óÏ©¤Ç¤Ï¿å¾½¿¶Æ°»ÒÍѤΥ³¥ó¥Ç¥ó¥µ(²óÏ©¿Þ¾å¤Î 22pF ¤Î¥³¥ó¥Ç¥ó¥µ x 2) ¤¬¼è¤êÉÕ¤±¤é¤ì¤Æ¤¤¤Þ¤»¤ó¤¬¡¢¥¯¥í¥Ã¥¯¤Î°ÂÄê¤Î¤¿¤á¤Ë¤ÏÉÕ¤±¤ë¤Ù¤­¤Ç¤¹¤Î¤Ç¤ß¤Ê¤µ¤ó¤ÏÉÕ¤±¤Æ¤¯¤À¤µ¤¤¡Ä

ATmega8535 ¤Ç¤ÏºÇÂç 16MHz ¤ÇÆ°ºî¤µ¤»¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¤¬¡¢8MHz ¤«¤é¼þÇÈ¿ô¤òÊѹ¹¤¹¤ë¾ì¹ç¤Ï¡¢Á°½Ò¤Î¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤ÎÀßÄꤪ¤è¤Ó³Æ¥µ¥ó¥×¥ë¥×¥í¥°¥é¥à¤Ë¤ª¤±¤ë¥¯¥í¥Ã¥¯¼þÇÈ¿ô°Í¸Éôʬ¤ò½ñ¤­´¹¤¨¤Æ»ÈÍѤ·¤Æ¤¯¤À¤µ¤¤¡£

¤Ê¤ª¡¢ÅŸ»¤Ï 5V ½ÐÎϤΥ¹¥¤¥Ã¥Á¥ó¥°ÅŸ»¡ÊAC ¥¢¥À¥×¥¿¡Ë¤ò»È¤¤¤Þ¤·¤¿¡£

¢­¤Ï¼Â¸³ÍѲóÏ©¤È PC ¤òÀܳ¤¹¤ë¤¿¤á¤Î DAPA (Direct AVR Parallel Access) ¥±¡¼¥Ö¥ë¤Ç¤¹¡£

DAPA ¥±¡¼¥Ö¥ë¤Î¼Ì¿¿

AVR ¤È PC ¤ÎÀܳ¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤Ï¤¤¤í¤¤¤í¤¢¤ëÍͤǤ¹¤¬¡¢ËÜÊý¼°¤¬°ìÈÖ´Êñ¤Ê¤Î¤Ç¤³¤ì¤ò»È¤Ã¤Æ¤¤¤Þ¤¹¡£DAPA ¥±¡¼¥Ö¥ë¤ÎÇÛÀþ¿Þ¤Ï ¤³¤Á¤é ¤Ë¤ª¤¤¤Æ¤ª¤­¤Þ¤¹¡£DAPA ¥±¡¼¥Ö¥ë¤Ï¡¢PC ¤Î¥Ñ¥é¥ì¥ë¥Ý¡¼¥È¤È AVR ¤Î MOSI/MISO/SCK/RESET ¥Ô¥ó¡ÊPDIP ¥Ñ¥Ã¥±¡¼¥¸¤Î¾ì¹ç¤Ï¤½¤ì¤¾¤ì 6/7/8/9 ÈÖ¥Ô¥ó¡Ë¤òÀܳ¤·¤Þ¤¹¡£¤³¤Î¥±¡¼¥Ö¥ë·Ðͳ¤Ç¥×¥í¥°¥é¥à¤Î¥¢¥Ã¥×¥í¡¼¥ÉÅù¤ò¹Ô¤¤¤Þ¤¹¡£MOSI/MISO/SCK/RESET ¥Ô¥ó¤Ë¤è¤ë¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤ò¥·¥ê¥¢¥ë¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤È¸Æ¤Ó¡¢¥·¥ê¥¢¥ë¥¤¥ó¥¿¥Õ¥§¡¼¥¹¤òÍѤ¤¤¿ AVR ¤Î¥×¥í¥°¥é¥ß¥ó¥°¤ò¥·¥ê¥¢¥ë¥×¥í¥°¥é¥ß¥ó¥°¤È¸À¤¤¤Þ¤¹¡£ËÜʸ½ñ¤Ç¤Ï¡¢¥·¥ê¥¢¥ë¥×¥í¥°¥é¥ß¥ó¥°¤Ë¤Ï¸å½Ò¤¹¤ë uisp ¤È¤¤¤¦¥ª¡¼¥×¥ó¥½¡¼¥¹¥½¥Õ¥È¤ò»È¤¤¤Þ¤¹¡£

¡û »ÈÍѤ¹¤ë¥½¥Õ¥È¥¦¥§¥¢

ËÜʸ½ñ¤Ç¤Ï¡¢Linux ® ¾å¤Ç avr-gcc ¤òÍѤ¤¤Æ C ¸À¸ì¤Ë¤è¤ê¥×¥í¥°¥é¥à¤òºîÀ®¤·¤Þ¤¹¡£¶ñÂÎŪ¤Ë¤Ï°Ê²¼¤Î¥½¥Õ¥È¥¦¥§¥¢¤ò»ÈÍѤ·¤Þ¤¹¡£1 - 3 ¤ÏƳÆþ½ç¤òɽ¤·¤Þ¤¹¡£uisp ¤ÏƳÆþ¤Î½çÈÖ¤ÏÆä˴ط¸¤¢¤ê¤Þ¤»¤ó¡£

  1. GNU Binutils

    ¥¢¥»¥ó¥Ö¥é¤ä¥ê¥ó¥«Åù¤Î´ðËÜŪ¤Ê¥×¥í¥°¥é¥ß¥ó¥°¥Ä¡¼¥ë¤òÄ󶡤¹¤ë¥½¥Õ¥È¥¦¥§¥¢¤Ç¤¹¡£ËÜʸ½ñ¤Ç¤Ï¥Ð¡¼¥¸¥ç¥ó 2.17 ¤ò»ÈÍѤ·¤Þ¤¹¡£¥À¥¦¥ó¥í¡¼¥É¸å

    cd [Ÿ³«¤·¤¿ binutils ¤Î¥È¥Ã¥×]
    ./configure --target=avr --program-prefix='avr-' --disable-nls; make
    
    

    ¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¸å¡¢root ¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤¯¤À¤µ¤¤¡£

  2. GCC

    GNU ¤¬³«È¯¤·¤Æ¤¤¤ë¥³¥ó¥Ñ¥¤¥é¥³¥ì¥¯¥·¥ç¥ó¤Ç¤¹¡£ËÜʸ½ñ¤Ç¤Ï¥Ð¡¼¥¸¥ç¥ó 4.1.2 ¤ò»ÈÍѤ·¤Þ¤¹¡£¥À¥¦¥ó¥í¡¼¥É¸å

    cd [Ÿ³«¤·¤¿ gcc ¤Î¥È¥Ã¥×]
    ./configure --target=avr --program-prefix='avr-' --enable-languages=c \
               --with-dwarf2 --disable-nls --disable-libssp; make
    
    

    ¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¸å¡¢root ¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤¯¤À¤µ¤¤¡£

  3. AVR LibC

    AVR ¥¢¡¼¥­¥Æ¥¯¥Á¥ã¤Ç»ÈÍѲÄǽ¤Ê libc ¤òÄ󶡤¹¤ë¥½¥Õ¥È¥¦¥§¥¢¤Ç¤¹¡£ËÜʸ½ñ¤Ç¤Ï¥Ð¡¼¥¸¥ç¥ó 1.4.5 ¤ò»ÈÍѤ·¤Þ¤¹¡£¥À¥¦¥ó¥í¡¼¥É¸å

    cd [Ÿ³«¤·¤¿ avr-libc ¤Î¥È¥Ã¥×]
    ./configure --build='./config.guess' --host=avr; make
    
    

    ¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¸å¡¢root ¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤¯¤À¤µ¤¤¡£

  4. uisp

    ¥×¥í¥°¥é¥à¤Î¥¢¥Ã¥×¥í¡¼¥É¡¿¥Ò¥å¡¼¥º¥Ó¥Ã¥È¤ÎÀßÄêÅù¤Î PC ¤È AVR ¤Î´Ö¤ÎÄÌ¿®ºî¶È¤ò¹Ô¤Ã¤Æ¤¯¤ì¤ë¥½¥Õ¥È¥¦¥§¥¢¤Ç¤¹¡£ËÜʸ½ñ¤Ç¤Ï¥Ð¡¼¥¸¥ç¥ó 20050207 ¤ò»ÈÍѤ·¤Þ¤¹¡£¥À¥¦¥ó¥í¡¼¥É¸å

    cd [Ÿ³«¤·¤¿ uisp ¤Î¥È¥Ã¥×]
    ./configure; make
    
    

    ¤È¤·¤Æ¥³¥ó¥Ñ¥¤¥ë¸å¡¢root ¤Ç¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¤¯¤À¤µ¤¤¡£