ã¯ããã«
ç§ã®æèŠã§ã¯ãäžçã«ååšããã»ãšãã©ãã¹ãŠã®ãã€ã¯ãã³ã³ãããŒã©ãŒã®ããã°ã©ãã³ã°ãè¿ éã«åŠç¿ããã«ã¯ãæè¡ææžã®åŠç¿ã«å ããŠãCèšèªãç¿åŸããJTAGãããã°ã䜿çšããå¿ èŠããããŸãã ç§ã®èãã説æããŸãã Cèšèªã³ã³ãã€ã©ã¯ãæ¢åã®ã»ãšãã©ãã¹ãŠã®ãã€ã¯ãã³ã³ãããŒã©ãŒã«å¯Ÿå¿ããŠããŸãã ãã®ãããèšèªCã¯ã¯ãã¹ãã©ãããã©ãŒã ã¢ã»ã³ãã©ãŒãšããŠã®å°äœã確ç«ããŠããŸãã 圌ã®ç¥èã«ããããã€ã¯ãã³ã³ãããŒã©ã®æ°ãããã¡ããªããšã«ã¢ã»ã³ããªæé ãåŠã¶å¿ èŠããªããªããŸãã JTAGãããã°ã¯ãã€ã³ãµãŒããããšã©ãŒæ€çŽ¢ã®å¯èœæ§ãæäŸããã ãã§ãªããå éšãããã€ã¯ãã³ã³ãããŒã©ãŒã調æ»ããã®ã«ã圹ç«ã¡ãŸãã åçŽãªãã€ã¯ãã³ã³ãããŒã©ã§ãããããã°ããã«åçŽã«ããã°ã©ãã³ã°ããå Žåãå ¥åãšåºåãåãããã©ãã¯ããã¯ã¹ãšããŠã·ã¹ãã ã®ç 究ã«ã¢ãããŒãããããšã¯èª°ã«ãšã£ãŠãæããã ãšæããŸãã ãã®ã¢ãããŒãã¯ãç¹ã«åæ段éã§ã¯ãåŠç¿ãå°é£ã«ããŸãã äžæ¹ãJTAGã䜿çšãããšãå éšã«å ¥ããããã°ã©ã ã段éçã«å®è¡ãããæ¹æ³ã確èªããã¡ã¢ãªãšã¬ãžã¹ã¿ã§äœãèµ·ãããã確èªãããã¬ãŒã¯ãã€ã³ããžã®è奮ãéå§ããããã°ã©ã ã®éã¢ã»ã³ãã«ãããããŒãžã§ã³ãå®è¡ã§ããŸãã ãã®æ©èœã«ãããåŠç¿ãå€§å¹ ã«ã¹ããŒãã¢ããã§ããŸãã
AVRãSTM8ãMSP430ãAVR32ãSTM32ãEFM32ãRenesas RXãªã©ã®ãã€ã¯ãã³ã³ãããŒã©ãŒã«ã¯ãCèšèªã³ã³ãã€ã©ãšJTAGã€ã³ã¿ãŒãã§ã€ã¹ã䜿çšãããããã°ããããŸãã ãããã®å€ãã®ãã€ã¯ãã³ã³ãããŒã©ãŒã®åäžã®ã¯ãã¹ãã©ãããã©ãŒã ç°å¢ã¯ãEmbedded Workbenchã§ãã ç°å¢ã¯ææã§ããã30æ¥éã®ç¡æããŒãžã§ã³ãŸãã¯ã³ãŒããµã€ãºå¶éã®ããããŒãžã§ã³ã䜿çšããããšãã§ããŸãã ä»æã®æ°ãã家æã®æåã®ç 究ã®ããã«ååãããããŸããã ãã®åŸã家æã«ã€ããŠæ±ºå¿ããç¡æã®ããŒã«ã§å®¶æãšäžç·ã«ä»äºãç¶ããããå°èŠæš¡ãããžã§ã¯ãã®å Žåã¯ãµã€ãºãå¶éãããŠããããŒãžã§ã³ã®ã³ãŒãã䜿çšãããã決å®ã§ããŸãã 倧èŠæš¡ãªåçšè£œåã®å Žåã¯ããã®åªäœãè³Œå ¥ã§ããŸãã
ãŸããAVRãSTM8ãMSP430ãã¡ããªãŒã§åŠç¿ãéå§ããããšããå§ãããŸãã ãããã®ãã€ã¯ãã³ã³ãããŒã©ã®åäœã¯ãæ¯èŒçåçŽãªã³ãã³ãã·ã¹ãã ãå°æ°ã®ããã»ããµã¬ãžã¹ã¿ããã³åšèŸºæ©åšãåããŠãããããç解ã容æã§ãã ç°¡åãªäŸãäœæããåŸã ã«ç¬èªã®ã©ã€ãã©ãªãäœæããããšããå§ããæ¹ãè¯ãã§ãããã ããã¯ãã¹ãŠé ã§ããèŠãããŠããŸãã æåã®ç¥ãåãã«ãšã£ãŠãããã¯éåžžã«æåããŠããŸãã
以äžã§èª¬æããäŸã§ã¯ãAVRããã€ã¯ãã³ã³ãããŒã©ã®äžçã§æã人æ°ã®ãããã¡ããªã§ãããããAVRãéžæããŸããã å§ããã®ã¯ç°¡åã ãšæããŸãããããã«éå®ããã¹ãã§ã¯ãããŸããã
JTAGãããã¬ãŒã®éžæ
Cã§èšè¿°ãããããã°ã©ã ã®ã€ã³ãµãŒããããããã°ã«ã¯ãAVRãã€ã¯ãã³ã³ãããŒã©ãŒçšã®JTAGãããã¬ãŒãå¿ èŠã§ãã æãæé ãªäŸ¡æ Œã§è£œé ã容æãªã®ã¯ãAVR JTAGICEç¬èªã®ãããã¬ãŒã®ã¯ããŒã³ã§ãã ãã®ãããªã¯ããŒã³ã¯ã eBayã§äœäŸ¡æ Œã§æ³šæã§ããŸãã å質ã¯å®ããã®ãããªãã®ã§ãã
ã¯ããŒã³ã¯ãããšãã°Olimexã«ãã£ãŠãçæãããŸã ã COMããŒããä»ããŠã³ã³ãã¥ãŒã¿ãŒã«æ¥ç¶ããã¯ã©ã·ãã¯ããŒãžã§ã³ãšãUSBã€ã³ã¿ãŒãã§ã€ã¹ãä»ããæ¥ç¶ã®æ°ããããŒãžã§ã³ããããŸãã
ãã®ãããªã¯ããŒã³ã®å人çç£ã§ã¯ãç¬èªã®ããªã³ãåºæ¿ãäœæã§ããªãå ŽåãDIPã³ã³ããŒãã³ãã®ã¿ã䜿çšã§ãããããã€ã³ã¹ããŒã«ãç°¡åã«ãªããŸãã JTAGICEã¯ããŒã³ãå«ãåæããŒãžã§ã³ã®Evertool㯠ããã®ããã«ããŠäœæãããŸããã
]
ã»ãšãã©ã®JTAGICEã¯ããŒã³ã¯ã次ã®å³ã«ç€ºãå³ã«åºã¥ããŠããŸãã ããæ£ç¢ºã«ã¯ãJTAGICEã»ã¯ã·ã§ã³ãšåŒã°ããéšåã§ãã ãããã¬ãŒã®ã³ã¢ã¯Atmega16Lãã€ã¯ãã³ã³ãããŒã©ãŒã§ãã JTAGICEã¯ããŒã³ãUSBçµç±ã§æ¥ç¶ãããå Žåã¯ã MAX3232ã¬ãã«å€æããããFTDI FT232ãããã«å€æŽããŸãã ãã ããFT232ã¯DIPããã±ãŒãžã§ãªãªãŒã¹ãããŠãããããã®ããããæèŒããDIPã¢ãžã¥ãŒã«ã®äŸ¡æ Œã¯éåžžã«é«ããªã£ãŠããŸãã ãããã£ãŠãããã§ã¯ã1ã€ã®åè·¯åºæ¿ãšDIPã³ã³ããŒãã³ãã ãã§éããããšã¯ã§ããŸããã 现ãã¯ã€ã€ãŒã§FT232ããã¬ããããŒãã«ã¯ãã ä»ãããããå¡©çŽ ãå«ãéåžžã®ãããããªã³ãã§åå±€ã®ããªã³ãåè·¯åºæ¿ããšããã³ã°ããå¿ èŠããããŸãã
ãã¡ãŒã ãŠã§ã¢ã¯ãAVR Studio 4ã®ã€ã³ã¹ããŒã«ãã©ã«ããŒã«ãããã ããããããŠã³ããŒãã§ããŸã ã
äžèšã®JTAGICEã¯ããŒã³ã®æ¬ ç¹ã¯ã AVR Studio 6ã§ãµããŒããããŠããªãããšã§ãã ãã ããAVR Studio 4ã®å€ãããŒãžã§ã³ãšAVRçšIARã®å€ãããŒãžã§ã³ãšæ°ããããŒãžã§ã³ã§ã¯ããããã®ã¯ããŒã³ã¯ååã«ãµããŒããããŠããŸãã
åŸã§æžãããCã³ãŒãäŸããããã°ããããã«ããã®ã¹ããŒã ã«åŸã£ãŠäœæãããã¯ããŒã³ã䜿çšããŸããã ãã®äžã®MAX3232ãããã¯ãæ¬è³ªãå€ããªãADM3202ã®ä»£æ¿åã§ãã
JTAGICEã®ãã®ã¯ããŒã³ã¯ç§ã«åŒãç¶ãããŸããã ç§ã¯è·å Žã§é»åå»æ£ç©ã®å ¥ã£ãç®±ãèŠã€ããŸããã ããŸããããªãã£ãã®ã§ãåãã©ãã·ã¥ããããšã«ããŸããã åçã«èŠãããããã«ãAtmega16Lãããã°ã©ãã³ã°ããããã®AVR ISPã³ãã¯ã¿ã¯ãµã€ãºãçž®å°ããããã«åºåãããªãããããªãç¹å¥ãªã¢ããã¿ãäœæããå¿ èŠããããŸãããã ãã¡ãŒã ãŠã§ã¢ã®åŸãJTAGICEã¯ãæ»åŸã®äžçãã®å¯¿åœãç²åŸããç²åŸããŸããã
COMããŒããæ代é ãã«ãªã£ãä»ãç§ã¯ãæ§åããæšãŠããUSB-RS-232ã±ãŒãã«ã³ã³ããŒã¿ãŒãè³Œå ¥ããŸãã ã
ãããã°ããŒã
ãããã°ããŒããšããŠããã¬ããããŒãã«çµã¿ç«ãŠãããžã¿ã«æž©åºŠèšã䜿çšããŸãã ããŒãã¯USBã§é§åãããã³ã¢ã¯DIPããã±ãŒãžã®Atmega16ãã€ã¯ãã³ã³ãããŒã©ãŒã§ãã ãã€ã¯ãã³ã³ãããŒã©ãŒã¯ãåšæ³¢æ°ã16 MHzã®æ°Žæ¶æ¯ååããã¯ããã¯ãäŸçµŠãããå¿ èŠæå°éã®ååéšåã®ã»ããïŒæ°Žæ¶ã®å Žåã¯22 pFã³ã³ãã³ãµããªã»ããã©ã€ã³ãé»æºã«ãã«ããããã®10kΩæµæãé»æºã®å Žåã¯0.1ÎŒFã³ã³ãã³ãµïŒã§çµã°ããŸãã ãã€ã¯ãã³ã³ãããŒã©ã®æšæºããã°ã©ãã³ã°ããã³ãããã°çšã«ã2ã€ã®æšæº6ãã³AVR ISPããã³10ãã³AVR JTAGãœã±ãããåãä»ããããŠããŸãã ããŒãã«ã¯ãã¢ããã°æž©åºŠã»ã³ãµãŒã3æ¡ã®éç7ã»ã°ã¡ã³ãã€ã³ãžã±ãŒã¿ãããã³è¿œå ã®LEDããããŸãã 衚瀺LEDããã³ã€ã³ãžã±ãŒã¿ã»ã°ã¡ã³ãã¯ã500ãªãŒã ã®é»æµå¶éæµæåšãä»ããŠãã€ã¯ãã³ã³ãããŒã©ã«æ¥ç¶ãããŠããŸãã 3ã€ã®7ã»ã°ã¡ã³ãã€ã³ãžã±ãŒã¿ãŒã¯ãããããããŒãAãBãDã®ããããã®ç«¯å0ãã6ã«æ¥ç¶ãããŸããLEDã¯ããŒãDã®7çªç®ã®ç«¯åã«æ¥ç¶ãããŸããã¢ããã°ã»ã³ãµãŒåºåã¯ããŒãAã®7çªç®ã®ç«¯åã«æ¥ç¶ãããŸãïŒå èµADCã®ãã£ã³ãã«7 ïŒ
ãã¹ãŠã®èŠçŽ ã¯MGTFã¯ã€ã€ã§ã¯ãã ä»ããããŸããã
IARéçºç°å¢
ããã°ã©ã ã®äœæãšãããã°ã«ã¯ãAtmel AVRç°å¢çšã®IAR Embedded Workbenchãã€ãŸãã³ãŒããµã€ãºå¶éã4 Kbã®ç¡æããŒãžã§ã³ã䜿çšããŸãã AVRãã¡ããªãŒã®ãã€ã¯ãã³ã³ãããŒã©ãŒçšã®Cèšèªã®å°ããªãããžã§ã¯ãã®å Žåãããã§ååã§ãã
ããã«è¡ã£ãŠãçŸåšã®AVRçšIARã®ææ°ããŒãžã§ã³ãæäŸãããã®ãèªãã§ã¿ãŸãããã åè¿°ã®JTAGICEãããã¬ãŒã¯ã以åãšåæ§ã«ãµããŒããããŠããŸãã
ãµããŒãããããã¡ããªã®ãªã¹ãã«ã¯ãmegaAVRãå«ãŸããŸãã
JTAGãããã¬ãŒãšãããã°ããŒããåäœããããšã確èªããåŸãIARãããŠã³ããŒãããŸã ã
ã€ã³ã¹ããŒã©ãŒã䜿çšãããšãããã¯ã¹ã¿ãŒãã©ã€ã»ã³ã¹ã«ç»é²ã§ããŸãã
ã€ã³ã¹ããŒã«åŸãIARãç»é²ããã«ã¯ãç»é²ãã©ãŒã ã«èšå ¥ããå¿ èŠããããŸãã
ã¢ã³ã±ãŒããžã®èšå ¥åŸãããŒãã¡ãŒã«ã«å±ããŸããããŒãå ¥åãããšãç¡æã®ç»é²æžã¿ããã¯ã¹ã¿ãŒãããŒãžã§ã³ãç¡å¶éã«å±ããŸãã
ã¿ã¹ã¯çšã®ç©ºã®ãããžã§ã¯ããäœæããŸãã AVR Studio 4ã䜿çšããŠåºå16é²ãã¡ã€ã«ããã©ãã·ã¥ããå¿ èŠãããå Žåã«åããŠãCèšèªãšãªãã·ã§ã³AVR Studio 4äºæåºåãéžæããŸãã
èšèªãéžæãããšãå®å šã«ç©ºã®ã»ãŒç©ºã®ãœãŒã¹ãã¡ã€ã«ã衚瀺ãããŸãã
ãããžã§ã¯ãã®èšå®ã«ç§»ããŸãããã ãªããªã Atmega16ã®ããã°ã©ã ãäœæããããã»ããµãŒæ§æã®åã§ãã®ãã€ã¯ãã³ã³ãããŒã©ãŒãéžæããŸãã
[ãããã¬]ã¡ãã¥ãŒé ç®ã§ã[JTAGICE]ãéžæããŸãã
ãããã¬ãŒ-> JTAGICEã®ã¡ãã¥ãŒé ç®ã§ããããã¬ãŒãæ¥ç¶ãããŠããCOMããŒãçªå·ãéžæããŸãã
ç°å¢ã©ã€ãã©ãªãŒå ã®ãã€ã¯ãã³ã³ãããŒã©ãŒã®åšèŸºã¬ãžã¹ã¿ãŒã®éèŠãªãããã®å®çŸ©ãæ£ããåäœãããã«ã¯ã以äžãè¡ãå¿ èŠããããŸãã
[å šè¬ãªãã·ã§ã³]-> [ã·ã¹ãã ]ã¡ãã¥ãŒé ç®ã®[I / O-Include files]ãã§ãã¯ããã¯ã¹ã§ãããå®çŸ©ãæå¹ã«ããŸãã
ããã°ã©ãã³ã°ãšãããã°
äŸã®èª¬æãå§ããåã«ãIARç°å¢ã®ããã€ãã®æ©èœã説æããå¿ èŠããããŸãã Atmega16ã®ã¬ãžã¹ã¿ã¢ãã¬ã¹å®çŸ©ãå«ãiom16.hããããŒãã¡ã€ã«ã«ã¯ã次ã®ããã«å éšåšèŸºã¬ãžã¹ã¿ã®ç¹å®ã®ãããã«ã¢ã¯ã»ã¹ã§ãããã¯ããå«ãŸããŠããŸãã
... * Examples of how to use the expanded result: * TCCR2 |= (1<<5); * or if ENABLE_BIT_DEFINITIONS is defined * TCCR2 |= (1<<COM21); * or like this: * TCCR2_Bit5 = 1; * or like this: * TCCR2_COM21 = 1; ***************************************************************************/
å®éããããã®ãªãã·ã§ã³ã®ããããã䜿çšã§ããŸãã å®éãããã§ã®éžæã¯ãç¹å®ã®ãªãã·ã§ã³ã䜿çšããããšã®å©äŸ¿æ§ãšãæžãããŠããå 容ã®ãã®åŸã®ç解ã®åçŽãã§ãã
IARç°å¢ã§ã¯ã__ delay_cyclesïŒxïŒçµã¿èŸŒã¿é 延é¢æ°ã䜿çšã§ããŸããxã¯ãã£ãã¯åäœã®é 延æéã§ãã ãã®å Žåã1ã¯ããã¯ãµã€ã¯ã«ã®é 延ã¯1/16000000 = 62.5 nsã§ãã
ãããã®2ã€ã®ãã€ã³ããããã£ãã®ã§ãæä»çè«çåã䜿çšããŠLEDãåçŽã«ç¹æ» ããæåã®äŸã«é²ã¿ãŸãã
/* */ #include <ioavr.h> #include <intrinsics.h> /* */ // #define F_CPU 16000000 /* */ // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // void main( void ) { // // // 7- D DDRD_DDD7 = 1; // 7- D "0" PORTD_PORTD7 = 0; // for(;;) { // 7- D "0" "1" "1" "0" // PORTD_PORTD7 ^= 1; // DELAY_MS(1000); }//end for }
å¿ èŠãªæéã®é 延ã®åœ¢æãç°¡çŽ åããããã«ãé 延ãã¯ãé¢æ°DELAY_USïŒusïŒããã³DELAY_MSïŒmsïŒãäœæããŸããããã«ããããµã€ã¯ã«ã§ã¯ãªããã€ã¯ãç§ããã³ããªç§åäœã§é 延ãèšå®ã§ããŸãã 次ã«ãã¡ã€ã³ïŒïŒããã°ã©ã ã®ã¡ã€ã³é¢æ°ã«ç§»åããŸãããã®é¢æ°ã¯ããã€ã¯ãã³ã³ãããŒã©ãŒããªã³ã«ããåŸããŸãã¯ãªã»ããåŸã«ååŸããŸãã ã¹ã€ãããå ¥ããåŸã«æåã«ãã¹ãããšã¯ããã®ã±ãŒã¹ã§ã¯åäœã«å¿ èŠãªåšèŸºãããã¯ãæ§æããããšã§ããããã¯ããŒãDã®1ã€ã®ãã³ã®ã¿ã§ãããã³ã«æ§æããã«ã¯ãDDRDããŒã¿æ¹åã¬ãžã¹ã¿ã®DDD7ãããã1ã«èšå®ããã ãã§ãã 足ã«ã1ãïŒ5 VïŒãèšå®ããã«ã¯ãPORTDããŒã¿ã¬ãžã¹ã¿ã®PORTD7ããããèšå®ããå¿ èŠããããŸãã足ã«ã0ãïŒã°ã©ã³ãïŒãèšå®ããã«ã¯ãPORTD7ãããããªã»ããããå¿ èŠããããŸãã 詳现ã«ã€ããŠã¯ã ããŒã¿ã·ãŒããã芧ãã ããã
å¶åŸ¡ã¬ãžã¹ã¿DDRDããã³PORTDã®ããããèšå®ããã³æžã蟌ãããã«ããããåäœã®åé¢ããã³çµåãªãã§åã«æžã蟌ãïŒDDRD = 0x01ãDDRD = 0x00ïŒã®ã¯æãŸãããããŸããïŒDDRD | = 0x01ãDDRDïŒ=ã0x01ãDDRD | =ïŒ1 << 0ïŒã DDRDïŒ=ãïŒ1 << 0ïŒïŒãããã«ããããã®æäœã®åã«èšå®ãããã¬ãžã¹ã¿ã®æ®ãã®ããããæ¶å»ãããããã§ãã ãããç解ããããšãéèŠã§ãã
調æŽåŸãã¡ã€ã³ã®ç¡éforïŒ;;ïŒã«ãŒãã«å ¥ããŸãããã®ã«ãŒãã§ã¯ãååãšããŠãã¡ã€ã³ããã°ã©ã ããžãã¯ãå®è¡ãããŸãã ãã€ã¯ãã³ã³ãããŒã©ããã°ã©ã ãå®è£ ãããã®ãããªã¢ãã«ã¯ãã¹ãŒããŒãµã€ã¯ã«ã·ã¹ãã ãšåŒã°ããŸãã ãã®ç¡éãµã€ã¯ã«ã¯ãåšèŸºãŠãããã®åŠçã®äžæäžããã³äœæ¶è²»é»åã¢ãŒããžã®åãæ¿ãäžã¯äžæåæ¢ããããã€ã¯ãã³ã³ãããŒã©ãŒããªã»ãããããŠãªãã«ãªã£ãå Žåã«ã®ã¿åæ¢ããŸãã
ã¡ã€ã³ã®ç¡éã«ãŒãã§ã¯ãorãé€ããããæŒç®ã䜿çšããŠãã0ãããã1ããžã次ã«ã1ãããã0ããžã®äžå®ã®åãæ¿ãããããŸãã ããã¯ããã¯ãé¢æ°DELAY_MSïŒmsïŒã«ãã£ãŠæäŸããã1ç§ã®é 延ã§çºçããŸãã
次ã«ãJTAGICEã䜿çšããŠãã®äŸãããŒãããŠãããã°ããŸãã ãããè¡ãã«ã¯ã[ãããžã§ã¯ã]-> [ããŠã³ããŒããšãããã°]ã¡ãã¥ãŒé ç®ãã¯ãªãã¯ããããCtrl + DããŒãæŒãããèµ€ãäžè§åœ¢ã®ã¢ã€ã³ã³ãã¯ãªãã¯ããŸãããã®åŸãã³ãŒãã«æ§æãšã©ãŒããªãå Žåãã¹ããããã€ã¹ãããã®ã³ãã³ãã䜿çšã§ãããããã°ã¢ãŒãã«åãæ¿ããŸãããªãŒããŒãã¹ãããã€ã³ãã¹ãããã¢ãŠãã次ã®ã¹ããŒãã¡ã³ãã移åããªã»ããã ããã«ããã¬ãŒã¯ãã€ã³ãã䜿çšããå¯èœæ§ããããŸãã ããã«ãããããã°ã©ã ãã¹ãããããšã«å®è¡ããããŒãDã®ããã»ããµã¬ãžã¹ã¿ãšDDRDããã³PORTDã¬ãžã¹ã¿ã®åã¹ãããã§äœãèµ·ãããã確èªããå®è¡ããŠããåæ¢ãããã¬ãŒã¯ãã€ã³ããŸã§éå§ã§ããŸãã ããã¯ãã¹ãŠããšã©ãŒãèŠã€ããããã®ããŒã«ãæäŸããã ãã§ãªãããã€ã¯ãã³ã³ãããŒã©ãŒã®åäœãããããç解ããã®ã«ã圹ç«ã¡ãŸãã 圌ãšããéãåãããšãåŠã³ãªããã
2çªç®ã®äŸãLEDã®ç¹æ» ã§ãããè¿œå ã®ãã¯ãæ©èœã䜿çšããŠããŸãã
/* */ #include <ioavr.h> #include <intrinsics.h> /* */ // #define F_CPU 16000000 // #define DELAY_TIME 1000 // // #define LED_DDR DDRD #define LED_PORT PORTD #define LED_PIN DDD7 /* */ // #define LED_INIT() ( LED_DDR |= (1<<LED_PIN) ); // #define LED_LOW() ( LED_PORT &=~ (1<<LED_PIN) ); // #define LED_HIGH() ( LED_PORT |= (1<<LED_PIN) ); // #define LED_TOG() ( LED_PORT ^= (1<<LED_PIN) ); // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // void main( void ) { // // LED_INIT(); // LED_LOW(); // for(;;) { // LED_TOG(); // DELAY_MS(DELAY_TIME); }//end for }
ãã¯ãé¢æ°ã¢ãããŒãã¯ã2ã€ã®æ¹æ³ã§äŸ¿å©ã«ãªããŸãã 1ã€ã¯ãã³ãŒãã®å¯èªæ§ãåäžãããããšã§ãã 2ã€ç®ã¯ãå¯èœãªä¿®æ£ã®ç°¡çŽ åã§ãã ããã§ãLEDãå¥ã®ããŒãã®å¥ã®ãã³ã«åæ§æããå¿ èŠãããå Žåã¯ãLED_DDRãLED_PORTãLED_PINã®3ã€ã®å®çŸ©ãå€æŽããããã°ã©ã ããã¹ãå šäœãä¿®æ£ããªãã§ãã ããã ã©ã€ãã©ãªãæžããšããããã¯äººçã倧ãã«åçŽåããŸãã
3çªç®ã®äŸã¯ãã¹ããŒããã·ã³ã䜿çšããç¹æ» LEDã®å®è£ ã§ãã ã¹ããŒããã·ã³ã¯ãçŸåšã®ç¶æ ã«å¿ããŠãšã³ãã¬ã¹ãµã€ã¯ã«ããã©ã³ãã«åå²ããããã€ã¯ãã³ã³ãããŒã©ãŒãã¡ãŒã ãŠã§ã¢ã¢ãã«ãå®è£ ããããã®ãªãã·ã§ã³ã®1ã€ã§ãã
/* */ #include <ioavr.h> #include <intrinsics.h> /* */ // #define F_CPU 16000000 // #define DELAY_TIME_LF 1000 #define DELAY_TIME_AF 500 #define DELAY_TIME_HF 100 // #define LIMIT_CNT_LF 4 #define LIMIT_CNT_AF 8 #define LIMIT_CNT_HF 40 // #define UCHAR unsigned char // #define STATE_LOW_FREQ_BLINK 0 #define STATE_AVR_FREQ_BLINK 1 #define STATE_HIGH_FREQ_BLINK 2 // // #define LED_DDR DDRD #define LED_PORT PORTD #define LED_PIN DDD7 /* */ // #define LED_INIT() ( LED_DDR |= (1<<LED_PIN) ); // #define LED_LOW() ( LED_PORT &=~ (1<<LED_PIN) ); // #define LED_HIGH() ( LED_PORT |= (1<<LED_PIN) ); // #define LED_TOG() ( LED_PORT ^= (1<<LED_PIN) ); // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // UCHAR curr_state = STATE_LOW_FREQ_BLINK; // // UCHAR state_cnt = 0; /* */ // void main( void ) { // // LED_INIT(); // LED_LOW(); // for(;;) { // switch(curr_state) { // case STATE_LOW_FREQ_BLINK: // LED_TOG(); // DELAY_MS(DELAY_TIME_LF); // state_cnt++; // //, if (state_cnt==LIMIT_CNT_LF) { curr_state = STATE_AVR_FREQ_BLINK; // state_cnt = 0; }//end if break; // case STATE_AVR_FREQ_BLINK: // LED_TOG(); // DELAY_MS(DELAY_TIME_AF); // state_cnt++; // //, if (state_cnt==LIMIT_CNT_AF) { curr_state = STATE_HIGH_FREQ_BLINK; // state_cnt = 0; }//end if break; // case STATE_HIGH_FREQ_BLINK: // LED_TOG(); // DELAY_MS(DELAY_TIME_HF); // state_cnt++; // //, if (state_cnt==LIMIT_CNT_HF) { curr_state = STATE_LOW_FREQ_BLINK; // state_cnt = 0; }//end if break; } }//end for }
ãã®äŸã§ã¯ãSTATE_LOW_FREQ_BLINKãSTATE_AVR_FREQ_BLINKãSTATE_HIGH_FREQ_BLINKã®3ã€ã®ç¶æ ããããããããäœåšæ³¢æ°ãäžåšæ³¢æ°ãé«åšæ³¢æ°ã®LEDã®ç¹æ» ã«å¯Ÿå¿ããŠããŸãã åç¶æ ã«ã¯ãåç¶æ ãã¹ã§å®è¡ãããç¬èªã®é 延å€DELAY_TIME_LFãDELAY_TIME_AFãDELAY_TIME_HFããããŸãã åç¶æ ã«ããåãæéã¯ãLIMIT_CNT_LFãLIMIT_CNT_AFãLIMIT_CNT_HFã®å®çŸ©ã«ãã£ãŠæäŸãããåç¶æ ã®åãæ¿ããã¹ã®æ°ã決å®ããŸãã switchã¹ããŒãã¡ã³ãã¯ãcurr_stateå€æ°ã®çŸåšã®å€ã«åŸã£ãŠç¶æ éã®åãæ¿ããæäŸããŸãã state_cntå€æ°ã¯ãç¶æ åãæ¿ãå¶éã«éãããŸã§ãåç¶æ ãã¹ã§å¢åãããŸãã ifã¹ããŒãã¡ã³ãã¯ãåãæ¿ãå¶éã«éãããã©ãããå€å¥ããŸãã å¶éã«éãããšã次ã®ç¶æ ãžã®é·ç§»ãçºçããstate_cntãã¹ã«ãŠã³ã¿ãŒããªã»ãããããŸãã
ãããã°äžã«ãäžèšã§æ¢ã«èª¬æããããšã«å ããŠãView-> Watchã§curr_stateãšstate_cntå€æ°ã®å€ãèŠãããšãã§ããŸãã
4çªç®ã®äŸã¯ããã€ã¯ãã³ãããŒã©ãŒã®8ãããã¿ã€ããŒïŒTIMER0ïŒã䜿çšããããšãç®çãšããŠããŸãã ãã®äŸã§ã¯ãããŒãDã®6çªç®ã®ãã³ã«æ¥ç¶ããã7ã»ã°ã¡ã³ãã€ã³ãžã±ãŒã¿ãŒã»ã°ã¡ã³ãã®1ã€ã2çªç®ã®LEDãšããŠäœ¿çšãããŸãã
/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> /* */ // #define F_CPU 16000000 // #define TCNT0_VALUE 99 // #define T0_TICK_CNT_LIMIT 100 // #define UINT unsigned int /* */ // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // T0 UINT T0_tick_cnt=0; /* */ // void main( void ) { // // // 6- D DDRD_DDD6 = 1; // 6- D "0" PORTD_PORTD6 = 0; // // 7- D DDRD_DDD7 = 1; // 7- D "0" PORTD_PORTD7 = 0; // ( Normal) TCCR0_CS02=1;// 16 000 000 TCCR0_CS01=0;// 16 000 000 / 1024 = 15 625 TCCR0_CS00=1;// 1 / 15 625 = 0,000064 =64 TCNT0 = TCNT0_VALUE; // 156 * 0,000064 c = 0,009984 c (10 ) // 255-156 = 99 TIMSK_TOIE0=1; // // _SEI(); // for(;;) { // _NOP(); // 6- D "0" "1" "1" "0" // PORTD_PORTD6 ^= 1; // DELAY_MS(500); }//end for } /* T0 */ #pragma vector=TIMER0_OVF_vect __interrupt void ISR_TickTimer(void) { // _NOP(); // T0 T0_tick_cnt++; // 1 if (T0_tick_cnt >= T0_TICK_CNT_LIMIT) { // T0 T0_tick_cnt=0; // 7- D "0" "1" "1" "0" // PORTD_PORTD7 ^= 1; } // // TCNT0=TCNT0_VALUE; }//end func
ãã®äŸã§ã¯ãã¡ã€ã³ïŒïŒé¢æ°ã§ãLEDãèšå®ããåŸãTCCROå¶åŸ¡ã¬ãžã¹ã¿ã®ããããèšå®ããããšã§æ§æããããŒãã¿ã€ããŒãèšå®ãããŸãã ãªããªã éåžžã®ã¿ã€ããŒã¢ãŒãã䜿çšããå ŽåããããWGM00ããã³WGM01ã¯ãŒãã«ãªããŸãã åæå€ã¯ãã§ã«ãŒãã§ããããããããã«ã¯è§ŠããŸããã ãããCS00ãCS01ãCS02ã¯ã16 MHzã®ã¯ããã¯åšæ³¢æ°ã®æ倧ååšåšïŒ1024ïŒãååŸããããã«èšå®ãããŸãã
åå²åŸãã¿ã€ããŒã®åšæ³¢æ°ã¯15625 Hzã«ãªããŸããããã¯64ÎŒsã®ãã£ãã¯ã«å¯Ÿå¿ããŸãã ãã£ãã¯ã«156ïŒ156 * 0.000064 c = 0.009984 c = 10ããªç§ïŒãæãããšã10ããªç§ã«æãè¿ããªããŸãã ãããã£ãŠã10 msããšã«ãªãŒããŒãããŒã€ãã³ããåŠçããããã®å²ã蟌ã¿çæãåä¿¡ããã«ã¯ãã¬ãžã¹ã¿99ïŒ255-156 = 99ïŒãã«ãŠã³ãTCNT0ã«ããŒãããå¿ èŠããããŸãã ãªããªã ã¿ã€ããŒã¯99ããã«ãŠã³ããéå§ãã255ã«éãããšå²ã蟌ã¿ãçæããã156ãã£ãã¯ã®ãã¹ãååŸããŸãã
ããã«ãã®äŸã§ã¯ããŒãã¿ã€ããŒã®ãªãŒããŒãããŒã«å¯Ÿããå²ã蟌ã¿ãçæããããã«ãTIMSKå²ã蟌ã¿ãã¹ãã³ã°ã¬ãžã¹ã¿ã®TOIE0ããããèšå®ãããŸãã ãã®åŸããã¯ãé¢æ°_SEIïŒïŒã䜿çšããŠããã¹ãŠã®ãã¹ã¯ãããå²ã蟌ã¿ã®ã°ããŒãã«ãªè§£æ±ºãè¡ããŸãã
ãã¹ãŠã®å²ã蟌ã¿ãã¯ãã«ã®å®çŸ©ã¯ãiom16.hããããŒãã¡ã€ã«ã«ãããŸãã
/*==============================*/ /* Interrupt Vector Definitions */ /*==============================*/ /* NB! vectors are specified as byte addresses */ #define RESET_vect (0x00) #define INT0_vect (0x04) #define INT1_vect (0x08) #define TIMER2_COMP_vect (0x0C) #define TIMER2_OVF_vect (0x10) #define TIMER1_CAPT_vect (0x14) #define TIMER1_COMPA_vect (0x18) #define TIMER1_COMPB_vect (0x1C) #define TIMER1_OVF_vect (0x20) #define TIMER0_OVF_vect (0x24) #define SPI_STC_vect (0x28) #define USART_RXC_vect (0x2C) #define USART_UDRE_vect (0x30) #define USART_TXC_vect (0x34) #define ADC_vect (0x38) #define EE_RDY_vect (0x3C) #define ANA_COMP_vect (0x40) #define TWI_vect (0x44) #define INT2_vect (0x48) #define TIMER0_COMP_vect (0x4C) #define SPM_RDY_vect (0x50)
ããã°ã©ã ã®ããžãã¯ã¯ãã¡ã€ã³ã«ãŒããšå²ã蟌ã¿ãã³ãã©ãŒã®æºäžŠååäœãæäŸããã¹ãŒããŒãµã€ã¯ã«ãåããã·ã¹ãã ã®æåã®äŸã§æ¢ã«èª¬æãããŠããŸãã ã¡ã€ã³ã«ãŒãã§ã¯ãããŒãDã®6çªç®ã®ãã³ã500 msã®åšæã§åãæ¿ããããŸãã ã¡ã€ã³ã«ãŒãã¯10ããªç§ããšã«äžæããããŒãã¿ã€ããŒãªãŒããŒãããŒã«ããå²ã蟌ã¿ãåŠçããŸãã åŠçã¯ããã®ã€ãã³ãã§åŒã³åºãããISR_TickTimerïŒïŒãã³ãã©ãŒé¢æ°ã䜿çšããŠå®è¡ãããŸãã ãã®é¢æ°ã§ã¯ãå€æ°T0_tick_cntãã€ã³ã¯ãªã¡ã³ãããããšã«ããã10ããªç§ã®ãã£ãã¯ãã«ãŠã³ããããŸãã å€æ°T0_tick_cntã100ã«éãããšïŒã€ãŸãã1ç§ãçµéãããšïŒããã®ã€ãã³ãã¯ãã³ãã©ãŒã®ifã¹ããŒãã¡ã³ãã䜿çšããŠæ±ºå®ãããŸãã ãã®åŸãå€æ°T0_tick_cntã¯ããŒãDã®ãã³7ãåãæ¿ããŸããããã«ããã1000ããªç§ã®åšæã§2çªç®ã®LEDãç¹æ» ããŸãã
ãã®äŸããããã°ããå Žåãã¡ã€ã³ã«ãŒããšå²ã蟌ã¿ãã³ãã©ãŒã®äž¡æ¹ã«ãã¬ãŒã¯ãã€ã³ããèšå®ã§ããŸãã
5çªç®ã®äŸã¯ãäœæ¥ã®ããžãã¯ã«ãããšãåã®äŸã§ããããã¯ãé¢æ°ã䜿çšããŠããŸãã
/* */ #include <ioavr.h> #include <intrinsics.h> #include <ina90.h> /* */ // #define F_CPU 16000000 // #define DELAY_TIME 500 // // #define LED1_DDR DDRD #define LED1_PORT PORTD #define LED1_PIN DDD7 // // #define LED2_DDR DDRD #define LED2_PORT PORTD #define LED2_PIN DDD6 // #define F_CPU_DIV_1 (0<<CS02)|(0<<CS01)|(1<<CS00) #define F_CPU_DIV_8 (0<<CS02)|(1<<CS01)|(0<<CS00) #define F_CPU_DIV_64 (0<<CS02)|(1<<CS01)|(1<<CS00) #define F_CPU_DIV_256 (1<<CS02)|(0<<CS01)|(0<<CS00) #define F_CPU_DIV_1024 (1<<CS02)|(0<<CS01)|(1<<CS00) // #define TCNT0_VALUE 99 // #define T0_TICK_CNT_LIMIT 100 // #define UINT unsigned int /* */ // #define LED1_INIT() ( LED1_DDR |= (1<<LED1_PIN) ); // #define LED1_LOW() ( LED1_PORT &=~ (1<<LED1_PIN) ); // #define LED1_HIGH() ( LED1_PORT |= (1<<LED1_PIN) ); // #define LED1_TOG() ( LED1_PORT ^= (1<<LED1_PIN) ); // #define LED2_INIT() ( LED2_DDR |= (1<<LED2_PIN) ); // #define LED2_LOW() ( LED2_PORT &=~ (1<<LED2_PIN) ); // #define LED2_HIGH() ( LED2_PORT |= (1<<LED2_PIN) ); // #define LED2_TOG() ( LED2_PORT ^= (1<<LED2_PIN) ); // #define TIMER0_SET_CLK_DIV(x) ( TCCR0 |= x ); // #define TIMER0_SET_CNT(x) ( TCNT0 = x ); // #define TIMER0_OVF_INT_ON() ( TIMSK|=(1<<TOIE0) ); // #define DELAY_US(us) __delay_cycles((F_CPU / 1000000) * (us)); // #define DELAY_MS(ms) __delay_cycles((F_CPU / 1000) * (ms)); /* */ // T0 UINT T0_tick_cnt=0; /* */ // void main( void ) { // // LED1_INIT(); LED2_INIT(); // LED1_LOW(); LED2_LOW(); // ( Normal) TIMER0_SET_CLK_DIV(F_CPU_DIV_1024);// 16 000 000 // 16 000 000 / 1024 = 15 625 // 1 / 15 625 = 0,000064 =64 TIMER0_SET_CNT(TCNT0_VALUE); // 156 * 0,000064 c = 0,009984 c (10 ) // 255-156 = 99 TIMER0_OVF_INT_ON(); // // _SEI(); // for(;;) { // _NOP(); // LED1_TOG(); // DELAY_MS(DELAY_TIME); }//end for } /* T0 */ #pragma vector=TIMER0_OVF_vect __interrupt void ISR_TickTimer(void) { // _NOP(); // T0 T0_tick_cnt++; // 1 if (T0_tick_cnt >= T0_TICK_CNT_LIMIT) { // T0 T0_tick_cnt=0; // LED2_TOG(); }//end for // // TIMER0_SET_CNT(TCNT0_VALUE); }//end func
èšå®ããã¯ãTIMER0_SET_CLK_DIVïŒXïŒãçšããŠè¡ã£ãå Žåã瀺ããã³ã³ãããŒã«ã®ãããã¯ããŒãTCCROã¿ã€ãã¬ãžã¹ã¿ãåšæ³¢æ°ãåå²ããŠã¯ããã¯å®çŸ©F_CPU_DIV_1ãF_CPU_DIV_8ãF_CPU_DIV_64ãF_CPU_DIV_256ãF_CPU_DIV_1024ã®ã»ããããéžæãããæ¹æ³ã決å®ããåŒæ°xã åæå€ã¯ããã¯ãé¢æ°TIMER0_SET_CNTïŒxïŒã䜿çšããŠã¢ã«ãŠã³ãã¬ãžã¹ã¿TCNT0ã«èšé²ãããŸããåŒæ°xã¯åæå€ãã®ãã®ã§ãïŒãã®å ŽåãTCNT0_VALUE = 99ïŒã TIMSKå²ã蟌ã¿ãã¹ã¯ã¬ãžã¹ã¿ã®TOIE0ãããã®èšå®ã¯ããã¯ãé¢æ°TIMER0_OVF_INT_ONïŒïŒã䜿çšããŠå®è¡ãããŸãã
IARãããžã§ã¯ãã®åœ¢åŒã®ãã¹ãŠã®äŸã¯ã ããããããŠã³ããŒãã§ããŸã ã
ãããã«
ãã®æçš¿ã«é¢å¿ãããå Žåã¯ã次ã®ããŒãã§ã¯ãå èµADCã§ãã7ã»ã°ã¡ã³ãã§ã®äœæ¥äŸãæ€èšããŸãã ãã®åŸãããžã¿ã«æž©åºŠèšã®ãœãããŠã§ã¢ãããžã§ã¯ãã§æ€èšãããã¹ãŠã®äŸãåéããŸãã
å ç®
IARã§èšè¿°ãããããã°ã©ã ã®16é²ãã¡ã€ã«ãååŸããå¿ èŠãããå Žåããããè¡ãããšã¯ãŸã£ããé£ãããããŸããã 以äžã®ã¹ã¯ãªãŒã³ã·ã§ããã®ããã«ãèšå®ãè¡ãã«ã¯ã[ãªã³ã«ãŒ]-> [åºå]ã¿ãããã³[ãªã³ã«ãŒ]-> [è¿œå åºå]ã¿ãã®ãããžã§ã¯ãèšå®ã§ååã§ãã ãã®åŸããµããã©ã«ããŒ[ãããžã§ã¯ãå] \ Debug \ Exeã§Project-> Rebuild Allãã¯ãªãã¯ããŠãããžã§ã¯ãããªãã«ããããšãhexãã¡ã€ã«ãèŠã€ãããŸãã AVR910ããã°ã©ããŒãSTK500ã¯ããŒã³ããŸãã¯ä»ã®å©çšå¯èœãªããã°ã©ããŒã§çž«ãããšãã§ããŸãã