MicroCamp2.0
Transcription
MicroCamp2.0
MicroCamp : ATmega8 Activity Kit Manual l 1 MicroCamp2.0 ATmega8 - 2008 2 l MicroCamp : ATmega8 1 MicroCamp...........................................................................................3 2 MicroCamp................................................15 3 AVR Studio WinAVR C-compiler.....................................................................23 4 C.................................................33 5 WinAVR C-compiler............................................................43 6 MicroCamp........................53 7 1 2 MicroCamp...............................................63 .......................................................68 ........................................71 3 4 5 ..................................................75 SLCD16x2...........................................80 SLCD16x2.................................84 SLCD16x2...........................................85 6 7 8 ............................89 ................91 .........................................94 ...........................................96 9 10 11 ........................99 GP2D120..............102 GP2D120...........................104 ........106 12 13 14 ..................................................................109 38kHz......................................111 ER-4..............................................113 ER-4...............................115 8 9 10 11 MicroCamp : ATmega8 l 3 1 MicroCamp MicroCamp . . ( MicroCamp”), “ , , . . 1-1 MicroCamp. " (6 " .) ATmega8 (ISP) / P0 = PC0/ADC0 P1 = PC1/ADC1 P2 = PC2/ADC2 P3 = PC3/ADC3 P4 = PC4/ADC4 GND +5V S/DATA S/DATA (PD4) LED1 (PC5) GND +5V RESET SW2 (PD3) GND +5V SW1 (PD2) RxD TxD LED2 (PD1) 1-1 MicroCamp 4 l MicroCamp : ATmega8 1.1 MicroCamp 1.1.1 MicroCamp l 8- AVR Atmel; ATmega8. : 10- (ADC), 8KB (10,000 (RAM) 512 ), 512 . l 16MHz, l 5- . ( 3- ). , . ( " " +5 ), . 38kHz. (RxD) , l . l . l2 . l " ". l2 l , . : . 6 , 600 ; 4.5 . l +4.8 +6 (4 AA). . l +5 . 1.1.2 PX-400 AVR . AVR . : l RS-232. USB, USB/Serial . UCON-232S. l ISP- : , , . . MicroCamp : ATmega8 l 5 1-2 PX-400. l l +5 , AVR Studio . AVR Prog. tools. : AT90S1200, AT90S2313, AT90S2323, AT90S2343, AT90S4433 , AT90S8515 , AT90S8535 , ATmega128 , ATmega16 , ATmega161 , ATmega162 , ATmega163 , ATmega164P , ATmega165 , ATmega168 , ATmega32 , ATmega64 , ATmega8 , ATmega8515 , ATmega8535, ATtiny12 , ATtiny13 , ATtiny15L , ATtiny2313, ATtiny26 , Avr-OSP II AT90CAN128, AT90CAN32, AT90CAN64, AT90PWM2, AT90PWM3, AT90S1200, AT90S2313, AT90S2323, AT90S2343, AT90S4414, AT90S4433, AT90S4434, AT90S8515, AT90S8515comp, AT90S8535, AT90S8535comp, ATmega103, ATmega103comp, ATmega128, ATmega1280, ATmega1281, ATmega16, ATmega161, ATmega161comp, ATmega162, ATmega163, ATmega165, ATmega168, ATmega169, ATmega2560, ATmega2561, ATmega32, ATmega323, ATmega325, ATmega3250, ATmega329, ATmega3290, ATmega406, ATmega48 , ATmega64, ATmega640, ATmega644, ATmega645, ATmega6450, ATmega649 , ATmega6490, ATmega8, ATmega8515, ATmega8535, ATmega88, ATtiny11, ATtiny12, ATtiny13, ATtiny15, ATtiny22, ATtiny2313,ATtiny24, ATtiny25, ATtiny26, ATtiny261, ATtiny28, ATtiny44, ATtiny45, ATtiny461, ATtiny84, ATtiny85, ATtiny861 6 l MicroCamp : ATmega8 +Vm SW1 POWER K1 + DC input L1 R1 0.47R 6 50 µH D1 1N4001 +5V 8 R3 30k 3 - IC1 TL499A +4.8~6Vdc 4 C1 220/16V R2 150 C2 0.01/50V 5 R5 1k 2 C3 1000/6.3V R4 10k 7 C4 1000/6.3V LED1 ON +5V +Vm C5 0.1/50V R6 47R MOSI 7 VCC AVCC 1 PC6/RESET S2 RESET +5V SCK MISO PB1/ 15 OC1A C6 0.1/50V R7 150R RESET 17 R8 150R PB3/MOSI 18 PB4/MISO R9 150R 19 P0 23 R11 150R P1 25 PC2/ADC2 R13 150R P3 R14 150R P4 GND +5V RESET R16 150R R17 150R RxD TxD 1 1E R20 150R PD2 4 PC4/ADC4 PB6 9 PC5/ADC5 PB7 2 3 PD1/TxD PD4 6 15 R27 4.7k R26 150R R28 4.7k SW1 SW2 CR1 16MHz GND 22 MicroCamp R31 1k C14 0.1/50V 2B C12 10/16V SP1 PIEZO 4Y GND 5 12 13 K2 MOTOR-B LED2 10 2A R24 150R 21 AREF GND 8 3Y + 11 9 2E R23 150R IC2 ATMega8 LED4 IND1 2Y 6 7 1B R22 150R R29 47R R30 1k C13 0.1/50V 10 PD0/RxD 1Y 3 2 1A R21 150R R25 150R 8 VM IC3 L293D 4 27 C11 0.1/50V 1-3 schematic R19 150R +5V PD3 5 R18 1k LED5 IND2 11 26 PC3/ADC3 28 R15 1k PC0/ADC0 PD5 16 VCC C8 0.1/50V 24 PC1/ADC1 R12 150R P2 C10 0.1/50V PD7 13 PB0 14 R10 150R C9 0.1/50V PD6 12 PB2/ 16 OC1B PB5/SCK +5V IRM C7 0.1/50V 20 14 LED3 + K3 MOTOR-A MicroCamp : ATmega8 l 7 1.2 MicroCamp ATmega8. 16MHz, PB6 , PB7. PC0 - PC4 P0 - P4. . / . , ATmega8. PB3, PB4 10- PB5 ISP, . . . " PC6/RESET " . PD0/RxD . IRM 5- . PD1/TxD . IND2) . LED5 ( TxD 5- LED4 (IND1) PC5 . . PD3 PD2 4.7k . 10 PD4 . . L293D. : A B . E . - , (PWM) . . , L293D . . . TL499A. +5 . 8 l MicroCamp : ATmega8 1.3 MicroCamp , MicroCamp , , ISP- . , PCB3AA-8 . 1.3.1 ISP10- 10- . IDC. ISP- . Atmel. . +5V GND GND GND GND 1.3.2 JST3AA-8 INEX, JST. MicroCamp 2GND MOSI N/A RST SCK MISO 2 20 . . . . 2 GND S +5V S/Data +5V 1.3.3 CX-4 - DB-9, RS-232. RJ-11 6P4C. . DB-9 1.5 . PX-400 . RJ11-6P4C 5 4 5 3 3 2 RxD ! TxD " DTR # GND 4 2 MicroCamp : ATmega8 l 9 1.4 ATmega8 , CMOS, 8- ATmega8 AVR , ATmega8 , RISC. , 1 MIPS . MicroCamp ATmega8 28- DIP . 1-4. . 1.4.1 ATmega8 8- l AVR RISC. 8K l , 512 ), 1K 10,000 (100,000 32 . / 23 , 3 B (PB0 - PB7) : 1. . (PB6 PB7) PB2 - PB5 . 2. PB0 C (PC0 - PC6 : 7 . PC6 . D (PD0 - PD7 : 8 3. PC0 - PC5 ) ) . 28 PC5/ADC5/SCL PC6/RESET 1 PD0/RxD 2 PD1/TxD 3 PD2/INT0 4 PD3/INT1 5 6 PD4/T0/XCK 28 7 Vcc 28 8 GND 28 PB6/TOSC1/XTAL1 PB7/TOSC2/XTAL2 10 9 1-4 27 PC4/ADC4/SDA 26 PC3/ADC3 ATmega8-16PI l 25 PC2/ADC2 24 PC1/ADC1 28 PC0/ADC0 23 28 GND 22 28 AREF 21 20 AVcc 19 PB5/SCK PD5/T1 11 PD6/AIN0 12 18 PB4/MISO PD7/AIN1 13 PB0/ICP1 14 16 PB2/SS/OC1B 17 PB3/MOSI/OC2 15 PB1/OC1A ATmega8 PB1. 10 l MicroCamp : ATmega8 8- l l / 16- , / , , l l 10- l6 l USART l SPI l Master/Slave l l l , l RC- l 5 save, Power-down, Standby : Idle, ADC Noise Reduction, Power- l 4.5 - 5.5 l 0 - 16 l 1.4.2 ATmega8 RISC : 8K 1K / / , 23 . 1-5. ATmega8 32 , 32 AVR . ATmega8 , 512 , , USART, 10, , , 6- SPI, 5 , . , 1.4.3 / , , Idle SPI, , . ATmega8 1-1 ATmega8. MicroCamp : ATmega8 l 11 XTAL2 RESET XTAL1 C (PC6-PC0) B (PB7-PB0) cc / / C 2AGND AREF / Flash Program Memory X Y Z AVR CPU - SPI USART D / D (PD7-PD0) 1-5 ATmega8 12 l MicroCamp : ATmega8 Vcc 7 - GND 8,22 - AVcc 20 - AREF 21 - +4.5 +5.5 +5 B PB0 14 / 15 / - PB0 - ICP1 1 - PB1 - / - PB2 OC1B - / SS - PB1 OC1A PB2 PB3 16 17 / / OC2 / MOSI Slave 18 MISO PB5 19 SCK - PB3 - / - 9 Master SPI ISP / - Master SPI ISP - Slave SPI ISP Slave SPI ISP / - / - PB4 PB5 / Master XTAL1 - , TOSC1 / - XTAL2 - TOSC2 - 1-1 ISP - PB6 10 SPI / - PB7 2 Slave PB6 1B SPI PB4 1A SPI ISP PB7 ATmega8 ( ) MicroCamp : ATmega8 l 13 C 23 PC0 / - PC0 - ADC0 24 PC1 / - 0 PC1 - ADC1 25 PC2 / ADC2 26 PC3 / ADC3 27 PC4 / ADC4 SDA 28 PC5 1 - PC2 - PC3 - PC4 / - / - 2 3 4 2- PC5 ADC5 - SCL - 2- - PC6 1 PC6 / 5 - RESET D 2 PD0 / RxD 3 PD1 / 4 PD2 / PD3 USART - PD1 - 5 / 6 / USART PD2 - / - - 0 PD3 - INT1 PD4 XCK T0 11 / T1 12 / 1 PD4 USART - Timer 0 - PD5 - Timer 1 - PD6 - AIN0 PD7 - - INT0 PD6 PD0 - TxD PD5 - 13 / - 0 PD7 - AIN1 1-1 1 ATmega8 ( ) 14 l MicroCamp : ATmega8 2 MicroCamp MicriCamp C. : 1. AVR Studio : Atmel Corporation. AVR Studio AVR. AVR Studio . , AVR Studio C, Atmel Corporation’s AVR Assembler Compiler. AVR Studio WinAVR C Microsoft Windows95 Microsoft Windows NT. Windows XP SP2. www.atmel.com. 2. WinAVR : WinAVR ( avrdude ( programmers notepad ( Windows. projects/winavr/. C, avrgcc), avr-as ( JTAG ICE), avr-gdb ( avrgcc ), ), Microsoft http://sourceforge.net/ ), avr-libc ( ), avarice ( ) . MicroCamp WinAVR AVR Studio, V20050214. Studio WinAVR. AVR , WINAVR. AVR Studio, WinAVR. HEX- , 3. . , : , C. library / 4. : AVR. Atmel PX-400. Port control , , .HEX- AVRProg. AVR Studio. PX-400 AVR Prog MicroCamp. . . MicroCamp : ATmega8 l 15 2.1 AVR Studio AVR Studio 2.1.1 Windows XP: aStudio4b460.exe AVR Studio MicroCamp. 2.1.2 . 2.1.3 ment Next . : I accept the terms of the license agreeNext. MicroCamp : ATmega8 l 16 2.1.4 . Change 2.1.5 . Next. Driver USB Upgrade. Next . 2.1.6 2.1.7 Install. AVR Studio, Finish. 17 l MicroCamp : ATmega8 2.1.8 Tools à AVR Studio 4. AVR Studio. à AVR Studio. à Atmel AVR MicroCamp : ATmega8 l 18 2.2 WinAVR , WinAVR AVR Studio. ! WinAVR Windows XP: 2.2.1 WinAVR-20050214-install.exe 2.2.2 . , OK. 2.2.3 Next. MicroCamp. , . 1 9 l MicroCamp : ATmega8 2.2.4 I agree. 2.2.5 . Browse. C:\WinAVR. Next. MicroCamp : ATmega8 l 20 . 2.2.6 Install. 2.2.7 . Finish. 2.3 (.H MicroCamp_include - ) , . . WinAVR, MicroCamp AVR Studio MicroCamp_include. . MicroCamp : ATmega8 l 21 3 MicroCamp AVR Studio WinAVR 3.1 C , , . , ( C ). : (1) (2) C ( (3) HEX). (4) (5) (2) . . (3) 1 . C AVR Studio WINAVR, MicroCamp. MicroCamp_include C AVR Studio, . HEX- , MicroCamp . ATMEGA8. : test_segment. test_segment.hex 22 l MicroCamp : ATmega8 3.2 AVR Studio V4.0 AVR Studio. , C : , , . 3.2.1 File : New File Open File Close Save Save As... Save All Print Print Preview Print Setup Exit AVR Studio . HEX- MicroCamp : ATmega8 l 23 3.3.2 Project : Project Wizard . . New Project . . Open Project , APS . Save Project Close Project Recent Projects Configuration Options . 3.2.3 Build : Build Rebuild All Build and run Compile Clean Export Makefile 3.2.4 Edit : Undo ( ) Redo Cut Copy Paste Toggle Bookmark / Re- move Bookmarks Find Find in Files Next Error Show whitespace Font and color . . 24 l MicroCamp : ATmega8 3.2.5 View : / Toolbars . / Status Bar ( ) / Disassembler 3.2.6 Watch / Memory / Memory 2 / 2 Memory 3 / 3 Register / Tools Studio . AVR MicroCamp$ PX-400. . AVRprog. PX-400 3.2.7 COM- AVRprog. Debug . MicroCamp 3.3 . C 3.3.1 AVR Studio. Project à Close Project 3.3.2 AVR Studio - , Project à New Project. MicroCamp : ATmega8 l 25 3.3.3 . 3.3.3.1 : Project type AVR GCC: C. 3.3.3.2 Switch_LED ( . Switch_LED.c. 3.3.3.3 \Code. ). Location: : G:\Work2006\AVR-ROBOT Finish. 3.3.4 Switch_LED . 26 l MicroCamp : ATmega8 Switch_LED G:\Work2006\AVR-ROBOT \Code. Switch_LED.aps Switch_LED.c. 3.3.5 , . Project à Configuration Options 3.3.5.1 Switch_LED Project Options. 5 : l General l Include Directories l Libraries l Memory Settings l Custom Options 3.3.5.2 General l Device : atmega8 l Frequency: 16000000 Hz MicroCamp : ATmega8 l 27 3.3.5.3 Include Directories , . Add. C:\AVR_ROBOT\include. 3.3.5.4 3.3.5.5 Add Library. Libraries Available Link Objects:, OK . . libm.a 2 8 l MicroCamp : ATmega8 3.3.6 C Switch_LED.c. , . 3-1. #include <in_out.h> #include <sleep.h> void main() { while(1) { if (in_d(2)==0) { toggle_c(5); } if (in_d(3)==0) { toggle_d(1); } sleep(200); } } 3-1 C Switch_LED.c 3.3.7 Switch_LED.hex Build Build à F7 AVR Studio . , , , Build Output. . Switch_LED.hex . : Switch_LED.hex \Work2006\AVRROBOT\Code\Switch_LED\ default. G: MicroCamp : ATmega8 l 2 9 3.4 Project à Open . Project . .aps : Project à Switch_LED, Open Project Switch_LED.aps. . . 3.5 HEXSwitch_LED.hex. . : ( 3.5.1 POWER). . 3.5.2 ISP- MicroCamp. PX-400 USB/Serial UCON-232/UCON-232S RS-232, USB/Serial. USB RS-232 MicroCamp 3-1 MicroCamp PX-400 30 l MicroCamp : ATmega8 3.5.3 AVR Studio, 3.5.4 AVRprog. 3.5.5 Switch_LED.hex AVRprog Tool à AVR Prog... Browse hex- , . . . . 3.5.6 Program ATmega8 Switch_LED.hex MicorCamp. 3.5.7 SW1 Flash. , MicroCamp. SW2 LED. LED .. . MicroCamp : ATmega8 l 31 4 C . , . . ‘ , ’ . C , . C. 4.1 : return_type function_name(parameter1, parameter2, ...) { command_list 1; .................... .................... command_list n; } function_name return_type return(value) , . . . void return_type. - . , , . void. , command_list 1...command_list n . . 32 l MicroCamp : ATmega8 4.2 " " . , . , “ ” : function_name(agument1, agument2,...) function_name - . , agument - . , . 4-1 void tone(void) { sound(3000,100); // ; 3 // sleep(1000); // sound(3000,100); // 0.1 1 ; 3 // 0.1 } tone. . 1 3 0.1 . : void main() { ................ tone(); ............... } // // // : tone 2 ; sound.h 4-2 void tone(unsigned int delay) { sound(3000,100); sleep(delay); sound(3000,100); // // // ; ; } Sleep. "delay" tone . sleep.h MicroCamp : ATmega8 l 33 4.3 , . , . C. AVR Studio. 4.3.1 , . .h. , , ; led1.h. : (1) File à New File. (2) Blink: void sleep(unsigned int ms) { unsigned int i,j; for(i=0;i<ms;i++) for(j=0;j<795;j++); } void blink(unsigned int cnt) { unsigned int _cnt=0; DDRC |= _BV(5); // while(_cnt < (cnt*2)) // { PORTC ^= _BV(5); sleep(300); _cnt++; } } (3) led1.h PC5 // // File à Save As... . PC5 0.3 .h. 34 l MicroCamp : ATmega8 4.3.2 , , , C. #include <library_filename> #include “library_filename” #include , C . 4-6 (1) ; test_lib (2) C #include <in_out.h> #include <led1.h> void main() { blink(10); } test_lib.c // // blink LED 10 // : test_lib . led1 2 2 . ATmega8 (in_out.h). ; blink sleep(). LED. (3) (5) PC5 sleep() . "0". blink Project à Configuration Options. led1.h . test_lib.hex. test_lib.hex (6) blink "1" LED (4) led1.h . . LED PC5 ATmega8 10 . MicroCamp : ATmega8 l 35 4.4 C WinAVR char 8- . -128 unsigned char 8- . 0 +255. int 16- . -32,768 unsigned int 16- . long 32- . -2,147,483,648 unsigned long +65535 +2,147,483,647 32- . 0 +4294967295 long long 64-9223372036854775808 unsigned long long 640 float and double 0 +127. . + 9223372036854775807 . +18446744073709551616 32- , arrays . pointers structures . . 32767 36 l MicroCamp : ATmega8 4.5 C WinAVR 3 C. 1. . 2. 0bBBBBBBBB. . 3. ,B 0 0xHHHHHHHH. 1 ,H 4-7 0...9, A...F. 0b10010010 146 7 6 5 4 3 2 1 0 : (1x2 ) + (0x2 ) + (0x2 ) + (1x2 ) + (0x2 ) + (0x2 ) + (1x2 ) + (0x2 ) = 14610 . 4-8 16- ; 0b1111010011101101 62701 . (1x215) + (1x214) + (1x213) + (1x212) + (0x211) + (1x210) + (0x29) : + (0x28) + (1x27) + (1x26) + (1x25) + (0x24) + (1x23) + (1x22) + (0x21) + (1x20) = 6270110 4-9 ; 0xFF 255 : (15x161) + (15*160) = 25510 . 0xFF à 0b11111111 . 4-10 ; 0x31 : (3x161) + (1x160) = 4910 49 0x31 à 0b00111111 4.6 C WinAVR ANSI-C. type variable_name; type variable_name : . . MicroCamp : ATmega8 l 37 int a; // long result; // result long float start; // start float int x,y; // 2- float p,q,r; // 3 ; x ; p, q r. y. float. , int x=100; x. // int // int x=15,y=78; 100. // y. p q. integer // // x=15 y=78. // // long p=47L,q=31L; x p=47 long q=31. 4.7 (type)variable type , variable - 4-11 int x=100; float y=43.67,z; z = y+(float)x ; x // // integer y // // // z = y + x. x // z = 143.67. z 100. float int. float y = 43.67. (float)x. 4-12 int a=50; // // a integer 50. long b=23L,c; // c = b*(long)a; // c = b * a. // // a b // (long)a // c = 1150 c b = 23. long int. b long c. 3 8 l MicroCamp : ATmega8 4.8 WinAVR 4.8.1 4.8.1.1 : type name[size]; type name size - ( ) : name[index] index , . 4-13 . : char arr[4]; , arr . arr[0] : : 0 arr[1] : 1 arr[2] : 2 3 arr[3] : arr[0], arr[1], arr[2] . 4 arr[3] char. arr 1 4 . MicroCamp : ATmega8 l 39 4-14 char dat[8] = {1,3,5,7,9,11,13,15} ; dat[0] dat[1] dat[2] dat[3] dat[4] dat[5] 11; dat[6] 13; dat[7] = = = = = = , 8 dat. : 1; 3; 5; 7; 9; = = 15; char i , j ; i = 3; j = dat[i]; // j = dat[i] ==> j = dat[3] ==> j = 7 j = 7 */ /* 4-15 char dat[4] = “ abcd” ; 4 dat. dat[0] dat[1] dat[2] dat[3] = = = = , : ‘a’; ‘b’; ‘c’; ‘d’; char i , j ; i = 3; j = dat[i]; // j = dat[i] ==> j = dat[3] ==> j = ‘d’ is j = ‘d’ */ /* . . 40 l MicroCamp : ATmega8 4.8.1.2 : type name[x][y]; : type name xy: int a[2][5]; 10 “a”. . a[0][0], a[0][1], a[0][2], a[0][3], a[0][4] , a[1][0], a[1][1], a[1][2], a[1][3], a[1][4] : int menu[3][4] ={{1,3,4,9} , {2,8,0,5}}; : menu[0][0] = 1 menu[0][1] = 3 menu[0][2] = 4 menu[0][3] = 9 menu[1][0] = 2 menu[1][1] = 8 menu[1][2] = 0 menu[1][3] = 5 menu[2][0] = 0 menu[2][1] = 0 menu[2][2] = 0 menu[2][3] = 0 MicroCamp : ATmega8 l 41 5 WinAVR Win AVR : , . 5.1 : + * / % ++ 1 - - 1 += -= *= /= %= 5.1.1 (+) (-) 5-1 int a = 12; a = a + 3; a = 15 : a = 12. a 3 a. 42 l MicroCamp : ATmega8 5-2 int a = 12; a = a - 3; a=9 : a = 12. a 3 a. 5.1.2 / % : 1. / . , 2. % . 5-3 int x , y , z; x = 10; y = x/3; z = x%3; y=9 z=1 : y = x/3; à y = 10/3 à y = 3 ( z = x%3; àz = 10%3à z = 1 ( 5.1.3 ++ ) ) - -- 5-4 int y = 5; y++; y=6 : y = 5. , y+1 = 6 y = y + 1. 5-5 int y = 5; y - -; y=4 gives the result similar to y = y - 1; command y. , y++; MicroCamp : ATmega8 l 43 5.1.4 += -= : y +=a; y = y + a; y-=a; y = y - a; 5-6 int x = 100; x += 10; x = 110 5.1.5 *= , /= %= : y *=a; y = y * a; y /=a; y = y/a; y %=a; y = y%a; 5-7 int x, y, z; x = y = z = 120; x *= 4; y /= 4; z %= 4; x = 480 , y = 30 z=0 44 l MicroCamp : ATmega8 5.2 “1” . “0” : == != > < >= <= ! && || 5-8 a = 10, b = 4, c = 0xA0 a>b true 1 a>c false 0 a>=c true 1 ( a!= b true 1 a!= c false 0 5.2.1 ! , && !( . 0xA0 = 10) || ) ! false true(1) ! true false(0) &&( ) false && false false(0) false && true false(0) true && false false(0) true && true true(1) false . MicroCamp : ATmega8 l 45 ||( ) false || false false(0) false || true true(1) true || false true(1) true || true true(1) true . 5-9 a = 10, b = 4 c = 0xA0 a>b true. 1 a>b true 1 a>c false 0 a>=c true 1( a != b true 1 a != c false 0 !(a>b) false 0 !(a>c) true 1 !(a>=c) false 0 !(a != b) false 0 !(a != c) true 1 !(a>b) && (a>=c) false(0) (a != b) && (a>=c) true(1) (a != b) && !(a != b) false(0) !(a>b) || (a>=c) true(1) (a != b) || (a>=c) true(1) (a != b) || !(a != b) true(1) !(a>=c) || !(a != b) false(0) 0xA0 = 10) 46 l MicroCamp : ATmega8 5.3 ~ & | ^ << >> <<= >>= &= |= . ^= 5.3.1 ~ ~0 1 ~1 0 & 0&0 0 &1 1&0 0 0 0 1&1 1 | 0|0 0|1 1|0 0 1 1 1|1 1 ^ 0^0 0 0 ^1 1^0 1 1 1^1 0 MicroCamp : ATmega8 l 47 5-10 : int x,y,result1,result2,result3,result4; x = 0x9C; y = 0x46; : result1 result2 ! result3 " result4 = x&y; = x|y; = x^y; = ~x; : . x = 0x9C à 0000000010011100 ( 16- y = 0x46 à 0000000001000110 (1) result1 = (0000000010011100) & (0000000001000110) 0000000010011100 AND 0000000001000110 0000000000000100 à 0x0004 0x04 (2) result2 = (0000000010011100) | (0000000001000110) 0000000010011100 OR 0000000001000110 0000000011011110 à 0x00DE 0xDE (3) result3 = (0000000010011100) ^ (0000000001000110) 0000000010011100 XOR 0000000001000110 0000000011011010 à 0x00DA (4) result4 = ~(0000000010011100) 1111111101100011 à 0xFF63 0xDA ) 48 l MicroCamp : ATmega8 5.3.2 : dat = dat<<4; , 4 dat dat. : dat = dat>>1; dat dat. 5-11 int dat, x1, x2; dat = 0x93; x1 = dat<<1; x2 = dat<<2; : dat = 0x93 à 0000000010010011 dat 0000000010010011 X1 0000000100100110 X2 0000001001001100 (1) x1 1 x1 = 0x0126 x2 = 0x024C 5-12 int a , b , c; a = 0x7A; b = 0x16; c = 0xFD; &= 0x3C; |= 0x51; ^= 0xD0; , 294 2 (2) x2 a b ! c dat. . dat. 588 , . MicroCamp : ATmega8 l 4 9 : (1) a &= 0x3C a = a & 0x3C. a. : a = (0000000001111010) & (0000000000111100) 0000000001111010 AND 0000000000111100 0000000000111000 (2) 0x38 b |= 0x51 : (3) à 0x0038 b = b |= 0x51. b. b = (0000000000010110) |= (0000000001010001) 0000000000010110 OR 0000000001010001 0000000001010111 à 0x0057 0x16 OR 0x51 0x57 c ^= 0xD0 : 0x7A AND 0x3C c = c ^= 0xD0. 0xFD XOR 0xD0 c. c = (0000000011111101) ^= (0000000011010000) 0000000011111101 XOR 0000000000101101 0000000011010000 à 0x002D 0x2D MicroCamp : ATmega8 l 50 6 MicroCamp MicroCamp / . , , , . : l in_out.h . l sleep.h l analog.h l led.h P0...P4 LED l motor.h l sound.h l timer.h . MicroCamp_include - . 51 l MicroCamp : ATmega8 6.1 in_out.h 6.1.1 B in_b : in_c : C in_d : D : char char char char in_a(x) in_b(x) in_c(x) in_d(x) : x- . 0 7. : “0” “1” 6-1 char x=0; x = in_b(2); // // x PB2 x // // x PD4 x 6-2 char x=0; x = in_d(4); 6-3 #include <avr/io.h> // #include <in_out.h> // #include <sound.h> // void main() { while(1) { if (in_d(2)==0) { sound(3000,100); } } } // // SW1 SW1 MicroCamp : ATmega8 l 52 6.1.2 , . . out_b : B out_c : C out_d : D : out_b(char _bit,char _dat) out_c(char _bit,char _dat) out_d(char _bit,char _dat) : _bit _dat - . 0 “0” 7. “1” 6-4 out_c(5,0); out_d(1,1); " 0" " 1" // // PC5 PD1 6-5 #include <avr/io.h> // // #include <sound.h> // void main() { while(1) // { } } out_d(1,1); // sleep(300); // out_d(1,0); // sleep(300); // " 1" PD1. LED2 0.3 "0" 0.3 PD1. LED2 53 l MicroCamp : ATmega8 6.1.4 toggle_b : B toggle_c : C toggle_d : D : toggle_b(x) togg le_c(x) togg le_d(x) : x - . 0 7. 6-6 toggle_c(5); // PC5 toggle_d(1); // PD1 6.2 sleep.h sleep, . . : void sleep(unsigned int ms) : . 6-7 sleep(20); // 20 sleep(1000); // 1 0 65,535. MicroCamp : ATmega8 l 54 6.3 analog.h: 6.3.1 . PC0...PC4. ATmega8. 0 10- . 1,023 0 5 . : unsigned int analog(unsigned char channel) : channel - . 0 PC0...PC4 4. : , 0 1,023 . 6-8 // int adc_val=0; adc_val = analog(0); // 0 (PC0) adc_val. 6.4 led.h MicroCamp 2 PC5 (LED1) , “0” PD1(LED2). “1” . led.h. LED1 (PC5) led1_on() : LED1 (PC5) led1_off() : LED2 (PD1) led2_on() : LED2 (PD1) led2_off() : 6-9 void main() { led1_on(); // } LED1 55 l MicroCamp : ATmega8 6.5 motor.h 6.5.1 MicroCamp. : void motor(char _channel,int _power) : _channel - . 2 ;1 2. - _power MicroCamp . -100 100. (1...100), . (-1...-100), . , 0, . 6-10 1 motor(1,60); // ................ motor(1,-60); // 60% 1 60% 6-11 2 motor(2,100); // 6.5.2 motor_stop (100%) . : void motor_stop(char _channel) : _channel - . 3 OUT1, 2 .1 OUT2, ALL 6-12 motor_stop(1); // 1 motor_stop(2); // 2 motor_stop(ALL); // (1 2). MicroCamp : ATmega8 l 56 6.5.3 motor_off . 0. : void motor_off() 6.5.4 forward , . : void forward(int speed) : speed - 6.5.5 . 0 100. 0 100. backward , . : void backward(int speed) : speed - 6.5.6 . s_left , . : void s_left(int speed) : speed - 6.5.7 . 0 100. 0 100. s_right , . : void s_right(int speed) : speed - . 5 7 l MicroCamp : ATmega8 6.6 sound.h , - MicroCamp. : void sound(int freq,int time) : freq - . time - . 6-13 2 sound(2000,500); // , 0. 5 6.7 . timer.h 6.7.1 timer_start . . : void timer_start(void) 6.7.2 timer_stop . : void timer_stop(void) 6.7.3 timer_pause . : void timer_pause(void) 6.7.4 timer_resume timer_pause. : void timer_resume(void) . MicroCamp : ATmega8 l 58 6.7.5 msec . : unsigned long msec() : . 6.7.6 “long”. sec .. : unsigned long sec() : . “long”. 6-14 #include <in_out.h> #include <sleep.h> #include <timer.h> void main() { timer_start(); while(1) { if(msec()>500) { timer_stop(); toggle_c(5); timer_start(); } } } // // // . // // // // 500? . 0.5 . . MicroCamp : ATmega8 l 59 7 MicroCamp , MICROCAMP. , . , Microcamp . . . MICROCAMP 2 4 . 2 2 . Part list 48:1 x2 MicroCamp x1 x2 x1 x1 ( ) x2 x2 2 x2 25 x2 60l MicroCamp : ATmega8 . 1. 2 . , 2. 3x6 3. 25 . . 3 x 10 3 . 25 2- 3 4. 3 x 10 . MicroCamp : ATmega8 l 61 5. 3x15 , 2 3 . . 3 x 15 3 x2 6. . 3 . - 7. . 3 8. 3 5 MicroCamp .( . P0, P1). 5 . 62l MicroCamp : ATmega8 9. 3 x 10 3 . . 10. . 3 x 10 . 3 . . P2 (PC2), 11. P3 (PC3). MicroCamp. 4 AA MicroCamp . MicroCamp : ATmega8 l 63 MicroCamp : +V LED1 R1 510 R2 10k R3 220 DATA S1 GND . , DATA "1" , DATA "0", LED1 . , . . +V TCRT5000 OUT 510 10k ND , , . - . . , OUT , , .( TCRT5000 OUT 30 0.1 0.5 1023. 5 , MicroCamp 1.5 ). 64l MicroCamp : ATmega8 1 MicroCamp 1-1 A1.1 AVR Studio, A1-1. C . A1.2 PX-400 MicroCamp . HEXISP- A1.3 . . . A1.4 . . MicroCamp . . 1 . , , ( ). , . . #include <in_out.h> #include <sleep.h> #include <motor.h> // void main() { while(1) // { forward(100); // sleep(1000); // 1 backward(100); // sleep(1000); // 1 } } A1-1 . . . . C MicroCamp : ATmega8 l 65 1-2 A1.5 A1-2. C A1.6 PX-400 MicroCamp . HEXISP- A1.7 . . . A1.8 . . SW1 SW2. #include <in_out.h> #include <sleep.h> #include <motor.h> void main() { while(1) { while((in_d(2)==1)); motor(1,100); motor(2,30); while((in_d(3)==1)); motor_off(); } } // // // // // 1 2 A1-2, . MOTOR. . . , . , . SW1 . PD2 While. “0” , SW2 PD3. . . A1-2 C SW1 30% SW2 66l MicroCamp : ATmega8 1-3 A1.9 C MicroCamp PX-400 HEX- . . ISP- A1.10 . . . SW1 . #include <in_out.h> #include <sleep.h> #include <motor.h> void main() { while(1) { if (in_d(2)==0) { while(1) { forward(100); sleep(900); s_right(50); sleep(300); } } if (in_d(3)==0) { while(1) { forward(100); sleep(900); s_left(50); sleep(300); } } } } SW2. SW2 SW1, . // // SW1 0.9 // // // 50% 0.3 SW2 0.9 // // 50% 0.3 SW2 ( ) A1-3 A1-3. . ( SW1 ) MicroCamp : ATmega8 l 67 2 2-1 , . , . A2.1 A1-4. C . A2.2 A2.3 PX-400 MicroCamp HEX- . . . ISP- A2.4 . A2.6 . A2.7 . PD2 PC3. “0”. . , . , . 68l MicroCamp : ATmega8 #include <in_out.h> #include <sleep.h> #include <motor.h> void main() { while((in_d(2)==1)); // while(1) // { if (in_c(2)==0) // { backward(100); // SW1 , sleep(400); // s_left(50); sleep(300); } else if (in_c(3)==0) // { backward(100); // sleep(400); s_right(50); sleep(300); } else { forward(100); 0.3 0.3 // . 0.4 . . , // 0.4 . , } } } . A2-1 MicroCamp : ATmega8 l 69 2-2 , , . (A2-1) A2-2. A2.8 A2-2. C A2.9 PX-400 HEX- MicroCamp . . . ISP- . A2.10 . A2.11 . . , 5 180 . #include <in_out.h> #include <sleep.h> #include <motor.h> #include <sound.h> void main() { unsigned char cnt_=0; while((in_d(2)==1)); sound(3000,100); while(1) { if (in_c(2)==0) { if ((cnt_%2)==0) {cnt_++;} else {cnt_=0;} backward(100); sleep(400); s_left(50); if (cnt_>5) { sleep(700); sound(3000,100); cnt_=0; } // // // // // SW1 // // // // // // // // // // // // // // . , ? . , 0.4 5 , 0.7 A2-2 ( ) 70l MicroCamp : ATmega8 else { sleep(300);} // // else if (in_c(3)==0) { if ((cnt_%2)==1) // 5, 0.3 } {cnt_++;} else {cnt_=0;} backward(100); sleep(400); s_right(50); sleep(300); } else {forward(100);} } } A2-2 ( ) // // // // // // // // // . , . 1 , 0.4 0.3 , MicroCamp : ATmega8 l 71 8 LCD- 16 SLCD16x2 . . bps, 2400 2 TTL RS-232. SEIKO EPSON SED1278. HITACHI HD44780 , , 6 1 . 8.1 9600 SLCD16x2 MicroCamp. SLCD16x2 8.1.1 l RS-232 l 1/8 TTL/CMOS. 1/16 . l LCD Serial BackpackTM command. Scott Edwards’s l l +5 12 8.1.2 . 8-1 SLCD16x2. (1) (ST). MicroCamp : SLCD16x2 - 2 . (EX). (ST). (2) : 8 . 4 1/8 1/16 . 1/16. 1/16. 1/8 16 72 l MicroCamp : ATmega8 +5 (EX) (ST) 8- 16- (8) 9600 bps (96) (16) RS-232 (IN) (DI) 2400 bps (24) 8-1 SLCD16x2™ (3) : 2400 8N1 (8- (4) , 1 : TTL/CMOS (DI). ), 9600 bps ( ) TTL/CMOS RS-232 (IN) SLCD16x2. 3 (G). : +5 (+), (S) MicroCamp : ATmega8 l 73 8.1.3 SLCD16x2 MicroCamp JST3AB-8. . 2.54 2.00 GND S +5V JST3AB-8 2.00 (P0...P4) SLCD16x2. 2.54 (A-end). MicroCamp. , • • • . Standard (ST). • 16- A-end B-end (16). 9600 bps (96). Direct (DI). (B-end), JST 74 l MicroCamp : ATmega8 8.1.4 SLCD16x2 . , . , ASCII 254 (0FE hex 11111110 ( SLCD16x2 ). . . 8-2) . : , ( COMMAND\DATA BIT ASCII 1), ) D7 D6 [254] D5 D4 D3 D2 00000001 SLCD16x2 ( [1] D1 D0 1. Initial LCD 0 0 0 0 0 0 0 0 2. Clear LCD 0 0 0 0 0 0 0 1 3. Returm Home 0 0 0 0 0 0 1 * 4. Entry Mode Setting 0 0 0 0 0 1 I/D S 5. Display Setting 0 0 0 0 1 D C B 6. Shift Display 0 0 0 1 S/C R/L * * 7. Function Setting 0 0 1 DL * N F * * 8. Set CGRAM Address 0 1 A5 A4 A3 A2 A1 A0 9. Set DDRAM Address 1 A6 A5 A4 A3 A2 A1 A0 Standard instrction command set summary (except Initial LCD is addition command. Initialize make I/D=1, S=0, D=1, C=0, B=0, N=1, F=0, DDRAM Address=00 * [] Don't care bit S 0=Automatic cursor shift after byte 1=Cursor not moved I/D 0=After byte, decrease cursor position 1=After byte, increase cursor position (when S=1, cursor won't be shifted .) D C B 0=Display OFF, 1=Display ON 0=Cursor OFF, 1=Cursor ON 0=Cursor not blink, 1=Cursor blink S/C R/L 0=Cursor shift, 1=Display Shift 0=Left shift, 1=Right shift N 0=1/8 Duty, 1=1/16 Duty (not recommend to set this bit, use jumper setting instead) 0=5x7 dot size, 1=5x10 dot size F A0 to A7 are CGRAM or DDRAM Address Serial input timing diagram SERIAL INPUT Start 8-2 D0 D1 D2 D3 D4 D5 D6 D7 Stop SLCD16x2 TP (Processing time) TP MIN = 5 ms. Start D0 D1 D2 ... MicroCamp : ATmega8 l 75 8.1.5 ( . . , E) , ASCII 0...7, , *See note . .( HD44780A . 1 08h-0Fh, 8 2 SED1278F0A) . 0 10h-17h, ... 7 00h-07h, 38h-3Fh. Example: Load arrow ymbol on CGRAM 3, aprogram wouldssend the following bytes to the SLCD controller. [254] , [01011000 b] , [0] , [254] [01011001 b] , [4] , [254] , [01011010 b] , [2] , [254] , [01011011 b] , [31] , [254] , [01011100 b] , [2] , [254] , [01011101 b] , [4] , [254] , [01011110 b] , [0] , [254] , [01011111 b] , [0] , 76 l MicroCamp : ATmega8 3 SLCD16x2 A3.1 B-end A3.2 3x35 3 JST3AB-8 SLCD16x2 SLCD16x2. 3x10 25 3 . MicroCamp . 35 25 3 A3.3 end JST3AB SLCD16x2 P2 . MicroCamp. . A- MicroCamp : ATmega8 l 77 8.2 soft_serout SLCD16x25 . soft_serout.h. 8N1. 8-1. (P0...P4). 8.2.1 3 . soft_serout_init() . 9600 . void soft_serout_init(unsigned long baud_) : soft_serout_init(9600); 8.2.2 Set the baudrate to 9600 bit per second. serout_byte() . void serout_byte(char tx,unsigned char dat) ; tx 0...4 MicroCamp. P0...P4 dat - : serout_byte(2,0x80); 8.2.3 Send 0x80 data to P2 port. serout_text() . void serout_text(char tx,unsigned char * p) ; tx - . 0 4 P0...P4 *p- : serout_text(2,"MicroCamp"); "MicroCamp" P2. 7 8 l MicroCamp : ATmega8 #include <avr/io.h> #include <in_out.h> #ifndef _soft_serout_ #define _soft_serout_ #define PRESCALER_1 (1<<CS20) #define PRESCALER_8 (1<<CS21) #define PRESCALER_32 (1<<CS21) | (1<<CS20) #define PRESCALER_64 (1<<CS22) #define OFFSET_DELAY1 20 #define OFFSET_DELAY2 18 unsigned int base=0; unsigned char base_start_rcv=0; unsigned char TCCR2_cal=0; unsigned int base; unsigned int baud=9600; // // // // // // void soft_serout_init(unsigned long baud_) { unsigned long tick=0; if(baud_<=4800) { tick = ((1000000/baud_)-OFFSET_DELAY1)/4; TCCR2_cal = PRESCALER_64; } else if(baud_>4800 && baud_<=9600) { tick = ((1000000/baud_)-OFFSET_DELAY2)/2; TCCR2_cal = PRESCALER_32; } TCCR2 = 0; TIFR |= 1<<TOV2; base = 255-tick; base_start_rcv = 255-(tick/2); (1/16M) 0.0625 us per MC (8/16M) 0.5 us per MC (32/16M) 2 us per MC (64/16M) 4 us per MC for out function used 20 us for out function used 20 us // Config.and Start up timer 2 // Calculate Delay for baudrate // Calculate Delay for baudrate // Stop timer // Ensure Clear Overflow flag } // Delay For baudrate void delay_baud(unsigned int _tick) { // TCNT2 = _tick; TCCR2 = TCCR2_cal; // while(!(TIFR & (1<<TOV2))); // TIFR |= 1<<TOV2; // TCCR2 = 0; // } Load Prescaler form calculate Load interval Wait until count success Ensure Clear Overflow flag Stop timer 2 // Send Data 1 Byte void serout_byte(char tx,unsigned char dat) { int i; out_c(tx,0); // start bit delay_baud(base); // Delay for start bit for(i=0;i<8;i++) { out_c(tx,dat & 0x01); // Send data bit 8-1 soft_serout library ( ) MicroCamp : ATmega8 l 79 delay_baud(base); dat=dat>>1; } out_c(tx,1); delay_baud(base); // Delay for calculate base // Shift for next bit // stop bit // Delay for stop bit } // Send More Than 1 byte void serout_text(char tx,unsigned char * p) { while(*p) { serout_byte(tx,*p++); } } #endif 8-1 soft_serout library ( ) 80 l MicroCamp : ATmega8 4 SLCD16x2 A4.1 A4-1. C A4.2 soft_serout library A4.3 . PX-400 . MicroCamp HEX- . . . ISP- A4.4 . A4.5 SLCD16x2. MicroCamp SLCD16x2 . #include <soft_serout.h> #include <sleep.h> void main() { sleep(1000); soft_serout_init(9600); serout_text(2,"MicroCamp"); while(1); } 2 1 1. 2. 1 // // // // 9600 8N1 "MicroCamp" SLCD ; soft_serout.h sleep.h . SLCD16x2. 9600 3. 4. . // “MicroCamp” : . P2 SLCD16x2 . A4-1 SLCD16x2 MicroCamp : ATmega8 l 81 5 SLCD16x2 . h 0xFE . . A5.1 A5-1. C . A5.2 PX-400 HEX- MicroCamp . . ISP- A5.3 A5.4 . SLCD16x2. SLCD16x2 . . 82 l MicroCamp : ATmega8 #include <soft_serout.h> #include <sleep.h> void main() { unsigned char i=0; while (1) { sleep(1000); soft_serout_init(2,9600); serout_byte(2,0xFE);serout_byte(2,0x00); // serout_byte(2,0xFE);serout_byte(2,0x80); serout_text(2,"MicroCamp"); serout_byte(2,0xFE);serout_byte(2,0xC0); serout_text(2,"Microcontroller"); sleep(2000); // // // // "Microcontroller" ! serout_byte(2,0xFE);serout_byte(2,0x01); serout_byte(2,0xFE);serout_byte(2,0x85); serout_text(2,"From"); sleep(500); // // // 5"From" " serout_byte(2,0xFE);serout_byte(2,0x07); for (i=0;i<9;i++) { serout_byte(2,0x20); sleep(200); } // // 9 // # serout_byte(2,0xFE);serout_byte(2,0x05); for (i=0;i<9;i++) { serout_byte(2,0x20); sleep(200); } $ for (i=0;i<9;i++) // { serout_byte(2,0xFE);serout_byte(2,0x08); // sleep(200); serout_byte(2,0xFE); serout_byte(2,0x0C); // sleep(200); } % serout_byte(2,0xFE);serout_byte(2,0x00); serout_byte(2,0xFE);serout_byte(2,0x80); serout_text(2,"Innovative"); serout_byte(2,0xFE);serout_byte(2,0xC0); serout_text(2,"Experiment"); // // // 1 9600 8N1 "MicroCamp" 1- // <<<<<< 9 // // // // // // 9 "Innovative " 1"Experiment" 2- } } A5-1 SLCD16x2 ( . ) MicroCamp : ATmega8 l 83 SLCD16x2. 1 . 2 MicroCamp. 3 (0x80) Microcontroller. (0x01) From. (0x07) (0xC0) (0x85) 4 5From . 5 From (0x05) . 6 (0x08) . (0x0C) From. 7 Innovative A5-1 2, Experiment SLCD16x2 . ( ) MicroCamp : ATmega8 l 84 9 MicroCamp 7 . . MicroCamp PC0...PC4 . 5ATmega8. , 100 1,023 . . analog.h. , . 1,023 0000H 0 03FFH . . . ( ). . +V TCRT5000 OUT 10k 9-1 : ZX-03 ND 510 85 l MicroCamp : ATmega8 9.1 ZX-03 TCRT5000. . , . , . , . , ZX-03 . 3 0.1 4.8 , 9.2 8 . 20 1,000. analog: analog.h PC0...PC5. . unsigned int analog(unsigned char channel) channel: . P0...P4. 0 1023. 0 4 MicroCamp : ATmega8 l 86 6 . , . A6.1 analog A6.2 A6.3 . . PX-400 . MicroCamp HEXISP- . - A6.5 30 x 30 . . A6.4 30 A6-1. C . . - 30 x 8 7 l MicroCamp : Kvint #include <stdlib.h> // // #include <soft_serout.h> #include <analog.h> #include <motor.h> #include <sleep.h> void lcd_command(unsigned char pin,unsigned char command) { serout_byte(pin,0xFE);serout_byte(pin,command); } int main() { unsigned int l_sensor=0,r_sensor=0; unsigned char dec1[4],dec2[4]; sleep(1000); // 1 soft_serout_init(2,9600); // 9600 8N1 while(1) { l_sensor = analog(3); // r_sensor = analog(4); // utoa(l_sensor,dec1,10); // Integer utoa(r_sensor,dec2,10); // Integer lcd_command(2,0x80); // 1serout_text(2,"L Sensor= "); // 1lcd_command(2,0x8A); serout_text(2,dec1); // Ascii lcd_command(2,0xC0); // 1serout_text(2,"R Sensor= "); // 1lcd_command(2,0xCA); serout_text(2,dec2); // Ascii sleep(300); } } ATmega8 . A6-1 . , Ascii Ascii MicroCamp : Kvint l 88 ( A6.6 . A6.4) , . . . L Sensor= 250 R Sensor= 250 L Sensor= 550 R Sensor= 550 : 600 100 (600+100) /2 = 350. 950 300 8 9 l MicroCamp : Kvint 7 . (1) : . , (2) - : . . , (3) - : . . , -1 A7-1 -2 -3 MicroCamp : Kvint l 90 #include #include #include #include unsigned <in_out.h> <sound.h> <analog.h> <motor.h> int AD0=350,AD=350; // // void main() { while((in_d(2)==1)); SW1 // while(1) { if((analog(3)>AD0)&&(analog(4)>AD1)) forward(100); if (analog(0)<AD0) s_left(100); if (analog(1)<AD1) s_right(100); - // // // // // // - } } A7-1 : A7.1 . . . . A7.2 A7-1. . A7.3 PX-400 ISP- . A7.4 HEX- MicroCamp . . SW1. . . . 91 l MicroCamp : Kvint 8 7. , MicroCamp 2- . . . , . . A8-1. A8.1 7. . . 2 . A8-1. A8.2 . A8.3 PX-400 ISP- . A8.4 HEX- MicroCamp . . SW1. . , , . . : . . . . MicroCamp : Kvint l 92 #include <in_out.h> #include <sound.h> #include <analog.h> #include <motor.h> unsigned int AD0=350,AD1=350; unsigned char i=0,j=0; void main() { while((in_d(2)==1)); // // // SW1 // while(1) { if((analog(3)<AD0)&&(analog(4)<AD1)) { j++; backward(30); sleep(10); motor_stop(ALL); for (i=0;i<j;i++) { sound(2500,100); sleep(50); } forward(100); sleep(300); // // // // // // } if((analog(3)>AD0)&&(analog(4)>AD1)) forward(100); if (analog(3)<AD0) s_left(100); if (analog(4)<AD1) s_right(100); } } A8-1 . // // // // // // - MicroCamp : Kvint l 93 10 . GP2D120, . , . 10.1 GP2D120 l 4 l 5 , 4.5 l 30 33 0.4 l . 2.4 +5 ( ) 2.8 2.4 2.0 1.6 /2 , 1.2 0.8 Vout GND Vcc 0.4 0 0 4 8 12 16 20 24 ( * 38.3±9.6 ms 1- Kodak n- 2- 90%. n- 5 ms 10-1 : * GP2D120 32 R-27. 2- 1- Vout 28 ) GP2D120, MicroCamp2.0 , . 94l MicroCamp : Kvint 3- GP2D120 : (Vcc), (GND) (Vout). GP2D120, 32...52.9 0.25 GP2D120 4 , 0.55 . . ( 30 +5 ) 2.25 ± 0.3 . 10.2 . , . . . , , . , . . - . , , : (L) L F = A X , ×A L= F X L A , . F GP2D120 X MicroCamp : Kvint l 95 10.3 GP2D120 GP2D120 , Vout = 0.5 . 6 . 26 , Vout = 2V 10-1 GP2D120 . , . , 307 8 . GP2D120™s Vout 10-1: GP2D120™, . 96l MicroCamp : Kvint 9 GP2D120 x2 x2 x4 3x10 x4 3 x4 GP2D120 ( MicroCamp2.0 Standard) GP2D120 MicroCamp. , GP2D120 . MicroCamp. . A9.1 3 x 10 GD2D120, . 3 . A9.2 . , ( ) A9.3 . A9.4 . . MicroCamp : Kvint l 97 A9.5 . GP2D120 3 x 10 A9.6 GPD120 P0 3 , . P0 . 98l MicroCamp : Kvint 10 MicroCamp analog(). GP2D120 GP2D120 : R = (2933 / (V + 20)) - 1 ; RV- . 0 1,023. , A10.1 A10.2 analog A10.3 A10-1. . PX-400 . HEX- MicroCamp . A10.4 ISP- A10.5 SLCD16x2. A10.6 . GP2D120. . , GP2D120 4 30 . MicroCamp : Kvint l 99 #include <stdlib.h> // #include <soft_serout.h> // #include <sleep.h> // #include <analog.h> // #define m 2933 // #define b 20 #define k 1 void main() // { unsigned char dec[4],dec2[4]; unsigned int gp2=0,cm=0; sleep(1000); soft_serout_init(2,9600); ascii // // // // 1 9600 8N1 while(1) { gp2 = analog(0); // cm = (m/(gp2+b)) - k; // utoa(gp2,dec,10); // utoa(cm,dec2,10); // serout_byte(2,0xFE);serout_byte(2,0x00); serout_byte(2,0xFE);serout_byte(2,0x80); serout_text(2,"RAW Data= "); serout_text(2,dec); serout_byte(2,0xFE);serout_byte(2,0xC0); serout_text(2,"Distance= "); serout_text(2,dec2); serout_byte(2,0xFE);serout_byte(2,0xCE); . Ascii . Ascii Integer Integer // // 1Ascii 2- // // // // // 214- serout_text(2,"CM"); sleep(500); } } (1) SLCD16x2. (2) P0 . (m/(gp2+b)) - k. (3) (4) ASCII (5) 0,5 SLCD16x2. . GP2D120, A10-1 : SLCD16x2 100l MicroCamp : Kvint 11 A11-1. , A11.1 A11.2 analog A11.3 . PX-400 . HEX- MicroCamp . ISP- A11.4 . . A11.5 . A11.6 . 8 . . , , , . < 8 cm. 1 2 3 4 MicroCamp : Kvint l 101 #include #include #include #include #include <stdlib.h> <motor.h> <sleep.h> <sound.h> <analog.h> // // // // void main() { unsigned int sensor=0; unsigned char i=0; sleep(200); sound(4000,50); while(1) { sensor=0; for (i=0;i<5;i++) { sensor=(sensor+analog(0)); } sensor=(sensor/5); if (sensor>260) { backward(50);sleep(800); s_left(50);sleep(600); } else { forward(50); } } } (1) // // GP2D120 5 // // // < 8 ? // // . (2) GP2D120 . 5 . (3) . 320 0.8 8 . 50%. (4) . , , 320, (5) . A11-1: GP2D120. 0.6 . MicroCamp : Kvint l 102 11 8 SLCD. . . - ER-4. . 38 . . 38 ER-4 . . 11.1 ER-4 l 4 8 l4 . l l . . 2.4-3.0 AA. l RS-232 1200 bps 8N1 +3-5V K A IR-LED "A" Easy remote4 "B" "C" C B A ER-4 3 SW3 V,, GP1 IC1 ER4-FW 2 R1 1k Q1 BC338 GP2 GP4 GND 8 (B) 11-1 : * 5 SW3 "D" GP0 GP5 6 SW2 D (A) 7 SW1 2-5V LED1 IR-LED 1 (C) ER-4 ZX-IRM 38 Standard. MicroCamp2.0 Beginner. 103l MicroCamp : Kvint 11.1.1 ER-4, 1,200 bps RS-232 8N1. 11-1. . A, A, a. B, B, b. C, C, c. D, D, d. . , . , , . 11.2 ZX-IRM (5...10 ) 38 38 . , . . , 38 , 38 “1”. , “0”. 0.1uF 50V 3 1 1 Out 3 2 2 3 cc 11-2 : Out GND 2 GND 1 Vcc 38 MicroCamp : Kvint l 104 12 3x10 3 x2 x1 x1 A12.1 3x10 ZX-IRM 38 ZX-IRM 3 x1 . . nut. A12.2 . ER-4. A12.3 ZX-IRM IRM MicroCamp. IRM 3x10 105l MicroCamp : Kvint 11.3 C serial.h file. , UART ATmega8. uart_set_baud() uart_get_key(). . 11.3.1 uart_set_baud(); ATmega8. UART void uart_set_baud(unsigned int baud) ER-4 1200 . : uart_set_baud(1200; 11.3.2 uart_get_key(); 1 30 RxD (timeout). . char uart_getkey(unsigned int timeout) : key=uart_getkey(20000); key. ATmega8. 20,000 MicroCamp : Kvint l 113 13 , ER-4 A12-1. , A12.1 serial.h A12.2 A12.3 . PX-400 . HEX- MicroCamp . ISP- A12.4 A12.5 2 A12.6 . AA ER-4. . ZX-IRM ER-4 MicroCamp. , SLCD. SLCD . Yo u Press Key C 107l MicroCamp : Kvint #include #include #include #include #include #include <stdlib.h> <soft_serout.h> <sleep.h> <serial.h> <sound.h> <motor.h> // // // // // // SLCD unsigned char key,flag=0; unsigned char dec[4],bin[9]; void main() { sleep(1000); // soft_serout_init(0,9600); // uart_set_baud(1200); // sound(2000,200); // serout_byte(0,0xFE);serout_byte(0,0x01); serout_byte(0,0xFE);serout_byte(0,0x80); serout_text(0,"You Press Key "); 1 9600 8N1 // // while(1) // { key=uart_getkey(20000); // if ((key!=flag)&&(key>0x40)&&(key<0x7F)) // { serout_byte(0,0xFE); serout_byte(0,0x8E); // serout_byte(0,key); flag=key; } } timeout 33 } 2 (1) 1 serial.h SLCD. (2) SLCD 9,600 (3) . . ER-4 1,200 (4) . "You Press Key". (5) (6) ER-4. . (7) , . A12-1 : ER-4 C . soft_serout.h. MicroCamp : Kvint l 108 14 12, MicroCamp A, B, C, D a, b, c, d. ER-4 8 , ER-4 : K A IR-LED , + * ) -D - -A - -C - a c -B - d b . serial.h A13.2 A13.3 . PX-400 . MicroCamp . A13.4 A13-1. , A13.1 ISP- . HEX- 109l MicroCamp : Kvint #include #include #include #include #include #include unsigned <stdlib.h> <soft_serout.h> <sleep.h> <serial.h> <sound.h> <motor.h> char key,flag=0; // // // // // // void main() { sleep(1000); soft_serout_init(0,9600); uart_set_baud(1200); // // // SLCD 1 sound(2000,200); // serout_byte(0,0xFE);serout_byte(0,0x01); // serout_byte(0,0xFE);serout_byte(0,0x80); // serout_text(0,"Press any IR Key"); // while(1) { key=uart_getkey(65000); // if ((key=='a')||(key=='A')) // "A" { backward(100); if (flag!=1) // "Backward" { serout_byte(0,0xFE); serout_byte(0,0xC0); serout_text(0,"Backward "); flag=1; } } else if ((key=='d')||(key=='D')) // "D" { forward(100); if (flag!=2) // "Forward" { serout_byte(0,0xFE); serout_byte(0,0xC0); serout_text(0,"Forward "); flag=2; } } else if ((key=='c')||(key=='C')) // "C" { s_left(100); if (flag!=3) // "Turn Left" { serout_byte(0,0xFE); serout_byte(0,0xC0); serout_text(0,"Turn Left "); flag=3; } } else if ((key=='b')||(key=='B')) // "B" A13-1: ( ) 9600 8N1 timeout 33 MicroCamp : Kvint l 110 { s_right(100); if (flag!=4) { serout_byte(0,0xFE); serout_byte(0,0xC0); serout_text(0,"Turn Right"); flag=4; } // } else {motor_off();flag=0;} "Turn Right" // } } ( A12-1) . . . ( A13-1: ) A13.6 . A13.7 . ER-4 . ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ ○ . .
Similar documents
Animateering: Puppet Workshop Console Component / Connection
Happ Jumbo Dome Illuminated Pushbutton
More information