MA-VIN PROGRAMMER GUIDE

Size: px
Start display at page:

Download "MA-VIN PROGRAMMER GUIDE"

Transcription

1 MA-VIN PROGRAMMER GUIDE

2 [MA-VIN] CONTENTS 1. Outline 2. Program Installation 3. Output Modules 3.1. LED 3.2. Buzzer Segment 3.4. DC Motor 3.5. LCD 3.6. Speaker 4. Input Modules 4.1. Push Switch 4.2. Touch Switch 4.3. Infrared Ray Sensor 4.4. CdS Sensor 4.5. Microphone 4.6. Remote Control 5. Practical Examples 5.1. Line Tracer 5.2. Obstacle Avoidance 5.3. Following a Finger 5.4. Passing an Intersection 5.5. Function Selectable Robot 2 of 138

3 1. What is AVR? i. AVR series microcontroller, an 8-bit controllable microprocessor, is released the first time in 1997 by Atmel, which is established in 1984 in the U.S. Its name is known to be designated by Alf-Egil Bogen and Vegard Wollen, and some says it is a simpler form of Advanced Virtual RISC. ii. Based on the Harvard architecture that uses a bus independently when program memory and data memory are accessed and the RISC (Reduced Instruction Set Computer) technology based on a pipeline processing method, AVR boasts an extraordinary fast command processing speed. By integrating AVR and the flash memory technology of Atmel, which is the Atmel s strength, a flash memory for program is built-in the chip. In addition, AVR has applied the ISP (In-System Programming) method, which allows a user program to be easily downloaded. In spite of very late come out, AVR has gained popularity in a short time that surpasses 8051 series or PIC series of microcontroller, which dominated the most of market in those days, due to these advantages. iii. Havard Architecture & Von Neumann Architecture Mostly used architecture of microcontroller or microprocessor is divided into Harvard architecture and Von Neumann architecture, where the modified architecture of them is used when it is applied to an actual microcontroller. As an example of 8051, the data and program memory bus are divided in a chip. However, when the chip is connected externally, the bus should be multiplexed (MUX) and used an identical external pin, which is known as the modified Harvard architecture. Generally, Harvard architecture is primarily used in DSP products made by TI or 8051 made by Intel, whereas the most of general microprocessors and microcontrollers adopt Von Neumann architecture. MA-VIN uses ATmega64 processor, where program memory exists only in the inner part of chip, and the address and data bus connected to the external are connected to data memory. Thus, it holds Harvard architecture that separates all program, data memory and bus in the inner and outer part of chip. Harvard Architecture - Using separate memory and bus for program and data. - Developed by Harvard s physicist, Howard Aiken, in the late 1930 s. - Developed by Harvard MARK I computer in Von Neumann architecture - Command and data use a single memory space. 3 of 138

4 - Allows simplifying the computer design. - Structure is developed by Von Neumann from University of Pennsylvania between 1943 and 1946, which is selected from ENIAC. - Possible to access either command or data at one time. Data Memory CPU 8 16 Program Memory CPU 8 Program & Data Memory < Harvard > < von Neumann> iv. Characteristics of AVR It is a unique 8-bit microcontroller, where the command is processed by 16-bit hardware bus whereas the data is based on 8-bit word length. Since it uses the advanced RISC architecture and the pipeline processing method, the power consumption is very low and the most of commands are executed in a single clock cycle. Instead of an accumulator-oriented, it has the register-oriented architecture having 32 general-purpose registers. It is designed greatly favorable for c language program such as possessing a simpler addressing mode and precise program code size. The performance is improved by using the Harvard architecture because both program memory and data memory can be accessed simultaneously. Program memory holds 1KB to 256 KB of memory according to the model. Since AVR has all program memory within MCU element, the program memory cannot be connected from the outside. Since the internal flash memory for program-purpose uses the serial communication method of ISP function, user can easily download a program. This flash memory allows the user to repeat programming up to 10,000 times. Since AVR holds 64 bytes to 4 KB of EEPROM according to the model, data backup is possible. This EEPROM allows the user to repeat programming up to 100,000 times. AVR contains the data memory within the relatively large size of SRAM, where the size of data memory varies from 64 bytes to 8 KB according to the model. According to the model, AVR holds various I/O functions such as parallel I/O port, clock oscillator in internal system, 8-bit timer, 16-bit timer, watchdog timer, UART or USART, SPI, TWI, analog comparator, 10-bit A/D converter, PWM signal, RTC (Real Time Counter), and BOD (Brown 4 of 138

5 Out Detector). Since the model can have external bus, data memory or I/O device can be expanded by using this external system bus. However, the program memory cannot be expanded. Has various interrupt sources and interrupt processing functionality. Has approximately 90 to 135 numbers of commands according to the model, where the hardware multiplier is built-in a high-performance superior model, which allows using the multiplier command that runs in 2 clock cycles. Has various power-saving modes including slip mode. In order to select the proper model for various application fields, three types of family (ATtiny, AT90, and ATmega) are designed for its functionality and performance. v. Characteristics of ATmega64 ATmega64 is an 8-bit microcontroller that has 64 KB of IPS (In-System Programmable) flash memory. The data sheet of ATmega64 provided by Atmel presents the following specifications of this chip: High performance and low powered AVR 8-bit microcontroller Enhanced RISC structure Nonvolatile program memory and data memory JTAG(IEEE std compliant) interface Possibility of parallel operation Operates in the range of 4.5 ~ 5.5 V & 0 ~ 16 MHz For more detailed information of each item, please refer to the manual of ATmega64. <Screenshot of ATmega64 attached on MA-VIN> 5 of 138

6 2. Program Installation Installing WinAVR Basically, AVR that we are trying to use is a programmable chip developed in the UNIX environment. WinAVR is a tool that holds the avr-gcc internally, which allows making and downloading this in the Window environment. If this program is used in the Window environment, c language source code of AVR can be edited and compiled. 1. Run the install file of WinAVR. 2. When the following image appears, click OK button. 3. When the following image appears, start the installation by clicking Next [Weiter] button. 6 of 138

7 4. The following image is related with the right of use agreement. Since WinAVR is a freeware, continue the installation by clicking Agree [Annehmen] button. 5. The following image asks for the installation folder. Basically, it is recommended to use the folder that is set. Continue the installation without any modification by clicking Next [Weiter] button. 7 of 138

8 6. When the elements of program are selected, click Install button. 7. The following image shows the installation process. 8 of 138

9 8. The following image appears when the installation is completed. Finish the installation by clicking Finish [Fertig stellen] button. 9. The following image is the screenshot of WinAVR when it is run. When the program made in WinAVR properly completes both compile and building process, *.hex file having the identical name of the program will be generated. If this file is downloaded by using the HEX download program, MA-VIN will run the program. 9 of 138

10 10. The following image shows the process when a program is downloaded into AVR. 10 of 138

11 3. Output Module 3.1. LED What is LED? LED is an abbreviated form of light-emitting diode, which is a semiconductor element that emits light when a forward voltage is applied. Radiation principle uses the electroluminescence effect. Its life span is considerably longer than incandescent light and it can create one that emits ultraviolet light, visible ray, and infrared ray according to the used material. Figure Structure of LED and energy band structure LED is made up of the structure called pn junction, which uses a semiconductor. In the pn junction, an electron that holds energy is directly converted into light energy. Electron and holes that are injected from an electrode to the semiconductor flow on the other energy band (conduction band or valence band) and recombine around the pn junction after passing the band gap. When they are recombined, a considerable amount of energy is released from the band gap as a photon, which is a light. As an electric characteristic, it has the identical polarity of the general diode and uses it by applying a constant voltage from cathode to anode. When the voltage is low, the current does not flow and the radiation does not occur. However, when the voltage is above a certain threshold value, the current flows rapidly due to the rise of voltage and the light is generated according to the quantity of current. This voltage is called a forward voltage drop, which is higher than the general diode. According to the radiation color and the quantity of output radiation, there exists a difference between this forward voltage drops. When the voltage is applied in reverse direction, the withstanding voltage (generally -5 V) is lower than the general silicon diode and the element breaks down if it exceeds. Note that it cannot be used as a rectifier. 11 of 138

12 Operating Method of LED in MA-VIN First of all, the method for operating LED module in MA-VIN is explained. Total of 5 extendable modules can be attached or taken off from MA-VIN, where each module is connected to ATmega64 processor. It is assumed that LED module is connected to slot #1 at this point. Figure LED module Figure Circuit diagram of LED module #1 Figure Slot #1 Figure Circuit diagram of slot LED Module Slot #1 Processor Description PIN_1 PIN_1 PIN_10 PB0 PIN_2 PIN_2 PIN_11 PB1 PIN_3 PIN_3 PIN_12 PB2 PIN_4 PIN_4 PIN_13 PB3 Table Connection between module, slot, and processor LED provided by MA-VIN is a common anode type, where the forward voltage must be provided to the LED. In addition, the voltage drop must be occurred through LED for LED to operate. 12 of 138

13 type Figure Common anode type Figure Common cathode Thus, when LOW value is given to port that operates LED, there is a voltage difference between the supply voltage of +5V and the port voltage, which turns the diode on. As one of the example of LED module in MA-VIN, the program that turns LED 1 to LED 4 on in order and turn off in reverse order is shown. Figure shows the basic flow chart of the process of turning on/off LED Flow Chart Figure Flow chart of LED module operation 13 of 138

14 As shown in the above flow chart, the use of DDR must be set at first. DDR is a register called Data Direction Register, which determines the direction of input and output data. When the value of DDR is 0, it operates as an input, whereas it operates as an output when the value is 1. Since we are using it as data output here, the value of DDR is set to 1. LED can be turned on by giving a set command to the register, which sets the port to either HIGH or LOW. In order to turn LED off, a clear command is given to the port register. The commands that give the value of DDR and port are sbi (set bit in I/O) and cbi (clear bit in I/O). Keep in mind that LED only turns on when there is a voltage difference, where the supply voltage of +5V is provided to the LED module. Thus, in order to turn LED on, the value of port register must be set to LOW, which makes the difference compared to the voltage supplied to the module. Always remember this point and let s examine the following example program Example Program 1 : #include "newbeetle.h" 2 : void main( void ) 3 : { 4 : Initialize(); 5 : sbi(ddrb,0); sbi(ddrb,1); sbi(ddrb,2); sbi(ddrb,3); 6 : u08 i; 7 : while(1) 8 : { 9 : for(i=0;i<4;i++) 10 : { 11 : cbi(portb,i); 12 : msecdelay(7); 13 : } 14 : for(i=0;i<4;i++) 15 : { 16 : sbi(portb,3-i); 17 : msecdelay(7); 18 : } 19 : } 20 : } The above program turns on LED of LED module of MA-VIN, which is connected to slot #1, from LED 1 in order and turns off in reverse order 14 of 138

15 Line 1: newbeetle.h is the header file, which includes the general constants, the declaration of variables and functions used in MA-VIN. In the header file, functions that are needed to use each module such as initialization function and delay function are stored. Since the set values of each module are defined in the header file, MA-VIN can be easily operated by calling the functions within the header file. It is prior to understand the operation principle of processor instead of calling the functions recklessly in the initial process. Thus, it is recommended to use within the main function instead of using the method of function call. When the complex function is necessary in the final process, the method of calling this function of header file is used. Line 4: Initialize function initializes the processor, which is defined in the header file. Various purposes of initial value are fixed in the function. Detailed description about this function is explained later. For now, remember that the processor can be used for our purposes through this function. Line 5: sbi command represents Set Bit Input/output command, which sets the value of specified register to 1 (HIGH). DDR represents a Data Direction Register, which determines whether each port of processor is used as an input or output according to the bit value of this register. If the value of DDR is 0, it is an input whereas it represents an output if the value is 1. DDR can be set for each port. The meaning of sbi(ddrb, 0) to sbi(ddrb,3) is that 0 to 3 of B register of processor are used as an output. Line 6: u08 i command represents declaring a variable i. It will be easier to understand if you remember declaring int i in c language. If int declares a positive number variable, u08 means declaring 8-bit variable. In other words, i is the variable that has the value from to Line 11: cbi command represents a Clear Bit Input/output command, which sets the value of specified register to 0 (LOW). This command is opposite to sbi. cbi(portb,i) command means setting the value of port register to 0 (LOW) according to the value of i. Port register sets the operation of each port, which adjusts the output value through the pin of each port to either 1 (HIGH) or 0 (LOW) according to the value of port register. Since the value of port register and the output value of pin according to the value of port register are identical, port register is called as port for convenience from now on. When the value of port becomes 0, LED starts to turn on due to the design property of LED module. Each LED of LED module receives the supply voltage from the port and GND uses a common anode type (receives the supply voltage from the external) instead of common cathode type (receives the supply voltage from the slot). Thus, LED is not turned on when the value of port is HIGH because there is no voltage difference. However, when the value of port becomes LOW, there exists a voltage difference between the received voltage of LED and the port, which turns LED on. Keep in mind that the value of port must be LOW in order to use LED module. 15 of 138

16 Line 12: msecdelay command provides a delay to the processor, which is used when the time control is required. Since the command of MA-VIN processor executes in a micro-second unit, it operates faster than the limit of our eye sight. Thus, a fixed time of delay is required to check the results by our eyes. The delay command is used at this time and the function that adjusts this delay is defined within the header file. Since the descriptions related to delay are explained in the module that uses a system clock, refer to that section. When the above program is downloaded to the processor, MA-VIN repeats turning on LED of LED module that is attached to slot #1 from LED 1 to LED 4 in standard order, and turning off in reverse order. In the next subchapter, let s practice more about controlling the port through the operation of buzzer. 16 of 138

17 3.2. Buzzer What is Buzzer? Buzzer is a tool that generates a dial tone by combining electromagnet and diaphragm, and generates an alternating current (AC) from the direct current (DC) voltage. At here, it describes the tool that generates a dial tone. There are two types of signal buzzer: a direct current type and an alternating current type. For the DC type of buzzer, a metal rolled around with the coil acts as an electromagnet. A spring is attached to the diaphragm, which creates a sound during the collision between diaphragm and the point of contact when the current flows. For the AC type, it is similar to the DC type, but there is no point of contact. Instead, it uses an alternating current frequency to create a vibration. Figure Buzzer module Figure Operating method of buzzer Operating Method of Buzzer in MA-VIN Figure Circuit diagram of buzzer module 17 of 138

18 Since the buzzer can be either attached or taken off as a module in MA-VIN, the basic contents are almost similar to LED. Once the module is connected to one of the slot between slot #1 and slot #5, and the basic configuration is done, the buzzer can be simply operated. Let s use the port D of ATmega64 processor this time. Figure Connection between buzzer module and processor Buzzer Module Slot #2 Processor Description PIN_2 PIN_2 PIN_26 PD1 Table Connection between buzzer module, slot #2, and processor Since the buzzer can be simply operated by giving a HIGH/LOW value to the port, it only uses PIN_2 of the slot. In other words, it can be operated by giving a HIGH/LOW value to the first of PORTD (PD1 in circuit diagram) because PIN_2 of the slot is connected to the 1 st pin of port D of processor. 18 of 138

19 Flow chart Figure Flow chart of buzzer operation The flow chart in Figure shows the process to operate a buzzer. When the DDR register is set as an output after passing through the initialization steps, buzzer can be operated by making the value of port register connected to the buzzer to HIGH. As we examined the circuit diagram of buzzer in MA-VIN before, it operates when the voltage is provided to the 2 nd pin of module. Unlike LED, buzzer gets its voltage from the processor (keep in mind that LED used the voltage difference between the supply voltage of port and module). In other words, the sound of buzzer can be heard by making the port of processor HIGH and providing a voltage to the module (sbi = set bit in I/O = make the value of register to HIGH). The following example shows the process of ringing and turning off the buzzer. You can observe that the buzzer can be operated according to the HIGH/LOW value of port after setting the value of DDR as an output. In order to verify the operation of port, the control of port is confirmed through the generation of beep sound after a delay. 19 of 138

20 Example Program 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); 5 : sbi(ddrd, 1); 6 : while(1) 7 : { 8 : sbi(portd,1); 9 : msecdelay(1); 10 : cbi(portd,1); 11 : msecdelay(10); 12 : } 13 : } Line 1: declares the use of newbeetle.h header file. Line 4: advances the initialization process in order to use the processor. Line 5: declares the port in order to use it as an output. Line 8: when the value of port becomes HIGH, the buzzer starts to operate by sending out the output having the value of 1 (HIGH) through the pin #1 of port D. Line 9: after elapsing a certain period of time. Line 10: stops the buzzer operation by making the output to 0 (LOW). 20 of 138

21 Example Program 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); 5 : int i,j; 6 : while(1) 7 : { 8 : for(i=1; i<5; i++) 9 : { 10 : sbi(ddrb, i-1); 11 : sbi(ddrd,1); 12 : cbi(portb,i-1); 13 : for(j=0; j<i; j++) 14 : { 15 : sbi(portd,1); 16 : msecdelay(5); 17 : cbi(portd,1); 18 : msecdelay(5); 19 : } 20 : sbi(portb, i-1); 21 : msecdelay(5); 22 : } 23 : } 24 : } The above program distinguishes the LED number by using a beep sound. In other words, when the first LED turns on, it rings one beep sound whereas it rings two beep sounds when the second LED turns on. Let s examine the following flow chart in order to understand the above program. The basic flow of flow chart does not deviate from the operation of LED and buzzer. 21 of 138

22 Flow Chart DDR i =? i PORT LED / / ON j LED Figure Flow chart of buzzer operation according to LED order After the initialization steps, the program defines the value of DDR as an output by making this value HIGH in order to turn LED on. Also, it sets the values to ring a buzzer when the port is operated (when the value of port register is HIGH). Since the buzzer rings according to the number of port, when a certain number of port is selected, the buzzer must be rang according to the number of port by providing a HIGH value to the port. Then turn the buzzer off by giving a LOW value. In order to turn the next number of LED on, provide a HIGH value to the LED port and turn off all LEDs that are currently turned on. Then, make the value of port to LOW in order to turn the next LED on and repeat the earlier process. If this process is repeated, the program that rings the buzzer according to the LED number gets completed. 22 of 138

23 programmer guide Screenshots of LED & Buzzer When the Program is Running Figure Screenshots of the result of buzzer operation according to LED order Exercises 1. Make a counter that displays from 0 to 15 by using 4 LEDs. 2. Make a program that sounds a dial tone once for each counting in #1. 3. According to the value of counter, make a program that distinguishes the number by using the dial tone in #1. HINT1. HINT1. Assuming that LED is : turned on and : turned off, the numbers can be represented as follows: : 0 : 1 : 2 : 3 : 4 : 5 : 6 : 7 : 8 : 9 : 10 : 11 : 12 : 13 : 14 : 15 HINT2. Insert cbi command to turn LED on and sbi command to turn buzzer on at the same time. 23 of 138

24 programmer guide Segment Summary of 7-Segment Figure Screenshots of 7-segment module and the module is connected to MA-VIN 7-segment as the name indicates is made up of seven small display elements. Since these seven elements are possible to turn on or off individually, the representations of number between 0 and 9, and alphabet between A and G are possible through the combination of elements. In other words, the representation of 16 (hexadecimal) HEX digits is possible by using the 7-segment. Let s examine the following combinations: Figure Hexadecimal representation (0 ~ F) of 7-segment module 24 of 138

25 In order to display a hexadecimal using 7-segment, each element must be controlled individually. The next is the circuit diagram of 7-segment in MA-VIN. Figure Circuit diagram of 7-segment module For the operation of 7-segement, MA-VIN uses a special chip called 74HC595. This chip has the characteristics of 8-bit data series input and parallel output. 74HC595 contains the following characteristics: a. 8-bit series input b. 8-bit series or parallel output c. Storage register that holds 3-state output d. Direct erasable shift register e. 100 MHz variable frequency Table is the function table of 74HC595. INPUT OUTPUT SH_CP ST_CP OE MR DS Q7' Qn X X L L X L n.c X L L X L L X X H L X L Z X L H H Q6' n.c X L H X n.c Qn' L H X Q6' Qn' Table Function table of 74HC of 138

26 Figure HC595 and its connection in MA-VIN In Figure 3.3.4, you can confirm how 74HC595 is connected in MA-VIN. From Q1 to Q7 correspond to QA to QH in MA-VIN, respectively, where QA to QH represent parallel output and QH represents series output. Since QH is not used in MA-VIN, you can notice that MA-VIN does not use series output. Table is the pin description of 74HC595. PIN SYMBOL DESCRIPTION 1 Q1 parallel data output 2 Q2 parallel data output 3 Q3 parallel data output 4 Q4 parallel data output 5 Q5 parallel data output 6 Q6 parallel data output 7 Q7 parallel data output 8 GND Ground 9 Q7' serial data output 10 MR master reset(active Low) 11 SH_CP shift register clock input 12 ST_CP storage register clock input 13 OE output enable(active Low) 14 DS serial data input 15 Q0 parallel data output 16 Vcc positive supply voltage Table Pin description of 74HC of 138

27 Flow Chart DDR YES NO Figure Flow chart for generating 7-segements data Let s examine the method of using 7-segment in MA-VIN through the following simple program. 27 of 138

28 Example Program 1 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); 5 : u08 i,data; 6 : char segment[16]={0x48,0xeb,0x8c,0x89,0x2b,0x19,0x18, 7 : 0x4b,0x08,0x09,0x0a,0x38,0x5c,0xa8,0x1c,0x1e}; 8 : //-----fnd port IO setup for 7segment operation : sbi(ddrb, 0); sbi(ddrb, 1); sbi(ddrb, 2); 10 : // : cbi(portb,2); 12 : while(1) 13 : { 14 : // : data=segment[7]; 16 : for(i=0;i<8;i++){ 17 : if((data<<i) & 0x80){ 18 : sbi(portb,0); 19 : }else{ 20 : cbi(portb,0); 21 : } 22 : // : sbi(portb,1); 24 : cbi(portb,1); 25 : } 26 : // : sbi(portb,2); 28 : } 29 : } The above example displays the number 7 on 7-segment. Line 6: it is the array of data to represent 0 to F, which is the output of 7-segment. It is a value to display on the segment after selecting the desired output data. Since this value can be changed according to the circuit design, keep in mind that you won t be able to obtain the desired output in MA-VIN if the values are changed voluntarily. Line 7: assumes that 7-segment module is connected to slot #1 in the program. Thus, Data Direction Register becomes B. Since Data Direction Register Bit must be HIGH to turn 7-segment on, the output is set up by sbi command. 28 of 138

29 Line 10: to understand the statement, Latch is set to 0, understanding the operation of 74HC595 is necessary. This can be verified in the function table of 74HC595 (Table 3.3.1). Figure shows the logic diagram of 74HC595, which will help you the understanding of function table. Figure Logic diagram of 74HC595 As shown in Figure 3.3.6, 74HC595 uses two clocks: SH_CP and ST_CP. As described in the pin description of 74HC595 (Table 3.3.2), SH_CP and ST_CP are used as the register clock of 74HC SH_CP shift register clock input 12 ST_CP storage register clock input Since these two clocks operate when they are high-edge as shown in the function table, they act as a clock when the initial value is set to 0 and changes to 1 afterward. In that case, let s examine the circuit in MA-VIN now. In MA-VIN, PIN1 to PIN3 are connected to SER, SRCK, and RCK. You have confirmed that RCK and SRCK in the circuit (Figure 3.3.4) act as a clock. If you verify the PIN number, PIN2 and PIN3 are used as SH_CP and ST_CP, respectively. Since this corresponds to the port 1 and port 2 (assuming it is connected to slot #1), the port value, which will be used as a clock, can be adjusted by changing the setting as below. 29 of 138

30 74HC595 uses two clocks. First of all, the reason for setting the clock of latch can be understood by looking at the logic diagram. When the DS input enters into the flip-flop, the output value of flip-flop goes to the input of latch according to SH_CP. Then the final output value comes out according to the operation of ST_CP. Since the outcome is obtained according to ST_CP, the value of ST_CP is made to 0. Line 14: next is the transmission of data. The total number of inputs of 74HC595 is three: two of them are used as clock, and substantial input that is used to represent data is one, which is connected to PIN 1. Keep in mind that 74HC595 is an 8-bit serial input. Data uses the value in array, which has the output value of segments. Let s examine for loop statement. Since 74HC595 is a serial input, the value of data must be stored in consecutive order. Since the input has an 8-bit, the data is entered over 8 times. Table will help you the understanding of data input. Number 7(0x4b) & 0x80 i & Port On/off Value sbi Off cbi On sbi Off sbi Off cbi On sbi Off cbi On cbi On 1 Table Example of 74HC595 data input Data Input Direction Table is an example of entering the number 7. Remember that 7 is treated as a character instead of a constant. The value related to 7 is represented as 0x4b, which can be verified in the array. 0x4b has the value of in binary representation. In Table 3.3.3, the value of is entered in order. Since the input voltage, Vcc, is supplied to the segment module, LED on the segment module turns on when the value of port is LOW. When this process is repeated, entering a serial 8-bit data becomes practicable. Line 22: we have examined that two clocks operate in 74HC595 earlier. A clock that is setting now is the clock of flip-flop. When this clock is inserted in for loop statement, the data can be entered in order according to the value of i. As mentioned in the function table, 74HC595 operates in high-edge. Thus, the clock starts to operate when the value of port changes from LOW to HIGH. sbi(portb,2); Setting a latch to 1 has the identical reasoning of setting a latch to 0 before. Since the final output appears when the output of flip-flop enters to the latch, 30 of 138

31 the clock starts to operate through for loop statement and the input value comes to output in parallel to operate 7-segment. 31 of 138

32 Example Program 2 #include "newbeetle.h" void main(void) { Initialize(); u08 i,j,data; char segment[16]={0x48,0xeb,0x8c,0x89,0x2b,0x19,0x18, 0x4b,0x08,0x09,0x0a,0x38,0x5c,0xa8,0x1c,0x1e}; } //-----fnd port IO setup for 7segment operation sbi(ddrb, 0); sbi(ddrb, 1); sbi(ddrb, 2); while(1) { for(j=0;j<16;j++){ // cbi(portb,2); data=segment[j]; // for(i=0;i<8;i++){ if((data<<i) & 0x80){ sbi(portb,0); }else{ cbi(portb,0); } // sbi(portb,1); cbi(portb,1); } // sbi(portb,2); msecdelay(5); } The above program displays the hexadecimal numbers from 0 to F by applying the previous example, which represented one number on 7-segment. The basic contents are omitted because they are identical to the previous program. A noticeable part is the location of setting latch. To display one data, the latch was set to 0 in the initial stage of program. However, the data has to be displayed in consecutive order now and the initial setting value of latch must be included in for loop statement. When the program is executed, the 7-segment displays the characters from 0 to F in consecutive order. 32 of 138

33 Figure shows the process of displaying a hexadecimal number from 0 to F using 7-segment Exercises 1 Figure Screenshots of the data output of 7-segment Make a program that displays only even numbers between 0 and F of 7- segment. HINT1. Increases by 2 when you execute the for loop that increases j variable Exercises 2 After connecting LED on slot #2, make a program that displays the same number on LED and 7-segment. HINT1. Slot #2 is connected with DDRD 0 ~ 3 / PORTD 0 ~ 3. HINT2 INT2. LED turns on when the LOW value is given to the port. 33 of 138

34 3.4. DC Motor What is DC Motor? DC motor is a tool that converts an electric energy into a kinetic energy (mechanical energy) by using an electromagnetic force, which is generated from the magnetic field around a current carrying conductor. Rotor and stator are made up of coil and permanent magnet, respectively. The DC motor contains a rapid acceleration, high starting torque, and linear rotation characteristics Rotating Principle of DC Motor When current flows in the conductor of DC motor around the magnetic field, it generates an electromagnetic force. DC motor uses this electromagnetic force and it follows the Fleming s left hand rule. Figure Structure of direct current (DC) motor In the left image of Figure 3.4.1, the force is acted on upward at the point a of armature when you apply the Fleming s left hand rule. Similarly, the force is acted on downward at the point b of armature, which makes the armature to rotate. Current does not flow when the armature is perpendicular as shown in the middle image, but the armature continues to rotate due to the inertia. When the armature makes a half-turn as shown in the right image, both point a and b of armature become the opposite to the left image. However, since the current flows to the opposite direction due to the commutator, the armature continues to rotate with the identical force. 34 of 138

35 H-Bridge Circuit DC motor rotates to a fixed direction because + and - are connected to each ends of motor terminal. In order to change the rotating direction of motor, the polarity of + and - that are connected to the motor terminals must be changed. In general cases, there is a weakness because motor must change its wires to change the direction. H-bridge circuit solves this weakness by allowing this switching operation electrically. Since the structure of circuit is similar to an alphbet, H, H- bridge circuit is given as its name. Figure Structure of H-bridge circuit H-bridge circuit has the basic structure composed of 4 transistors, where each transistor acts as a switch. As shown in Figure 3.4.2, when Q1 and Q4 are on, and the rest Q2 and Q3 are turned off, the current flows from the supply voltage to Q1 where the left terminal of motor is provided with + voltage, and the right terminal is connected to GND through Q4 terminal. If the motor rotates in clockwise direction here, the motor rotates in counterclockwise direction when Q1 and Q4 are turned off, and Q2 and Q3 are turned on. + voltage is provided to the right terminal through Q2. Note that GND is connected to the left terminal of motor through Q3. Since H-bridge circuit can change the polarity of supply voltage of the motor using an electrical control method, the adjustment of rotating direction of motor is practicable such as clockwise or counterclockwise rotation. Figure Circuit diagram of H-Bridge in BA6289F 35 of 138

36 Circuit Diagram of DC Motor In MA-VIN, DC motor is connected from PIN 14 to PIN 17 (Port B 4-7) of ATmega64 processor. It is controlled based on a reversible motor driver, BA6289F, by using a PWM (Pulse Width Modulation) method. Figure Block diagram of BA6289F Figure Pin arrangement of BA6289F Table Pin description of BA6289F BA6289F Table Input/output truth table of Since BA6289F makes four types of output by the combination of two input signals (FIN and RIN), it is practicable to control the rotating direction of motor. 36 of 138

37 Motor Control Figure Pin arrangement of ATmega64 processor in ER6 37 of 138

38 Table Motor control port of ATmega64 processor Figure Connection between motor driver, BA6289F, and ATmega64 processor MA-VIN controls the motor through Port B and Port E of ATmega64 processor. PB4 and PB5 of processor are used as MOTOR_R_R and MOTOR_R_L, respectively. PB4 and PB5 are connected to FIN and RIN of BA6289F, respectively, and determine OUT1, OUT2, and the operation of motor by comparing these two input values. Refer the input/output truth table of BA6289F in Table PE4 and PE5 of processor are ports for an external interrupt. In MA-VIN, these two terminals are used to set the reference voltage. Since the interrupt is not generated unless there is a special input, the reference voltage is set to 0 V. 38 of 138

39 Source Code of Program The following is a portion of motor control within the header file, newbeetle.h. 1 : void DcMotor_temp(u08 direction,u08 sel_motor, u08 pwm_value) 2 : { 3 : sbi(ddrb,4); 4 : sbi(ddrb,5); 5 : sbi(ddre,4); 6 : sbi(ddrb,6); 7 : sbi(ddrb,7); 8 : sbi(ddre,5); 9 :.( ) Line 1: the selection of left/right motor, rotating direction, and rotating speed are provided as a factor. direction is a factor that determines the rotating direction of motor. sel_motor is a factor that determines the selection of left/right motor, and pwm_value determines the rotating speed of motor. In MA-VIN, the rotating speed of motor can be adjusted from 0 to : if(sel_motor == 1) // right_motor 2 : { 3 : if(direction == 1){ // 4 : cbi(portb,4); 5 : sbi(portb,5); 6 : }else if(direction == 0){// 7 : cbi(portb,5); 8 : sbi(portb,4); 9 : } 10 : org_pwm[0] = pwm_value; 11 : if(org_pwm[0]){ 12 : org_pwm[0] = pwm_value; 13 : } else { 14 : cbi(portb,4); 15 : cbi(portb,5); 16 : } 17 : } 39 of 138

40 First, let s examine the process of controlling the right side motor. The right side motor is selected when sel_motor == 1 in the above function. When the motor is selected, the rotating direction of motor is determined as direction == 1 (rotating clockwise). When the value of port becomes HIGH, the motor starts to rotate where the rotating speed is the value of pwm_value, which is provided during function calling. The operation of left side motor and both motors are identical to the operation of right side motor. motor. Let s examine the following flow chart, which is a simple program to operate Figure Flow chart of DC motor control using header file 40 of 138

41 1 : void main(void) 2 : { 3 : Initialize(); 4 : while(1) 5 : { 6 : DC_Control(DEFAULT,MOTOR_BOTH,10,CW); 7 : } 8 : } 9 : void DC_Control(u08 pos,u08 sel_motor,u08 pwm_value,u08 direction) 10 : { 11 : DcMotor_temp(direction,sel_motor,pwm_value); 12 : } 41 of 138

42 When the above program is downloaded, MA-VIN rotates both wheels forward with the speed of 10. Since the position of motor, rotating motor, speed of motor, and rotating direction are set to Default, MOTOR_BOTH, 10, and CW in the main function, respectively, the motor operating function starts to operate according to the input values. The above program is the simplest method to rotate motor by calling the function within the header file, which is already made in MA-VIN. Let s examine the method to rotate motor by adjusting each port directly. In order to rotate motor directly, you should be familiar with the connection between port, data bit, and motor. As shown in the circuit diagram of motor previously, the motor is practicable to control through the control of 6 ports. Port Pin Motor Operation Function DDR 4 MOTOR_R_R Right motor RIN DDRB 4 PORT B 5 MOTOR_R_L Right motor FIN DDRB 5 PORT E 4 MOTOR_REF_R Right motor VREF DDRE 4 6 MOTOR_L_R Left motor FIN DDRB 6 PORT B 7 MOTOR_L_L Left motor RIN DDRB 7 PORT E 5 MOTOR_REF_L Left motor VREF DDRE 5 Table Port and register connected to motor First, the direct control method is not far different to the previous function calling method, which is to make the value DDR to HIGH and set it as an output, and enter HIGH value to the port register in order to rotate a motor. However, from now on the motor is controlled by entering the rotating direction and rotating speed directly. An input signal has to be adjusted for a motor to rotate. Motor rotates in clockwise direction when the FIN port becomes HIGH, whereas it rotates in counterclockwise direction when RIN port becomes HIGH. In order to stop the rotation of motor, the value of input port should be changed from HIGH to LOW. Let s examine about the rotation of motor through the next example. 42 of 138

43 DDR PORT // YES NO Figure Operating procedure of motor for controlling port directly Example Program 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); // output port 5 : u08 velocity=5; 6 : sbi(ddrb,4); 7 : sbi(ddrb,5); 8 : sbi(ddre,4); 9 : sbi(ddrb,6); 10 : sbi(ddrb,7); 11 : sbi(ddre,5); 12 : org_pwm[0]=velocity; 13 : cbi(portb, 4); 14 : sbi(portb, 5); 15 : } 43 of 138

44 Velocity is a variable that controls the speed of motor. The speed of motor can be varied from 0 to 17 through the setting of this value. For the operation of motor, output port gets initialized and the value of DDR in each port is made to HIGH. Velocity determines the speed of motor by deciding the variable in isr_pwm (PWM interrupt function) through org_pwm[0]. Refer to the header file about isr_pwm function. When the rotating speed of motor is determined, it is practicable to control motor by providing a HIGH/LOW value to the port. When the 4 th pin of PORT B is given HIGH and the 5 th pin of PORT B is given LOW, the right side motor rotates in clockwise direction and the wheel attached to the motor rotates in forward direction Exercises 1 Make a program that moves forward for 2 seconds and then moves backward for 2 seconds. HINT1. Refer to the below table and the circuit diagram of ER-6 motor. HINT2. Enter the rotating direction of forward and reverse by considering the rotating direction of motor. HINT3. Determine the rotating period of motor by considering the time function (delay) Exercises 2 After setting the values of driving speed between 0 and 15, make a program that moves with displaying its driving speed on the 7-segment. HINT1. Driving speed is determined by the input values of org_pwm[0] and org_pwm[1]. HINT2. After setting the driving speed as a variable, designate the array of data for segment. 44 of 138

45 3.5. LCD Module Operating Method of LCD Module LCD module is a tool that displays either text or graphic that we want, which is largely divided into a text LCD and a graphic LCD. LCD module can be attached to MA-VIN, which uses 8 texts in one line and displays an output of 8 x 2 texts. The connection and pin configuration of a text LCD module provided by MA-VIN can be verified as follows: Figure LCD module of ER6 Figure Pin configuration of slot for LCD DDR PORT LCD LCD LCD Figure Flow chart of operating LCD module 45 of 138

46 Table Pin description of LCD module In Table 3.5.1, PIN 1 ~ PIN 6 of LCD module are related to the operation of LED, and the adjustment of PIN 4 to PIN 6 influences the actual operation. In addition, from PIN 7 to PIN 14 are used to move the data. Each pins is connected to PG0 ~ PG2 (PIN 0 ~ PIN 2 of port G) and PA0 ~ PA7 (PIN 0 ~ PIN 7 of port A) of ATmega64, which is the processor of MA-VIN. Since PIN 1 ~ PIN 3 are operated as the driving part of LCD and they are related with the design of circuit, they are not affected by an additional configuration. When PIN 4 and PIN 5 becomes 1(HIGH), 0(LOW), 1(HIGH) 0(LOW), the data gets displayed on LCD. Remember this point when you give a command. The following table is related with the command of LCD. 46 of 138

47 Table Pin configuration method for the commands of LCD module Table is a table that collects the commands for the initialization steps of LCD. Each LCD possesses different characteristics according to the product and the instruction cone is different as well. Thus, the initialization steps must be done according to the product. The procedure of initialization steps are shown as follows: 47 of 138

48 Figure Initialization order of LCD module 1. Display Clear 2. Function set: DL = 1: 8bit interface operation N = 0: 1- line display mode F = 0: 5*7 dots character font 3. Display ON/OFF control: D = 0: display OFF C = 0: Cursor OFF B = 0: Blink OFF 4. Entry Mode Set I/D = 1: +1 (increment mode) SH = 0: No Display Shift operation To perform the initialization in order as shown above, remember that 6 th pin of module operates at down edge. In other words, it recognizes that the command is entered when the value of port is changed from 1 (HIGH) to 0 (LOW) for each command. 48 of 138

49 All commands were processed in the main function till now. However, the case of LCD module uses the method of calling a function because there are many repetitive processes between LCD module and a processor. 1 : void lcd_command(unsigned char cmd) 2 : { 3 : delay(5); 4 : outp(0x04, PORTG); 5 : delay(5); 6 : outp(cmd, PORTA); 7 : delay(5); 8 : outp(0x00, PORTG); 9 : delay(5); 10 : } The above function is a function to give commands. This function receives the commands that we assign as factors. First, port G is set to 0x04 = Port G of MA-VIN uses three pins: PIN 0, PIN 1, and PIN 2. Give a HIGH value to the PIN 2 of port G. Since PIN 2 of port G is connected to the PIN 6 of module, it makes Enable Signal to HIGH condition. When the command of cmd is given to port A, the command starts to operate after downloading the PIN 2 of port G. Let s initialize the LCD by using this function. By using the commands in Table 3.5.2, execute instruction commands according to the initialization procedure in Figure Display clear = lcd_command(0x01) : Function Set = lcd_command(0x38) : Display ON/OFF = lcd_command(0x08) : Entry Mode set = lcd_command(0x06) : Let s combine the rearranged initialization procedure into one function. 1 : void lcd_initialization(void) 2 : { 3 : delayms(30); 4 : lcd_command(0x01); // Display clear 5 : lcd_command(0x38); // Function Set 6 : delayms(5); 7 : lcd_command(0x08); // Display ON/OFF 8 : delayms(5); 9 : lcd_command(0x06); // Entry Mode set 10 : } 49 of 138

50 A required time for the initialization is different according to product. If you do not have to display data in an extremely short amount of time, provide an enough delay time. If the initialization process is finished, let s examine the method of displaying data now. 1 : void lcd_output(unsigned char data) 2 : { 3 : delay(5); 4 : outp(0x05, PORTG); 5 : delay(5); 6 : outp(data, PORTA); 7 : delay(5); 8 : outp(0x01, PORTG); 9 : delay(5); 10 : } To display data to LCD module, it requires several kinds of process. Let s examine lcd_output function. Line 4: setting the value of port G to 0x05 = indicates making RS (Register Selection) bit HIGH, making into Display Data condition, and preparing the command by setting Enable bit HIGH. Line 6: when the data is ready to be sent through port A, lower the value of port G from HIGH to LOW and proceed the process of executing a command. TIP: outp command can be exchanged for sbi or cbi commands. Usually, it is used when the general setting of bit of register is required, and it can be used easily when the port is controlled. In the above case, outp(0x05, PORTG); command operates the identical actions as follow: sbi(portg, 0); cbi(portg, 1); sbi(portg, 2); cbi(portg, 3); cbi(portg, 4); cbi(portg, 5); cbi(portg, 6); cbi(portg, 7);. In other words, it is the command that outputs the value of 0x05 = to port G sequentially. This command can easily set the general operation of port and know the flow of data. However, it can modify the values of other ports if the setting is wrong. When you determine the direction of data bit by using this command, that is to determine both input and output, you should be careful. As an example of operating LED and switch, let s assume that both input and output are generated at DDRB. When you use outp(0x8f, DDRD) command, DDRD 4 ~ DDRD 6 are used as an input and DDRD 0 ~ DDRD3 are used as an output. DDRD 7 is run as an output. Since ER-6 provides a switch having 3 inputs, you do not have to set DDRD7 as an input. Since you can control the whole values of DDRD, you must have through knowledge of the role of each port when outp command is used to avoid problems. For the case of input, inp command can be used, which can be confirmed in Chapter 4 Input Modules. 50 of 138

51 The above progression process of using lcd_output function is the process of sending one data. Since we have to send a connected text, let s consider another different function. 1 : void lcd_str_output(unsigned char *msg) 2 : { 3 : while(*msg){ 4 : lcd_output(*(msg++)); 5 : } 6 : } The above function saves a data by using pointer and displays the data sequentially. This function saves the entered text into a temporary register called msg and displays the text by taking out the data in the address of msg consecutively. Let s assume that we are trying to display a text, ER6_TEST. Line 1: this function saves a character E, R, 6, _, T, E, S, T sequentially into the memory address of char type pointer variable msg until the lcd_str_output function is called from the main function. Line 3: in while loop, until the stored value in the memory becomes NULL. Line 4: increases the address of memory in order and outputs the value of memory address that the pointer variable msg indicates. When the above process is completed, we can test the display of text in LCD module. However, there exists a problem when the above process is preceded. There are two lines for LCD module connected to MA-VIN, where one line can only display 8 texts. In other words, if the number of text is higher than 8 in Line 1, texts entered after 8 texts are not displayed. The reason is that a specific address is provided to the line of module and if this is not set separately, the process only executes the output from the address of 00H. Thus, we have to set the address of LCD module to display the output properly. Table Address of LCD module Table indicates the address of LCD module and Table shows the method for setting the address. 51 of 138

52 Table Address configuration method of LCD module (LCD command code) Let s find out about the DB7 of LCD command, which has the value of 1. As you can see in Table 3.5.2, it is written as Set DDRAM Address. This is a command that sets the address of memory through the bit of AC6 ~ AC0. If you examined particularly, DB7 must have the value of 1 when the address is set because it is a command that sets the address of LCD. The starting address of Line 1 of LCD DDRAM is 00H and the starting address of Line2 is 40H. Since DB7 always has the value of 1, the value of 8-bit always has the value of 1xxx xxxx when the address is set. 00H is the value of and 40H is the value of The starting value of address is either 1xxx xxxx or 1xxx xxxx Thus, the starting address of Line 1 becomes 0x80 = and Line 2 becomes 0xc0 = This can be confirmed in the example function, which sets the address. The memory address can be set as the value of DB7 ~ DB0 by referring the above two tables. Keep in mind this fact and let s modify the lcd_str_output function, which was used before, and insert a function related to the line. 1 : void lcd_str_output(unsigned char line, unsigned char *msg) 2 : { 3 : lcd_line(line); 4 : while(*msg){ 5 : lcd_output(*(msg++)); 6 : delayms(5); 7 : } 8 : } As shown in the above function, insert a factor to receive the value of line and insert a function related to the line. The function related to the line is formed as follows. It represents the method for setting the address of memory within the function. 1 : void lcd_line(unsigned char line) 2 : { 3 : char address; 4 : if(line == 1) 5 : { 6 : address = 0x80; 7 : }else if(line == 2){ 8 : address = 0xc0; 9 : } 10 : lcd_command(address); 11 : } 52 of 138

53 This is a function that sets the line of LCD. When it is Line 1, the value of 0x80 = is stored in the variable called, address, and send this through lcd_command function. This represents that the address of DDRAM starts from 00H' and LCD starts to display the output from the left side of Line 1. If it is Line 2, send the value of 0xC0 = to the LCD and this represents starting from 40H according to the Table Thus, LCD starts to display the output from the left side of Line 2. Let s make a main function based on the explained functions until now Example Program 53 of 138

54 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); 5 : outp(0xff, DDRA), outp(0xff, DDRG); 6 : outp(0x00, PORTA), outp(0x00, PORTG); 7 : lcd_initialization(); 8 : lcd_command(0x0c); 9 : lcd_str_output(1, "ER-6"); 10 : delayms(5); 11 : lcd_str_output(2, "LCD test"); 12 : } 13 : void lcd_command(unsigned char cmd) 14 : { 15 : delay(50); 16 : outp(0x04, PORTG); 17 : delay(50); 18 : outp(cmd, PORTA); 19 : delay(50); 20 : outp(0x00, PORTG); 21 : delay(50); 22 : } 23 : void lcd_initialization(void) 24 : { 25 : delayms(30); 26 : lcd_command(0x01); 27 : lcd_command(0x38); 28 : delayms(5); 29 : lcd_command(0x08); 30 : delayms(5); 31 : lcd_command(0x06); 32 : } (Continue ) 54 of 138

55 1 : void lcd_output(unsigned char data) 2 : { 3 : delay(5); 4 : outp(0x05, PORTG); 5 : delay(5); 6 : outp(data, PORTA); 7 : delay(5); 8 : outp(0x01, PORTG); 9 : delay(5); 10 : } 11 : void lcd_str_output(unsigned char line, unsigned char *msg) 12 : { 13 : lcd_line(line); 14 : while(*msg){ 15 : lcd_output(*(msg++)); 16 : delayms(5); 17 : } 18 : } 19 : void lcd_line(unsigned char line) 20 : { 21 : char address; 22 : if(line == 1) 23 : { 24 : address = 0x80; 25 : }else if(line == 2) 26 : { 27 : address = 0xc0; 28 : } 29 : lcd_command(address); 30 : } The result of above program displays outputs MA-VIN in line #1 and LCD test in line # Exercises Make a program that shifts a text to the left on the LCD module. HINT1. Shift a text by adjusting the address of LCD module. HINT2. If the address is fixed, shift an output by adjusting the value of address when the address of 55 of 138

56 3.6. Speaker Operating Method of Speaker Module The operation of speaker is almost same as buzzer. Thus, identical contents of buzzer are omitted and if you have questions, review the section 3.2 Buzzer part once again. Speaker module vibrates a diaphragm, which generates a sound, when current flows into the circuit. In general, the difference between speaker and buzzer is that buzzer can achieve its functionality by generating only a monotone (a single sound), whereas speaker must distinguish between high and low sound. In order to do this, it uses a frequency. According to octave and scale, the frequency is classified and the speaker can be operated by putting in this frequency value. The following figures show the speaker module of MA-VIN, the circuit diagram of speaker module, and its specifications. Figure Speaker module Figure Circuit diagram of speaker module Table Volume (db) Minimum 85 Capacity (pf) 7000± 30% Input Voltage (V pp ) Maximum 30 Operating Temperature -20~+70 () speaker module Specification of 56 of 138

57 Figure Flow chart of speaker operation scale. Please refer Table for the standard frequency according to octave and Table Standard frequency according to octave and scale As shown in Table 3.6.2, when the speaker module and connected port becomes HIGH after setting the frequency according to octave and scale, a sound is generated through speaker. In order to set a frequency value according to each octave and scale, a database that generates a proper frequency is required. Please refer to the newbeetle.h file for this database. 57 of 138

58 1 : const prog_char T1SOL [2] = {0,30}; 2 : const prog_char T1SOLS [2] = {1,30}; 3 : const prog_char T1RA [2] = {2,30}; 4 : const prog_char T1RAS [2] = {3,30}; 5 : const prog_char T1SI [2] = {4,30}; 6 : const prog_char T2DO [2] = {5,30}; 7 : const prog_char T2DOS [2] = {6,30}; 8 : const prog_char T2RE [2] = {7,30}; 9 : const prog_char T2RES [2] = {8,30}; 10 : const prog_char T2MI [2] = {9,30}; 11 : const prog_char T2PA [2] = {10,30}; 12 : const prog_char T2PAS [2] = {11,30}; 13 : const prog_char T2SOL [2] = {12,30}; 14 : const prog_char T2SOLS [2] = {13,30}; 15 : const prog_char T2RA [2] = {14,30}; 16 : const prog_char T2RAS [2] = {15,30}; 17 : const prog_char T2SI [2] = {16,30}; 18 : const prog_char T3DO [2] = {17,30}; 19 : const prog_char T3DOS [2] = {18,30}; 20 : const prog_char T3RE [2] = {19,30}; 21 : const prog_char T3RES [2] = {20,30}; 22 : const prog_char T3MI [2] = {21,30}; 23 : const prog_char T3PA [2] = {22,30}; 24 : const prog_char T3PAS [2] = {23,30}; 25 : const prog_char T3SOL [2] = {24,30}; 26 : const prog_char T3SOLS [2] = {25,30}; 27 : const prog_char T3RA [2] = {26,30}; 28 : const prog_char T3RAS [2] = {27,30}; 29 : const prog_char T3SI [2] = {28,30}; 30 : const prog_char T4DO [2] = {29,30}; The header file constructs a database related to musical tones as stated above. In addition, since other functions are implemented in order to generate sound, a melody can be easily made by calling these functions. Make sure to refer both SetSpeaker() and MelFunc() functions. Let s find out the applications of speaker through the following examples. 58 of 138

59 Example Program 1 1 : void main() 2 : { 3 : Initialize(); 4 : while(1) 5 : { 6 : SetSpeaker(1, T1SOL, RHYTHM_4_2); 7 : msecdelay(5); 8 : SetSpeaker(1, T1RA, RHYTHM_4_2); 9 : msecdelay(5); 10 : SetSpeaker(1, T1SI, RHYTHM_4_2); 11 : msecdelay(5); 12 : SetSpeaker(1, T2MI, RHYTHM_4_2); 13 : msecdelay(5); 14 : } 15 : } The following program generates a sound of sol (G), la (A), and si (B) in same octave and a sound of mi (E) in one octave higher. SetSpeaker function in header file holds the receiving value of each scale and note, and uses as the output by calling the value of MelodyRegister in MelFunction function. Since this process requires the understanding of timer/counter, refer to the section 4.3 Infrared Ray Sensor and the datasheet of ATmega64 for your better understanding. It is preferred to have an exercise using these implemented functions because the process of setting frequency and producing sound to speaker is complex in reality. 59 of 138

60 Example Program 2 1 : #include "newbeetle.h" 2 : void schoolbell() 3 : { 4 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 5 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 6 : SetSpeaker(1, T2RA, RHYTHM_8_2); 7 : SetSpeaker(1, T2RA, RHYTHM_8_2); 8 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 9 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 10 : SetSpeaker(1, T2MI, RHYTHM_4_2); 11 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 12 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 13 : SetSpeaker(1, T2MI, RHYTHM_8_2); 14 : SetSpeaker(1, T2MI, RHYTHM_8_2); 15 : SetSpeaker(1, T2RE, RHYTHM_2_2); 16 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 17 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 18 : SetSpeaker(1, T2RA, RHYTHM_8_2); 19 : SetSpeaker(1, T2RA, RHYTHM_8_2); 20 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 21 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 22 : SetSpeaker(1, T2MI, RHYTHM_4_2); 23 : SetSpeaker(1, T2SOL, RHYTHM_8_2); 24 : SetSpeaker(1, T2MI, RHYTHM_8_2); 25 : SetSpeaker(1, T2RE, RHYTHM_8_2); 26 : SetSpeaker(1, T2MI, RHYTHM_8_2); 27 : SetSpeaker(1, T2DO, RHYTHM_2_2); 28 : msecdelay(10); 29 : } 30 : void main() 31 : { 32 : Initialize(); 33 : while(1) 34 : { 35 : schoolbell(); 36 : } 37 : } The following example is the implementation of School Bell. As stated above, a desired melody can be made by entering individual pitch (sound). 60 of 138

61 Exercises By using push switches, make a program that generates a simple melody according to the switch 1, 2, and 3. HINT1. Refer to the information related to push switch in the next chapter. HINT2. Generate a different melody for the case of switch 1, 2, and 3 by using if command. HINT3. Keep in mind that there is no sound when a switch is not pushed. 61 of 138

62 4. Input Module 4.1. Switch Operation of Switch Module Let s examine about switch in this subchapter. Switch module provided by MA-VIN is composed of the total of 3 push switches, where the circuit diagram of push switch is organized as follows: Figure Push switch module Figure Circuit diagram of push switch 3 switches are connected to the ground (GND) and the voltage drops to 0V when the switch is pressed. Since the operation of switch cannot be confirmed directly, it is explained by providing an example to turn on LED using switch. 62 of 138

63 Figure Flow chart of operating push switch and LCD Keeping the order of flow chart in mind, let s examine the following example. This example turns LED on according to the switch number. It assumes that LED module and switch module are connected to slot #1 and slot #2, respectively. 63 of 138

64 Example Program 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); 5 : sbi(ddrb, 0); sbi(ddrb, 1); sbi(ddrb, 2); sbi(ddrb, 3); 6 : sbi(portb, 0); sbi(portb, 1); sbi(portb, 2); sbi(portb, 3); 7 : cbi(ddrd, 0); cbi(ddrd, 1); cbi(ddrd, 2); 8 : sbi(portd, 0); sbi(portd, 1); sbi(portd, 2); 9 : outp(0x00, SFIOR); 10 : while(1) 11 : { 12 : if( (0x01 & inp(pind)) == 0 ) 13 : { 14 : sbi(portb, 0), sbi(portb, 1), sbi(portb, 2); 15 : cbi(portb, 0); 16 : } else if( (0x02 & inp(pind)) == 0 ) 17 : { 18 : sbi(portb, 0), sbi(portb, 1), sbi(portb, 2); 19 : cbi(portb, 1); 20 : }else if( (0x04 & inp(pind)) == 0 ) 21 : { 22 : sbi(portb, 0), sbi(portb, 1), sbi(portb, 2); 23 : cbi(portb, 2); 24 : } 25 : } 26 : } Port configurations of both input and output are important here. Input/output of ATmega64 is defined as follows: Table Port pin configurations 64 of 138

65 Table represents that input ports must set the value of DDxn to 0 (LOW: input). Since the switch is connected to the ground, basically the port should have the value of 1 (HIGH). The reason is that the value drops from HIGH to LOW when the switch is closed. To confirm the switch status, pull-up is used. Pull-up is the operation for processor to check the status of port when the switch is opened. Generally, the port holds the value of 1 (HIGH). When the switch is closed and the voltage drops to 0 (LOW), the processor concludes that the switch is pressed. Let s examine the above example from line #5. 5 : sbi(ddrb, 0); sbi(ddrb, 1); sbi(ddrb, 2); sbi(ddrb, 3); 6 : sbi(portb, 0); sbi(portb, 1); sbi(portb, 2); sbi(portb, 3); 7 : cbi(ddrd, 0); cbi(ddrd, 1); cbi(ddrd, 2); 8 : sbi(portd, 0); sbi(portd, 1); sbi(portd, 2); 9 : outp(0x00, SFIOR); This part sets the operation of port. Since it is assumed that LED module is connected to slot #1, port B must be set up as an output. Line 5: since DDRB is a register connected to the port to check the result of LED, it must be set up as an output. Thus, DDRB uses sbi command to obtain a HIGH value of 1. Line 6: after setting the value of DDRB as an output, now the value of port register is set. As mentioned in section 3.1 LED, emitting light occurs to the LED module when its voltage is 0 due to the drop of electric voltage. Thus, make the initial state of LED to OFF by setting the value of PORTB to 1 (HIGH). Line 7: since it is assumed that the switch module is connected to slot #2, the data direction of DDRD must be set up as an input. In order to make the value of DDRD to LOW, the values of DDRD 0 to DDRD2 are set to 0 by using cbi command. Keep in mind that the switch module has 3 buttons. Line 8: execute the operation of input by setting the value of PORTB to 1 (HIGH). If the switch is pressed, the drop of electric voltage occurs because the current flows between the switch and its connected ground. Line 9: then set an internal pull-up. ATmega64 has a special register called SFIOR (Special Function IO Register), where the 2-bit of this register controls the pull-up function. Pull-up is one of the important concepts in digital circuit, which is operated with the value of either 0 or 1. If the value that is a little higher than 0 (LOW) or lower than 1 (HIGH) comes into the device, it could be confused with what value has to be taken and cause a problem. In order to avoid this problem, a resistor is connected to the input side, which is called a pull-up register. ATmega64 processor can set the bit of this pull-up register to decide whether to use. 65 of 138

66 Figure SFIOR of ATmega64 By setting the value of SFIOR to 0x00, Pull-Up Disable (PUD) becomes inactive whereas an internal pull-up becomes active (use). If an external pull-up resistor is connected separately from the processor, make this bit HIGH and leave pull-up as disable state. Since MA-VIN uses internal pull-up instead of external pullup, the internal pull-up can be used when a low value is provided to Disable and make it Enable state. Let s examine the structure in while loop now. 10 : while(1) 11 : { 12 : if( (0x01 & inp(pind)) == 0 ) 13 : { 14 : sbi(portb, 0), sbi(portb, 1), sbi(portb, 2); 15 : cbi(portb, 0); 16 : }else if( (0x02 & inp(pind)) == 0 ) 17 : { 18 : sbi(portb, 0), sbi(portb, 1), sbi(portb, 2); 19 : cbi(portb, 1); 20 : }else if( (0x04 & inp(pind)) == 0 ) 21 : { 22 : sbi(portb, 0), sbi(portb, 1), sbi(portb, 2); 23 : cbi(portb, 2); 24 : } 25 : } The core of this part is to decide which switch is pressed and provide an input. Let s assume that pin #1 is given as an input. In the circuit diagram of switch (Figure 4.1.2), switch #1 is connected to the pin #1 of slot and pin #1 of slot #1 is connected to the pin 0 of port D of processor. PD 0 to PD 2 can receive an input due to cbi(ddrd, n) command in line 7 and sbi(portd,n) command in line 8. In addition, HIGH value is provided from PD 0 to PD 2 through the supply voltage of +5V, which is provided to slot #1. If switch #1 is pressed, PD 0 and GND are connected, and the voltage is dropped to 0 V (LOW). PIND of slot #2 = PD(0 : 3) = xxxx x111 When switch #1 is pressed = xxxx x110 0x01 & = of 138

67 Thus, if statement (line 12) starts to operate. The rest of if statements in line 16 and line 20 can be operated in a similar manner. Keeping in mind that LED must be changed according to each switch. Make sure to turn off everything except the LED that maches the switch. Thus, make all LEDs to OFF state before the desired LED is turned on similar to line 15, line 19, and line Exercises After connecting 7-segment in slot #1 and switch in slot #2, make a counter that repeatedly displays the number from 0 to 9 on 7-segment when the switch is pressed. HINT1. Assume the first switch of slot is pressed. HINT2. Making a counter that increases one when 0x01 & inp(pind) == 0 by creating one variable. Make sure to call an array of segment data in order. HINT3. When the counter that calls an array of segment data increases to 9, initialize the counter by a reset. 67 of 138

68 4.2. Touch Switch Operation of Touch Switch Touch switch is a tool to perform a switch role where a human body acts as an instantaneous conductor by applying that current can flow through the human body. Touch switch is commonly used to turn on/off a light and general electronic device. MA-VIN provides this touch switch as a module and various exercises are possible through the touch switch. The following figures show the touch switch module and its circuit diagram used in MA-VIN. Figure Touch switch module Figure Circuit diagram of touch switch The important point in this circuit diagram is an ES01 chipset, which allows performing a switch role. This chipset is a 1CH-capacitance comparator and detects the difference of electric charge between two inputs: IN+ and IN-. ES1 of MA-VIN returns an output of 1 (HIGH) if there is an electric charge difference between IN+ and IN-. All of you may know the fact that the current flows in a human body. If a human hand touches a touch pad (J13) as shown in Figure 4.2.2, an electric charge in C53 goes out through the hand. At this point, an electric charge difference between IN+ and IN- is occurred and ES01 chip informs this fact by generating a HIGH value to the output port. When this OUT and MA-VIN port are connected, the operation of touch switch is achieved. Keeping this fact in mind, let s examine the following program example. The example assumes LED and touch switch are attached in slot #1 and slot #2, respectively. When the touch switch is pressed, LED #1 is turned on whereas LED #2 is turned on when there is no contact. 68 of 138

69 Example Program Figure Flow chart of touch switch operation 1 : #include newbeetle.h 2 : void main(void) 3 : { 4 : Initialize(); 5 : outp(0xff, DDRB); 6 : outp(0xff, PORTB); 7 : cbi(ddrd, 0); cbi(ddrd, 0); 8 : sbi(ddrd, 3); sbi(portd,3); 9 : outp(0x00, SFIOR); 10 : while(1) 11 : { 12 : if( (0x01 & inp(pind) ) == 0x01 ) 13 : { 14 : cbi(portd, 3); 15 : cbi(portb, 0); 16 : } else { 17 : sbi(portd,3); 18 : cbi(portb, 1); 19 : } 20 : outp(0xff, PORTB); 21 : } 22 : } Line 4: it precedes the initializing process in order to use MA-VIN. 69 of 138

70 Line 5: it assumes LED is attached in the slot #1 and sets DDRB as 1 (HIGH) because LED is an output module. Line 6: the value of port is set HIGH because the LED module uses the change of voltage value from HIGH to LOW when it turns on with +5V supply. Line 7: touch switch is attached in the slot #2. As shown in the circuit diagram of Figure 4.2.2, pin 0 of port D and pin 3 of port D are used as input and output, respectively. Since the attached LED in pin 3 of port D indicates the operating status of touch switch, decide whether you want to use. Line 12: since the processor receives an input of 1 (HIGH) when it is touched, PIND holds the value of When this input value and go through AND operation, the result becomes and executes the first line of if statement. If touch switch does not work, if statement is not executed because it does not receive any values from ES01. Line 14: when it is touched, the attached LED on the module and the first LED of LED module in slot #1 are turned on. Line 17: when it is not touched, the attached LED on the module and the second LED of LED module in slot #2 are turned off. Line 20: lastly, all LEDs are turned off including LEDs that were already turned on and wait for the next command. When this structure is repeated, we can obtain the results that we want. By integrating a touch switch and a 7-segment, let s examine the program that increases the counter by 1 when it is touched. In the previous chapter, we learned how to operate 7-segment. Let s complete the program by calling these functions. 70 of 138

71 Example Program 1 : #include "newbeetle.h" 2 : void segment(u08 sw) 3 : { 4 : u08 i, data; 5 : char seg[16]={0x48,0xeb,0x8c,0x89,0x2b,0x19,0x18,0x4b, 6 : 0x08,0x09,0x0a,0x38,0x5c,0xa8,0x1c,0x1e}; 7 : sbi(ddrb, 0), sbi(ddrb, 1), sbi(ddrb, 2); 8 : cbi(portb, 2); 9 : data=seg[sw]; 10 : for(i=0; i<8; i++) 11 : { 12 : if( (data<<i) & 0x80 ){ 13 : sbi(portb, 0); 14 : } else{ 15 : cbi(portb, 0); 16 : } 17 : sbi(portb, 1); 18 : cbi(portb, 1); 19 : } 20 : sbi(portb,2); 21 : } 22 : void main(void) 23 : { 24 : Initialize(); 25 : outp(0xff, DDRB); 26 : outp(0xff, PORTB); 27 : cbi(ddrd, 0), cbi(ddrd, 0); 28 : sbi(ddrd, 3), sbi(portd, 3); 29 : outp(0x00, SFIOR); 30 : u08 cnt; 31 : segment(0); 32 : while(1) 33 : { 34 : if(cnt == 16){ 35 : cnt=1; 36 : } else { 37 : if( (0x01 & inp(pind) ) == 0x01) 38 : { 39 : cbi(portd, 3); 40 : segment(cnt); msecdelay(2); 41 : cnt++; 42 : } else{ 43 : sbi(portd, 3); 44 : } 45 : } 46 : } 47 : } 71 of 138

72 Since the above program is the integration of used or made programs beforehand, it can be used without any difficulties. The most important part in the program is when to start setting a counter. Since the counter in the program will increase when it is touched, it should be included in the following if statements where the touch operation is executed. 34 : if(cnt == 16){ 35 : cnt=1; 36 : } else{ 37 : if( (0x01 & inp(pind) ) == 0x01) 38 : { 39 : cbi(portd, 3); 40 : segment(cnt); 41 : msecdelay(2); 42 : cnt++; 43 : } else{ 44 : sbi(portd, 3); 45 : } 46 : Line 34: initialize a counter. Since the FND displays the value from 0 to F, the counter should be able to display F value then the value of 0 again. If the value of current counter is 16, it should display 0 by initializing the counter to 1. Line 37: when the touch operation is occurred. Line 39: turn on the LED attached on the module. Line 40: turn off the value of FND according to the value of counter by executing segment function. Line 42: increase the value of counter by 1. Line 44: when there is no contact, turn off the LED attached on the module. 72 of 138

73 Exercises Once the LED module is attached in slot #1 and the touch switch module is attached in slot #2, make a program that turns on from LED #1 to LED #4 and then turn off from LED #4 to LED #1 in order when it is touched. When it is not touched, all LEDs must be turned off. HINT1. Include function that turns on LED in order and turns off LED in reverse order within the if statement where the touch operation is detected. HINT2. Include function that turns off all LEDs within the if statement where the touch operation is not 73 of 138

74 4.3. Infrared sensor Operation of Infrared Ray Sensor Infrared ray sensor is a tool that detects the physical or chemical amount of temperature, pressure, radiation strength, etc, by using infrared ray, and converts into the electrical amount for signal processing. There is an instrument, which senses the interception and detects the circumference of infrared rays by emitting infrared ray. It is used for the preventions of crime or fire. There is a passive type of infrared ray sensor, which only reads the amount of infrared ray differences from the external world. By copying infrared ray alone, light is isolated in this type and the passive type does not contain both emitter and receiver that are needed to detect the change. There are total 12 infrared ray sensors in MA-VIN, where 6 of them are active type and the rest 6 of them are passive type. In the active type sensor, infrared ray is copied and its rays are reflected after bumped into an obstacle. Then the passive type senses this amount. By using this infrared ray sensor, it can be used in the various applications including obstacle avoidance by driving motors when an obstacle is detected. Figure Infrared ray sensor module module Figure Connections of infrared sensor IR Sensor Module Slot Processor PIN 1 Not connected Not connected PIN 2 Vcc Vcc PIN 3 SENS_TRIG PC6 PIN 4 SENS_BOTTOM_LEFT PC5 PIN 5 SENS_BOTTOM_CENTER PC4 PIN 6 SENS_BOTTOM_RIGHT PC3 PIN 7 SENS_FRONT_LEFT PC2 PIN 8 SENS_FRONT_CENTER PC1 PIN 9 SENS_FRONT_RIGHT PC0 PIN 10 GND GND Table Connections between infrared sensor module and processor 74 of 138

75 Example Program 1 Let s make a program corresponds to the following flow chart. Figure is the flow chart of program that turns LED on according to the location of detected obstacles. DDR PORT No Yes # 1 LED # 2 LED # 3 LED Yes Figure Flow chart of operating infrared ray sensor module No 75 of 138

76 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); 5 : outp(0xff, DDRB), outp(0xff, PORTB); 6 : outp(0x00, DDRC), sbi(ddrc, 6); 7 : outp(0xff, PORTC); 8 : while(1) 9 : { 10 : SensorDir = 1; 11 : ControlPortc = 1; 12 : PhotoSensorUpdate(); 13 : if(forwardphotosensor == 0x01) 14 : { 15 : outp(0x0e, PORTB); 16 : }else if(forwardphotosensor == 0x02){ 17 : outp(0x0d, PORTB); 18 : }else if(forwardphotosensor == 0x04){ 19 : outp(0x0b, PORTB); 20 : }else if(forwardphotosensor == 0x00){ 21 : outp(0x0f, PORTB); 22 : } 23 : delayms(10); 24 : } 25 : } The above example is a program that turns on each of the fixed LED when an obstacle is detected by the forward infrared ray sensors. In order to operate this, let s recall Table 4.3.1, which was presented earlier. MA-VIN operates infrared ray sensors through the pin 0 to pin 6 of port C of ATmega64. Each connection is shown as follows: MA-VIN Pin # of Module ATmega64 Forward-right sensor 9 0 of Port C Forward-middle 8 1 of Port C sensor Forward-left sensor 7 2 of Port C Bottom-right sensor 6 3 of Port C Bottom-middle 5 4 of Port C sensor Bottom-left sensor 4 5 of Port C Sensor trigger 3 6 of Port C Table Connections between ER6, module, and processor Each port is used as either input or output. From PC 0 to PC 5 are used to receive 76 of 138

77 an input from sensors, where PC 6 is used as an output for trigger. Let s examine each task. 5 : outp(0xff, DDRB), outp(0xff, PORTB); 6 : outp(0x00, DDRC), sbi(ddrc, 6); 7 : outp(0x00, PORTC); Similar to the below statements, you can use this command by setting the values of DDR register and port register separately. Since (PORTC, 6) is used as an output port for trigger, it is set separately. sbi(ddrb, 0), sbi(ddrb, 1), sbi(ddrb, 2), sbi(ddrb, 3); sbi(ddrb, 4), sbi(ddrb, 5), sbi(ddrb, 6), sbi(ddrb, 3); sbi(portb, 0), sbi(portb, 1), sbi(portb, 2), sbi(portb, 3); sbi(portb, 4), sbi(portb, 5), sbi(portb, 6), sbi(portb, 7); cbi(ddrc, 0), cbi(ddrc, 1), cbi(ddrc, 2), cbi(ddrc, 3); cbi(ddrc, 4), cbi(ddrc, 5), sbi(portc, 6);, cbi(ddrc, 7); cbi(portc, 0), sbi(portc, 1), cbi(portc, 2), cbi(portc, 3); cbi(portc, 4), sbi(portc, 5), cbi(portc, 6), cbi(portc, 7); Now let s examine the while(1) statement. Line 9: SensorDir decides which sensor to be used. It selects 0 when the bottom sensor is used, whereas it selects 1 when the forward sensor is used. Refer to the header file about the value of 0 and 1 that selects a sensor. Line 10: ControlPortc informs the use of photo-sensor, which has an initial value of 0. Line 11: let s examine PhotoSensorUpdate() function. This function is shown as follows: 77 of 138

78 1 : void PhotoSensorUpdate() 2 : { 3 : static u08 timingcnt; 4 : timingcnt++; 5 : if(timingcnt == 16){ 6 : timingcnt = 0; 7 : }else if(timingcnt == 14){ 8 : sbi(portc, 6); 9 : }else if(timingcnt == 15){ 10 : if(sensordir == 1){ 11 : ForwardPhotoSensor = inp(pinc)& 0x07; 12 : }else{ 13 : DownwardPhotoSensor =inp(pinc)&0x38; 14 : } 15 : cbi(portc, 6); 16 : } 17 : } This function controls the emitter/receiver of infrared ray sensor, which is included in the header file. You can adjust the necessary time for both emitter and receiver through a counter. Time adjustment can be controlled through a clock and timer. Let s examine about the system clock in order to understand this process. MA- VIN generates an 8 MHz clock through an external crystal. Figure is the circuit diagram of external crystal oscillator. Figure External crystal oscillator MA-VIN uses a crystal to generate an 8 MHz clock and you should refer the following two tables in order to combine with ATmega64 processor. If ATmega64 uses the frequency range of crystal oscillator between 3.0 and 8.0 MHz, a ceramic capacitor must have the capacity of 12 to 22 pf. In addition, you can calculate the time that completes the initialization process of system through the setting of fuse bit. Since MA-VIN uses the crystal of 8 MHz, CKOPT = 1 and CKSEL3 1 = 111, and SUT = 11 because the clock is generated by using a crystal oscillator. In other words, it requires 16 CLK time + 65 ms amount of time to provide the power supply and stabilize the system. 78 of 138

79 Table Operation mode of crystal oscillator Table Starting time according to the selection of crystal oscillator You should understand the method for adjusting time by calculating the value of clock after understands the generation of clock. Since the external clock is 8 MHz, 1 clock provides the time of 1/8MHz = us us is a very short amount of time, which could be inefficient to use this clock directly as a timer or a counter. Prescaler is used for this. Prescaler is a method to bundle clocks in fixed unit and calculate this into a one new unit. in other words, for an 8 MHz frequency, 8000 clocks are provided in 1 ms. If we assume that 16 clocks counts one counter, it becomes us * 16 = 2 us and requires 2 us to increase one counter. Since 1 ms / 2 us = 500, you should count 500 counters to calculate 1 ms. Let s examine the method for setting this prescaler now. 79 of 138

80 Prescaler uses the concept of timer/counter. Thus, the increasing value of interrupt and the comparison of output values can be realized in this process. TCNT is a register that indicates the timer/counter and OCR is a register that compares the output value. For the detailed explanations related to value comparison and operation procedure, refer to the datasheet. First of all, TCCR must be set in order to set both TCNT and OCR. TCCR is a timer/counter control register, which determines the output value through the setting of this register and uses as the prescaler of clock. The value of TCCR0 is set to 0x01 in MA-VIN. This expresses the value of , and the meaning of this value is shown as follows: Figure Timer/counter control register Table Waveform generation mode Timer/counter operates in the normal mode in MA-VIN and its maximum value is 0xff = 256. Since COM01:0 of TCCR is 00, its operation is shown on the following table. Table displays the compare match output, where there are two operations for compare output mode. One is to perform a role of waveform generator, and the other is to operate a role of general output. When all of COM01:0 are 0, it performs the role of general output port. Table COM setting Let s examine the bit of CS02:0, which is the essential bit that determines the prescaler. Refer to Table The example that sets 16 clocks into one prescaler is described before. Let s set 32 clocks into a prescaler now. As you can see from the value of TCRR, if you set 32 clocks into a prescaler, one clock takes us and the time of 32 clocks becomes us * 32 = 4 us. In other words, a counter increases by 1 at every 4 us. Within 1 ms, the counter is increased by of 138

81 Table Selection of clock for prescaler Since we have examined about prescaler, a timer/counter is described now. We have found out the time calculation method of ATmega64 processor using clock and prescaler. TCNT register is used when we want to calculate the necessary time. The initial value of TCNT0 is set to 0x00 in MA-VIN and TCNT0 is an 8-bit counter. Thus, it is possible to count from 0 to 255. Figure Bit setting for TCNT In the initialization process of MA-VIN, TCNT and TCCR0 are set to 0x00 and 0x01, respectively. In other words, OC0 executes the operation of general output port and the prescaler is not used, which has the value of 1. A counter starts from 0 and counts to 255. There is an OCR0 register, which has the value of 8-bit. Its role is to turn on an interrupt when the timer is equal to OCR0. In other words, when TCNT = 0x00, TCCR0 = 0x01, and OCR0 = 0x11, OC0 operates as an output port, starts a counter from , and generates an interrupt at In order to use an interrupt for timer/counter, the bit 0 of TIMSK must be made HIGH. If the bit 0 of TIMSK and the bit 0 of TIFR are made HIGH, you can generate an interrupt when there is an overflow to the timer/counter, where its value is set in advance. Figure Bit setting for TIMSK and TIFR 81 of 138

82 With this, we have looked into a clock. Let s examine about a time cycle, which is used to detect a signal for infrared ray sensor. 1 : void PhotoSensorUpdate() 2 : { 3 : static u08 timingcnt; 4 : timingcnt++; 5 : if(timingcnt == 16){ 6 : timingcnt = 0; 7 : }else if(timingcnt == 14){ 8 : sbi(portc, 6); 9 : }else if(timingcnt == 15){ 10 : if(sensordir == 1){ 11 : ForwardPhotoSensor = inp(pinc)& 0x07; 12 : }else{ 13 : DownwardPhotoSensor = inp(pinc)&0x38; 14 : } 15 : cbi(portc, 6); 16 : } 17 : } Let s examine PhotoSensorUpdate() function again. Remember that each clock comes in at every us and one clock is used as a counter as it is which are defined in the initialization. The counter is initialized at every 16 cycles. It comes in at every us and increases the counter by 1 when TCNT equals 256 and the timer interrupt is generated. Then TCNT gets initialized to 0. Thus, the variable timingcnt gets initialized at 16 and 0.125*256*16 = 512 us, one sensor value is received at every 0.5 ms. If you want to change this time, you have to adjust the value of timingcnt or the value of prescaler. If the period of reading sensor value is set, let s analyze the input value now. The sensor input comes in through PINC. As mentioned before, the bit 0 to 5 of PINC are used to read the sensor value and the bit 6 is a bit for trigger. PhotoSensorUpdate() function includes a formula, which can be applied to both forward sensor and bottom sensor. However, we have assumed to read only the values of forward sensor, the value of SensorDir is 1 and the input value of PINC is determined by the value of pin 0 to 2 of port C. If the AND operation is executed with the value of , only the input values will be remained. As an example, if the forward-right sensor detects an obstacle, the following value comes out as a result & = Thus, we can decide that there is an obstacle at forward-right. If the forward-left sensor detects an obstacle, the following value comes out as a result. 82 of 138

83 & = In this case, we can decide that there is an obstacle at forward-left. In the case of rear sensors, it requires a little bit of more operations. If the rear-right sensor detects an obstacle, the following value comes out as a result & = Thus, we can decide that there is an obstacle at real-right. You can classify the one input among three forward sensors through this AND operation. Let s examine with the main function. 6 : sbi(ddrc,6); ====================================== 13 : if(forwardphotosensor == 0x01) 14 : { 15 : outp(0x0e, PORTB); 16 : }else if(forwardphotosensor == 0x02){ 17 : outp(0x0d, PORTB); 18 : }else if(forwardphotosensor == 0x04){ 19 : outp(0x0b, PORTB); 20 : }else if(forwardphotosensor == 0x00){ 21 : outp(0x0f, PORTB); Line 6: the bit 6 of PINC or the 6th register of port C is used as the signal trigger. If you want to understand the role of this pin, think about the structure of infrared ray sensor again. Infrared ray sensor has both emitter and receiver, where the sensor operates when a released signal from the emitter gets reflected and this is detected from the receiver. In other words, in order to decide an obstacle is located in front of which sensor, the emission of light must be occurred to the attached sensor. The bit 6 of PINC determines the emission of all sensors. Since the receiver has to be formed separately, it has a corresponding bit, but the emitter is controlled with one bit. Thus, the 6 th DDR register of port C is set to 1 and chosen as an output. You can achieve the emitting operation by making a bit HIGH/LOW and check the sensor input after achieving the receiving operation. The following is the sensor value of PINC : ( : clear, : set) : when the input is generated from the forward-right sensor : when the input is generated from the forward-front sensor : when the input is generated from the forward-left sensor 83 of 138

84 The above program turns LED on and off according to each input cases. Delay in the last of example program is inserted to make the counting speed of processor and the speed of obstacle contact identical. If this delay is not included, the processor receives the input value at very fast speed and turns LED on and off, which is impossible to observe the normal operation of sensor. With this, we have examined the method for using the infrared ray sensor Example Program 2 Let s make a program that informs the location of obstacle by combining the above program and infrared ray sensor. This program indicates the location of obstacle on LCD and turns LED on according to the sensor detection. Since this program is the combination of fully explained above programs, the detailed explanations are omitted here. 84 of 138

85 1 : #include "newbeetle.h" 2 : void main(void) 3 : { 4 : Initialize(); 5 : outp(0xff, DDRB), outp(0xff, PORTB); 6 : outp(0x00, DDRC), outp(0x00, PORTC); 7 : lcd_initialization(); 8 : lcd_command(0x0c); 9 : while(1) 10 : { 11 : SensorDir = 1; 12 : ControlPortc = 1; 13 : PhotoSensorUpdate(); 14 : sbi(ddrc, 6); 15 : if(forwardphotosensor == 0x01) 16 : { 17 : lcd_command(0x01); 18 : outp(0x0e, PORTB); 19 : lcd_str_output(1,"obstacle"); 20 : lcd_str_output(2," Right "); 21 : delayms(50); 22 : }else if(forwardphotosensor == 0x02){ 23 : lcd_command(0x01); 24 : outp(0x0d, PORTB); 25 : lcd_str_output(1,"obstacle"); 26 : lcd_str_output(2," Center "); 27 : delayms(50); 28 : }else if(forwardphotosensor == 0x04){ 29 : lcd_command(0x01); 30 : outp(0x0b, PORTB); 31 : lcd_str_output(1,"obstacle"); 32 : lcd_str_output(2," Left "); 33 : delayms(50); 34 : }else if(forwardphotosensor == 0x00){ 35 : lcd_command(0x01); 36 : outp(0x0f, PORTB); 37 : lcd_str_output(1,"obstacle"); 38 : lcd_str_output(2," Nothing"); 39 : delayms(50); 40 : } 41 : delayms(50); 42 : } 43 : } (Continue ) 85 of 138

86 44 : void lcd_command(unsigned char cmd) 45 : { 46 : delay(50); 47 : outp(0x04, PORTG); delay(50); 48 : outp(cmd, PORTA); delay(50); 49 : outp(0x00, PORTG); delay(50); 50 : } 51 : void lcd_initialization(void) 52 : { 53 : delayms(30); 54 : lcd_command(0x01); 55 : lcd_command(0x38); delayms(5); 56 : lcd_command(0x08); delayms(5); 57 : lcd_command(0x06); 58 : } 59 : void lcd_output(unsigned char data) 60 : { 61 : delay(5); 62 : outp(0x05, PORTG); delay(5); 63 : outp(data, PORTA); delay(5); 64 : outp(0x01, PORTG); delay(5); 65 : } 66 : void lcd_str_output(unsigned char line, unsigned char *msg) 67 : { 68 : lcd_line(line); 69 : while(*msg){ 70 : lcd_output(*(msg++)); 71 : delayms(5); 72 : } 73 : } 74 : void lcd_line(unsigned char line) 75 : { 76 : char address; 77 : if(line == 1) 78 : { 79 : address = 0x80; 80 : }else if(line == 2) 81 : { 82 : address = 0xc0; 83 : } 84 : lcd_command(address); 85 : } 86 of 138

87 Exercises By attaching a buzzer, make a program that generates a warning alarm and turns all 4 LEDs of LED module on when an obstacle is detected from the forward sensors, and then turns all LED off when an obstacle is disappeared. HINT1. Connect a buzzer on module #1 and set the values of DDR and port register. HINT2. Insert a function that rings buzzer and turns all LEDs on and off in the if statement of the above example, which is operated when ForwardPhotoSensor == 0x02 (forward obstacle). HINT3. Both buzzer and LED should not operate when the obstacle is disappeared. 87 of 138

88 4.4. CdS Sensor Operation of CdS Sensor CdS sensor is a Cadmium Sulfide cell, which is a crystal component that integrates cadmium and sulfur and connects a metal leg. It has the characteristic that the current flows when a visible ray is reached. In other words, it has the high resistance in the dark place, whereas it has the low resistance in the brighter place. Thus, it is used as an element to detect light. Figure CdS sensor module Figure Structure of CdS sensor Since the voltage value coming through CdS is an analog signal, microprocessor must use Analog to Digital Conversion (ADC) in order to use this value. Thus, let s examine about AD Converter provided by the processor. ADMUX is a bit, which must be set the very first time in AD converter. Figure is the block diagram of AD converter provided by ATmega64. Receiving analog signal ultimately changes to digital signal according to the bit setting of AD converter. 88 of 138

89 Figure AD Converter The following settings are done in order to use AD converter. Initially, set the bit of ADMUX. ADMUX, a register made up of 8-bit, is the register that decides the standard configuration of bit using in AD converter. Figure Bit organization of ADMUX REFS1 and REFS2 are bits that select the reference voltage of AD converter. Table displays the use of internal reference voltage according to the different configurations of REFS1 and REFS2. 89 of 138

90 Table Voltage reference selection according to REFS setting ADLAR indicates the aligned method of AD converter data. When it is 0, the data is aligned to the right, whereas aligned to the left when the value is 1. MUX 4 to MUX 0 set the analog channel. When MUX4:0 is set to one of ~ 00111, it selects one of ADC 0 ~ ADC 7 channels to use. Table Channel selection according to MUX setting Use of ADMUX is set up to (~00100) in MA-VIN. It does not have internal reference voltage and the data is aligned to the right. The number of total modules that can be connected to MA-VIN is 5 and it is possible to set the ADC channel of each slot. In other words, the total of 5 ADC channels (ADC0 to ADC4) is possible to set. Next set the bit of ADCSRA. ADCSRA means Analog Digital Control and Status Register A, which is the register that substantially indicates the operation setting of ADC. Figure Organization of ADCSRA Each bit has the following meaning: ADEN: ADC Enable ADSC: ADC Start Conversion 90 of 138

91 ADATE: ADC Auto Trigger Enable ADIF: ADC Interrupt FLAG ADIE: ADC Interrupt Enable ADPS2 - ADPS0: ADC Prescaler Select In other words, it allows using ADC when ADEN becomes Enable and ADC starts when the value of ADSC becomes 1. ADIE allows executing an interrupt through ADC and ADPS2 ~ ADPS1 set the use of prescaler. Table Usage of prescaler according to ADPS setting In MA-VIN, ADCSRA can be used as follows. Make ADEN Enable by changing the value of ADEN to HIGH. Make ADSC, ADIE, ADPS2, and ADPS0 to HIGH. Since the value of ADPS sets the value of prescaler, it is up to you to set to the desired value. Figure Input data through the channel ADC Data Register : ADC Data High/ ADC Data Low ADCH and ADCL are the received data through the ADC channel. Each data is received through the channel where the data is aligned to the right. The variable that we used so far is a constant of 8-bit. In order to use the same format of constant in ADC, the value of ADCH is shifted to the left 6 bits and the value of ADCL is shifted 91 of 138

92 to the right 2 bits. When OR operation is performed using these two values, the values of 8-bit between ADC 9 and ADC 2 are used. Figure Organization of ADCSRB Bit 7:3 Reserved bits ADTS2:0 ADC Auto Trigger Source Table Trigger configuration according to ADT setting When the values of ADTS2 to ADTS0 of ADCSRB are set to 000 to allow using Free Running Mode, the use of ADC becomes possible. Now, let s exercise the above configuration through an example. The example is a program that turns LED on according to the amount of light after connecting the CdS sensor module and the LED module to slot #1 and slot #2, respectively. When there is a large amount of light, all LEDs are turned on and LEDs are turned off sequentially according to the decreasing amount of light. 92 of 138

93 AD DDR PORT A/ D YES NO Figure Flow chart of turning LED on/off by using CdS sensor When the program is started, it performs the configuration of AD converter after passing the standard initialization process. Since this part is already explained before, refer to the previous descriptions. When the setting of ADMUX and ADCRSA is completed, analog signal arrives to ADC channel through CdS sensor. This signal changes to digital signal after passing AD converter, and turns LED on sequentially after estimating the magnitude of this signal. Let s examine this process in detail through the example program in the next section. 93 of 138

94 Example Program 1 : #include "newbeetle.h" 2 : void main() 3 : { 4 : Initialize(); 5 : outp(0x00, ADMUX); 6 : outp(0x80,adcsra); 7 : outp(0xff,ddrd); 8 : while(1) 9 : { 10 : outp(0xcd,adcsra); 11 : u08 temp; 12 : temp=(((adcl)>>2) ((ADCH)<<6)); 13 : if(temp < 2 temp > 120){ 14 : outp(0xff,portd); 15 : }else if(temp <= 3){ 16 : outp(0xfe,portd); 17 : }else if(temp <= 4){ 18 : outp(0xfc,portd); 19 : }else if(temp <= 6){ 20 : outp(0xf8,portd); 21 : }else if(temp <= 7){ 22 : outp(0xf0,portd); 23 : } 24 : } 25 : } ADMUX is It does not use internal reference voltage, uses channel 0 of ADC, and data is aligned to the right. ADCSRA is set to It represents making ADC Enable. DDRD is set up as an output. Create an infinite loop by using while loop, and change ADCSRA to Make the values of ADEN, ADSC, ADIF, and ADIE to HIGH, and set the prescaler to 32 by making the values of ADPS2 and ADPS0 to HIGH. Now the input value is coming into ADCL and ADCH through ADC channel 0. Save the value into temp after OR operation between ADCL>>2 and ADCH<<6. After comparing the magnitude of temp, output this value to the LED module. 94 of 138

95 Following figure shows the screenshots of output results: Exercises Make a program that displays the current amount of detected light on the 7- segment by receiving input through the CdS sensor. HINT1. Connect FND on the 2 nd module and set the values of DDR and port register. HINT2. Similar to classify the amount of light, set the range of data to classify the amount of light according 95 of 138

96 4.5. Microphone Operation of Microphone Microphone is a device that receives sound input. Sound is an analog signal. However, the microprocessor that we use deals with digital signal and thus ADC converter explained in the previous section has to be used. MA-VIN holds an internal microphone, where the microphone signal is received through the channel 6 of ADC, or the 6 th pin of PORTF. Figure Circuit diagram of microphone Figure shows the process when sound is transferred to a processor through a microphone. Input sound from the microphone (MIC) gets amplified through the transistors (Q13 and Q14) and ultimately transmitted to the processor through the MIC_IN terminal. Please refer to the following figure for the ADMUX configuration of ADC converter for microphone. Figure Configuration of ADMUX for microphone Similar to CdS, the configuration of ADC converter for microphone can be done through ADMUX. ADMUX is set up as because microphone uses channel 6. Since other configurations are identical to the CdS sensor, a detailed explanation is omitted. 96 of 138

97 AD DDR PORT A/ D YES NO Figure Flow chart of microphone operation Example Program The following program either turns on or off the LED from LED module according to the strength of sound incoming through a microphone. It is almost identical to the operation of CdS sensor, where the ADC converter channel that receives input signal (line 5) has been modified. Set the strength of microphone signal from MA-VIN in between 200 and 250. Since this magnitude changes according to the amplification of transistor, note that setting the strength of signal to this constant is restricted to only MA-VIN. 97 of 138

98 1 : #include "newbeetle.h" 2 : void main() 3 : { 4 : Initialize(); 5 : outp(0x06, ADMUX); 6 : outp(0x80, ADCSRA); 7 : outp(0xff,ddrb); 8 : u08 temp; 9 : while(1) 10 : { 11 : outp(0xc8,adcsra); 12 : temp=(((adcl)>>2) ((ADCH)<<6)); 13 : if(temp < 200 ){ 14 : outp(0xff,portb); 15 : }else if(temp > 200 && temp <211){ 16 : cbi(portb,0); 17 : }else if(temp > 211 && temp <222){ 18 : cbi(portb,1); 19 : }else if(temp > 222 && temp <233){ 20 : cbi(portb,2); 21 : }else if(temp > 233){ 22 : cbi(portb,3); 23 : } 24 : } 25 : } Exercises Make a program that indicates the strength of sound in the numerical range of 0 to 5 through 7-segment. HINT1. Attach FND on the 1 st module and set up the values of DDR and port register. HINT2. Think in the same method as the exercise of CdS sensor. 98 of 138

99 4.6. Remote Control Operation of Remote Control Remote controller, one of the tools used frequently in our daily lives, is a tool to control the electronic device at a long distance. Generally, a signal is sent by using infrared ray radiation and is used to control at a short distance. In MA-VIN, it provides a receiving module to receive infrared ray signal, which allows controlling a robot by using this. Figure shows the screenshot of remote controller provided by MA-VIN. The remote controller has up/down/left/right/stop buttons, L/R buttons, and SEND/EXIT/SET/SOUND/GAME buttons where the functionality of each button can be set by a user. The remote controller is fixed with a distinct signal for each button. Thus, the users can remote control according to the users demand when the generated signal is detected in the receiving module. Figure Remote controller of MA-VIN The following is the examples of generated signal from the remote controller. Figure Command signal generated from remote controller 99 of 138

100 By sending the input signal of 9 ms, it notifies the start of receiving input. Once the delay of 4.5 ms is elapsed, the custom code is sent. Custom code distinguishes the manufacturer and product. It sends the data when the custom code transmission is completed. It completes the one cycle of data transmission by sending an 8-bit data. The 8-bit data sent from the MA-VIN is shown as follows: Input Key Key Value RE_FRONT_KEY 0x02 RE_REAR_KEY 0x10 RE_RIGHT_KEY 0x20 RE_LEFT_KEY 0x08 RE_STOP_KEY 0xa0 RE_SEND_KEY 0x81 RE_EXIT_KEY 0x82 RE_SET_KEY 0x84 RE_SOUND_KEY 0x88 RE_GAME_KEY 0x90 RE_L_KEY 0x01 RE_R_KEY 0x04 Table Values of transmitted data according to the input key The infrared ray receiving module receives the signal generated from the remote controller at regular intervals. Once the signal is received, it analyzes the signal and executes the command according to the input signal. Figure Infrared ray receiving module The operation of remote controller is achieved through the following three functions within the header file: 1. GetRemocon(), 2. IrComm(), 3. IrRecv() 1: GetRemocon function saves the receiving values of remote controller receiving module into the register in order. 100 of 138

101 2: IrComm function calls IrRecv function according to the clock frequency. 3: IrRecv function receives the signal entering periodically and transfers this to GetRemocon function. Let s examine the following flow chart. DDR < > PORT YES NO 101 of 138 < > Figure Flow chart of remote control module As shown in Figure 4.6.4, an encoded signal is transmitted from remote controller and the remote controller receiving module receives the signal at regular intervals. When the transmitted signal is detected, the receiving module saves the signal into a temporary register. Once the analysis of saved signal in register is completed, it allows executing a command that matches with the signal. For detailed contents of necessary functions in each process, refer to the header file individually Example Program 1

102 Let s examine the following example. This example connects the receiving module of remote controller into slot #1 and the LCD module into slot #2. It is a program that turns each LED after receiving forward, backward, left, and right button of remote controller as an input. 1 : #include "newbeetle.h" 2 : void main() 3 : { 4 : Initialize(); 5 : outp(0xff, DDRD); 6 : outp(0xff, PORTD); 7 : while(1) 8 : { 9 : u08 temp; 10 : temp = GetRemocon(); 11 : if( (temp)==0x02) 12 : { 13 : cbi(portd, 0); 14 : }else if( (temp)==0x10){ 15 : cbi(portd, 1); 16 : }else if( (temp)==0x20){ 17 : cbi(portd, 2); 18 : }else if( (temp)==0x08){ 19 : cbi(portd, 3); 20 : }else 21 : outp(0xff, PORTD); 22 : } 23 : } In the above example, IrComm() or IrRecv() function is not mentioned. Instead of calling these two functions from the main function, they are continuously visited in a fixed interval when the program executes after the initialization. Through the timer inside of header file, two functions are activated once in 128 usec in order to detect an input signal. When the signal enters, the input value is sent back to GetRemocon function at this time and constantly waits for another input. Let s examine another example. This example connects the receiving module of remote controller into slot #1, and moves a robot by driving each motor after receiving forward, back, left, and right input. 102 of 138

103 Example Program 2 The following example is a program that moves an actual robot by driving motor after receiving the input from remote controller. It does simple forward/backward/left/right motion and in order to realize this, the method of calling the function that drives motor is used. Contents related to the motor, refer to the section 3.4 DC Motor. 103 of 138

104 1 : #include "newbeetle.h" 2 : void motorcontrol(u08 dir) 3 : { 4 : u08 speed = 5; 5 : org_pwm[0] = speed; 6 : org_pwm[1] = speed; 7 : if(dir == 0) // forward 8 : { 9 : outp(0x6d, PORTB); 10 : } else if(dir == 1) // back 11 : { 12 : outp(0x9f, PORTB); 13 : } else if(dir == 2) // left 14 : { 15 : outp(0x2b,portb); 16 : } else if(dir == 3) // right 17 : { 18 : outp(0x4e, PORTB); 19 : } else if(dir == 4) // Lrotate 20 : { 21 : sbi(portb, 6); cbi(portb, 5); 22 : sbi(portb, 4); cbi(portb, 7); 23 : } else if(dir == 5) // Rrotate 24 : { 25 : cbi(portb, 4); sbi(portb, 7); 26 : sbi(portb, 5); cbi(portb, 6); 27 : } else if(dir == 6) // stop 28 : { 29 : cbi(portb, 4); cbi(portb, 5); cbi(portb, 6); cbi(portb, 7); 30 : } 31 : } 32 : void main() 33 : { 34 : Initialize(); 35 : while(1) 36 : { 37 : u08 temp; 38 : temp = GetRemocon(); 39 : if( (temp)==0x02){ 40 : motorcontrol(0); 41 : }else if( (temp)==0x10){ 42 : motorcontrol(1); 43 : }else if( (temp)==0x20){ 44 : motorcontrol(3); 45 : }else if( (temp)==0x08){ 46 : motorcontrol(2); 47 : }else if( (temp)==0xa0){ 48 : motorcontrol(6); 49 : }else 50 : motorcontrol(6); 51 : } 52 : } 104 of 138

105 Exercises 1) Make a program that displays which button of remote controller is pressed on the LCD module. 2) By integrating the above exercise, make a program that displays the moving direction of remote controller on the LCD module. 3) Make a program that operates robot when the remote controller is pressed. HINT1. Contents related to the LCD module, refer to the section 3.5 LCD. HINT2. Drive the motor corresponds to the data transferred to the LCD module. HINT3. In the case of setting the motor drive function (use cbi command), or the remote controller is not pressed in the main function (it will change if you fix if statements), make sure to stop 105 of 138

106 5. Practical Examples 5.1. Line Tracer Line tracer, an extremely well-used exercise, is that robot follows the line drawn on the ground by using sensor. MA-VIN can implement the line tracer by using a bottom infrared ray sensor. The following example is the source code of line tracer that uses bottom sensor. The location of detected line is displayed on the LCD module and a simple line tracer can be implemented by driving motor according to the location of detected line. DDR PORT NO YES YES NO Figure Flow chart of line tracer 106 of 138

107 1 : #include "newbeetle.h" 2 : void lcd_command(unsigned char cmd) 3 : { 4 : delay(50); 5 : outp(0x04, PORTG); delay(50); 6 : outp(cmd, PORTA); delay(50); 7 : outp(0x00, PORTG); delay(50); 8 : } 9 : void lcd_initialization(void) 10 : { 11 : delayms(30); 12 : lcd_command(0x01); 13 : lcd_command(0x38); delayms(5); 14 : lcd_command(0x08); delayms(5); 15 : lcd_command(0x06); 16 : } 17 : void lcd_output(unsigned char data) 18 : { 19 : delay(5); 20 : outp(0x05, PORTG); delay(5); 21 : outp(data, PORTA); delay(5); 22 : outp(0x01, PORTG); delay(5); 23 : } 24 : void lcd_str_output(unsigned char line, unsigned char *msg) 25 : { 26 : lcd_line(line); 27 : while(*msg){ 28 : lcd_output(*(msg++)); 29 : delayms(5); } 30 : } 31 : void lcd_line(unsigned char line) 32 : { 33 : char address; 34 : if(line == 1){ 35 : address = 0x80; 36 : }else if(line == 2){ 37 : address = 0xc0;} 38 : lcd_command(address); 39 : } (Continue ) Line 2: it is the function that delivers commands to the LCD module: (5) passing Enable Signal, (6) setting command, and (7) running Down Edge. Line 9: it is the initialization function of LCD: (12) Display Clear, (13) Function Set, (14) Display On/Off, and (15) Entry Mode Set. Functions related to LCD are explained in section 3.5 LCD. If you have questions related to lcd_output, lcd_str_output, and lcd_line functions, refer to section 3.5 LCD. 107 of 138

108 40 : void motorcontrol(u08 dir) 41 : { 42 : u08 speed = 5; 43 : org_pwm[0] = speed; 44 : org_pwm[1] = speed; 45 : if(dir == 0) // forward 46 : { 47 : outp(0x6d, PORTB); 48 : } else if(dir == 1) // back 49 : { 50 : outp(0x9f, PORTB); 51 : } else if(dir == 2) // left 52 : { 53 : outp(0x2b,portb); 54 : } else if(dir == 3) // right 55 : { 56 : outp(0x4e, PORTB); 57 : } else if(dir == 4) // Lrotate 58 : { 59 : sbi(portb, 6); cbi(portb, 5); 60 : sbi(portb, 4); cbi(portb, 7); 61 : } else if(dir == 5) // Rrotate 62 : { 63 : cbi(portb, 4); sbi(portb, 7); 64 : sbi(portb, 5); cbi(portb, 6); 65 : } else if(dir == 6) // stop 66 : { 67 : cbi(portb, 4); cbi(portb, 5); cbi(portb, 6); cbi(portb, 7); 68 : } 69 : } 70 : void main(void) 71 : { 72 : Initialize(); 73 : sbi(ddrb, 4); sbi(ddrb, 5); sbi(ddrb, 6); sbi(ddrb, 7); 74 : sbi(ddre, 4); sbi(ddre, 5); // motor ref 75 : cbi(porte, 4); cbi(porte, 5); 76 : cbi(ddrd, 0); cbi(portd, 0); 77 : sbi(ddrd, 3); sbi(portd, 3); sbi(ddrc, 6); sbi(portc, 6); 78 : outp(0x00, SFIOR); 79 : u08 touch = 0; (Continue ) Line 40: the motor control function can be used for your convenience. To make a left turn, there is no law stating that the left wheel must turn backward. You can make a left turn if the right wheel turns faster than the left wheel. In addition, turning left can be obtained by turning only the right wheel while the left wheel is in stop state. Thus, it is up to you to make the operation of motor for your convenience. If the number of movement increases, the number of motor manipulation also increases. Thus, make sure to create the motor control function separately and use this by calling from the main function. It does not matter if you create functions separately related to the movements such as turning left or right, and moving straight and backward. Line 70: in the main function, the values of required DDR and PORT are set. Line tracer uses infrared ray sensor, motor and LCD module. 108 of 138

109 80 : while(1) 81 : { 82 : SensorDir = 0; 83 : ControlPortc = 1; 84 : PhotoSensorUpdate(); 85 : if( touch == 2) 86 : { 87 : touch = 0; 88 : motorcontrol(6); 89 : lcd_command(0x01); 90 : lcd_str_output(1," MOVING "); 91 : lcd_str_output(2,"stopped "); 92 : msecdelay(5); 93 : } else{ 94 : if( (0x01 & inp(pind)) == 0x01) 95 : { 96 : touch++; 97 : cbi(portd, 3); 98 : }else{ 99 : sbi(portd, 3); 100 : } 101 : } 102 : if(touch == 1) 103 : { 104 : if(downwardphotosensor == 0x10) 105 : { 106 : lcd_command(0x01); 107 : lcd_str_output(1," LINE "); 108 : lcd_str_output(2," CENTER "); 109 : motorcontrol(0); 110 : delayms(50); 111 : motorcontrol(6); 112 : }else if(downwardphotosensor == 0x08){ 113 : lcd_command(0x01); 114 : lcd_str_output(1," LINE "); 115 : lcd_str_output(2," RIGHT "); 116 : motorcontrol(4); 117 : delayms(50); 118 : motorcontrol(6); 119 : }else if(downwardphotosensor == 0x20){ 120 : lcd_command(0x01); 121 : lcd_str_output(1," LINE "); 122 : lcd_str_output(2," LEFT "); 123 : motorcontrol(5); delayms(50); 124 : motorcontrol(6); 125 : } (Continue ) Line 85: setting touch variable is required to include the ability to turn ON/OFF the robot movements. The value of touch variable is initially set to zero and this value increases when a contact is occurred. If the value of touch variable becomes 1, robot starts to move by following the line. If the contact is occurred one more time, robot stops its movement and the value of touch variable increases to 2. If this value equals 2, the value of touch variable becomes 0 due to if statements. When robot stops its movement, it waits for the next input command. 109 of 138

110 126 : else if(downwardphotosensor == 0x00){ 127 : lcd_command(0x01); 128 : lcd_str_output(1," LINE "); 129 : lcd_str_output(2,"?finding"); 130 : motorcontrol(5); 131 : delayms(50); 132 : motorcontrol(6); 133 : delayms(5); 134 : if(downwardphotosensor == 0x10 0x08 0x20 ) 135 : { 136 : lcd_command(0x01); 137 : lcd_str_output(1," LINE "); 138 : lcd_str_output(2,"!finding"); 139 : delayms(50); 140 : } else{ 141 : motorcontrol(5); 142 : delayms(50); 143 : motorcontrol(6); 144 : } 145 : } 146 : } 147 : delayms(5); 148 : } 149 : } Line 126: it is the case when robot fails to detect a line. It is up to you to create the most suitable movement of robot to find the line. Robot may find the line by making either a left or right turn. Robot may also find the line by moving backward. The most proper movement will change according to the situation. It is up to you to find out and apply the optimal method. Line 134: it is the case when two sensors detect a line at the same time when the lines were drawn close together. This is the part to set the movement of robot in this case. Since the optimal method changes according to the situation, it is up to you to find out a good method. 110 of 138

111 5.2. Obstacle Avoidance Obstacle avoidance using robot is one of the most used practical exercises of WMR (Wheeled Mobile Robot). MA-VIN can implement obstacle avoidance ability by using frontal sensors. The following example outputs the location of obstacle on the LCD module and avoidance movements are implemented according to the location of each obstacle. Once the exercise is completed through this example, it is expected you to challenge more complex obstacle avoidance movements. DDR PORT NO YES ( ) YES NO Figure Flow chart of obstacle avoidance 111 of 138

112 40 : #include "newbeetle.h" 41 : void lcd_command(unsigned char cmd) 42 : { 43 : delay(50); 44 : outp(0x04, PORTG); delay(50); 45 : outp(cmd, PORTA); delay(50); 46 : outp(0x00, PORTG); delay(50); 47 : } 48 : void lcd_initialization(void) 49 : { 50 : delayms(30); 51 : lcd_command(0x01); 52 : lcd_command(0x38); delayms(5); 53 : lcd_command(0x08); delayms(5); 54 : lcd_command(0x06); 55 : } 56 : void lcd_output(unsigned char data) 57 : { 58 : delay(5); 59 : outp(0x05, PORTG); delay(5); 60 : outp(data, PORTA); delay(5); 61 : outp(0x01, PORTG); delay(5); 62 : } 63 : void lcd_str_output(unsigned char line, unsigned char *msg) 64 : { 65 : lcd_line(line); 66 : while(*msg){ 67 : lcd_output(*(msg++)); 68 : delayms(5); } 69 : } 70 : void lcd_line(unsigned char line) 71 : { 72 : char address; 73 : if(line == 1){ 74 : address = 0x80; 75 : }else if(line == 2){ 76 : address = 0xc0;} 77 : lcd_command(address); 78 : } (Continue ) Line 1 39: the functions related to LCD module. Refer to section 5.1 Line Tracer or 3.5 LCD. 112 of 138

113 40 : void motorcontrol(u08 dir) 41 : { 42 : u08 speed = 5; 43 : org_pwm[0] = speed; 44 : org_pwm[1] = speed; 45 : if(dir == 0) // forward 46 : { 47 : outp(0x6d, PORTB); 48 : } else if(dir == 1) // back 49 : { 50 : outp(0x9f, PORTB); 51 : } else if(dir == 2) // left 52 : { 53 : outp(0x2b,portb); 54 : } else if(dir == 3) // right 55 : { 56 : outp(0x4e, PORTB); 57 : } else if(dir == 4) // Lrotate 58 : { 59 : sbi(portb, 6); cbi(portb, 5); 60 : sbi(portb, 4); cbi(portb, 7); 61 : } else if(dir == 5) // Rrotate 62 : { 63 : cbi(portb, 4); sbi(portb, 7); 64 : sbi(portb, 5); cbi(portb, 6); 65 : } else if(dir == 6) // stop 66 : { 67 : cbi(portb, 4); cbi(portb, 5); cbi(portb, 6); cbi(portb, 7); 68 : } 69 : } 70 : void main(void) 71 : { 72 : Initialize(); 73 : sbi(ddrb, 4); sbi(ddrb, 5); sbi(ddrb, 6); sbi(ddrb, 7); 74 : sbi(ddre, 4); sbi(ddre, 5); // motor ref 75 : cbi(porte, 4); cbi(porte, 5); 76 : cbi(ddrd, 0); cbi(portd, 0); 77 : sbi(ddrd, 3); sbi(portd, 3); sbi(ddrc, 6); sbi(portc, 6); 78 : outp(0x00, SFIOR); 79 : u08 touch = 0; (Continue ) Line 40 79: it is the initialization process of main function for motor and program. Refer to section 5.1 Line Tracer and section 3.4 DC Motor for the information related to motor. 113 of 138

114 80 : while(1) 81 : { 82 : SensorDir = 0; 83 : ControlPortc = 1; 84 : PhotoSensorUpdate(); 85 : if( touch == 2) 86 : { 87 : touch = 0; 88 : motorcontrol(6); 89 : lcd_command(0x01); 90 : lcd_str_output(1," MOVING "); 91 : lcd_str_output(2,"stopped "); 92 : msecdelay(5); 93 : } else{ 94 : if( (0x01 & inp(pind)) == 0x01) 95 : { 96 : touch++; 97 : cbi(portd, 3); 98 : }else{ 99 : sbi(portd, 3); 100 : } 101 : } 102 : 103 : if(touch == 1){ 104 : if(forwardphotosensor == 0x01){ 105 : lcd_command(0x01); 106 : lcd_str_output(1,"obstacle"); 107 : lcd_str_output(2," Right "); 108 : motorcontrol(6); //stop 109 : delayms(5); 110 : motorcontrol(1); // back 111 : msecdelay(3); 112 : motorcontrol(2); // moving left 113 : msecdelay(5); 114 : motorcontrol(5); // change direction 115 : msecdelay(2); 116 : motorcontrol(0); // straight 117 : delayms(5); }else if(forwardphotosensor == 0x02){ 118 : lcd_command(0x01); 119 : lcd_str_output(1,"obstacle"); 120 : lcd_str_output(2," Center "); 121 : motorcontrol(6); //stop 122 : delayms(5); 123 : motorcontrol(1); // back 124 : msecdelay(3); 125 : motorcontrol(4); // change direction 126 : msecdelay(3); 127 : motorcontrol(0); // moving a little 128 : msecdelay(5); 129 : motorcontrol(5); // change direction 130 : msecdelay(3); 131 : motorcontrol(0); // straight 132 : delayms(5); 133 : } (Continue ) Line : it is the identical structure as mentioned in line tracer. It is used to operate ON/OFF status of robot using the touch switch. Line : it describes the actions when robot meets an obstacle. When the right-side sensor detects obstacle, robot avoids to left direction. When obstacle is detected in the front, robot stops, moves backward, changes its direction, and moves forward again. 114 of 138

115 134 : else if(forwardphotosensor == 0x04){ 135 : lcd_command(0x01); 136 : lcd_str_output(1,"obstacle"); 137 : lcd_str_output(2," Left "); 138 : delayms(5); 139 : motorcontrol(6); //stop 140 : delayms(15); 141 : motorcontrol(1); // back 142 : msecdelay(3); 143 : motorcontrol(3); // moving right 144 : msecdelay(2); 145 : motorcontrol(5); // change direction 146 : msecdelay(2); 147 : motorcontrol(0); // straight 148 : delayms(5); 149 : }else if(forwardphotosensor == 0x00){ 150 : lcd_command(0x01); 151 : motorcontrol(0); 152 : lcd_str_output(1,"obstacle"); 153 : lcd_str_output(2," Nothing"); 154 : delayms(5); 155 : } 156 : delayms(5); 157 : } 158 : } 159 : } Line : when the left-side sensor detects obstacle, robot avoids to right direction. When there is no obstacle, robot continues moving forward. Obstacle avoidance method will be different according to the programmer. There are many algorithms related to obstacle avoidance and the algorithms are developed continuously. In this example, a simple obstacle avoidance method is used. Develop a method to reach the target point by avoiding obstacles and apply this method to the actual robot. 115 of 138

116 5.3. Following a Finger The following example implements robot following a finger. When the hand movement is detected by using frontal sensors, robot drives motor to follow the finger according to the location of sensor. If you think opposite to obstacle avoidance, you will be easily understood. In the case of obstacle avoidance, the program avoids obstacle when it is detected. In contrast, this program moves robot towards the direction of detected object through the sensor. Similar to the previous examples, the location of finger is displayed on the LCD module and robot moves towards the location of finger. DDR PORT NO YES YES NO Figure Flow chart for following a finger Line 1 40: the functions related to run the LCD module. Explanation is omitted because they are used in the practical examples 5.1 & of 138

117 1 : #include "newbeetle.h" 2 : void lcd_command(unsigned char cmd) 3 : { 4 : delay(50); 5 : outp(0x04, PORTG); delay(50); 6 : outp(cmd, PORTA); delay(50); 7 : outp(0x00, PORTG); delay(50); 8 : } 9 : void lcd_initialization(void) 10 : { 11 : delayms(30); 12 : lcd_command(0x01); 13 : lcd_command(0x38); delayms(5); 14 : lcd_command(0x08); delayms(5); 15 : lcd_command(0x06); 16 : } 17 : void lcd_output(unsigned char data) 18 : { 19 : delay(5); 20 : outp(0x05, PORTG); delay(5); 21 : outp(data, PORTA); delay(5); 22 : outp(0x01, PORTG); delay(5); 23 : } 24 : void lcd_str_output(unsigned char line, unsigned char *msg) 25 : { 26 : lcd_line(line); 27 : while(*msg){ 28 : lcd_output(*(msg++)); 29 : delayms(5); 30 : } 31 : } 32 : void lcd_line(unsigned char line) 33 : { 34 : char address; 35 : if(line == 1){ 36 : address = 0x80; 37 : }else if(line == 2){ 38 : address = 0xc0; 39 : } 40 : lcd_command(address); 41 : } (Continue ) 117 of 138

118 42 : void motorcontrol(u08 dir) 43 : { 44 : u08 speed = 5; 45 : org_pwm[0] = speed; 46 : org_pwm[1] = speed; 47 : if(dir == 0) // forward 48 : { 49 : outp(0x6d, PORTB); 50 : } else if(dir == 1) // back 51 : { 52 : outp(0x9f, PORTB); 53 : } else if(dir == 2) // left 54 : { 55 : outp(0x2b,portb); 56 : } else if(dir == 3) // right 57 : { 58 : outp(0x4e, PORTB); 59 : } else if(dir == 4) // Lrotate 60 : { 61 : sbi(portb, 6); cbi(portb, 5); 62 : sbi(portb, 4); cbi(portb, 7); 63 : } else if(dir == 5) // Rrotate 64 : { 65 : cbi(portb, 4); sbi(portb, 7); 66 : sbi(portb, 5); cbi(portb, 6); 67 : } else if(dir == 6) // stop 68 : { 69 : cbi(portb, 4); cbi(portb, 5); cbi(portb, 6); cbi(portb, 7); 70 : } 71 : } 72 : void main(void) 73 : { 74 : Initialize(); 75 : sbi(ddrb, 4); sbi(ddrb, 5); sbi(ddrb, 6); sbi(ddrb, 7); 76 : sbi(ddre, 4); sbi(ddre, 5); // motor ref 77 : cbi(porte, 4); cbi(porte, 5); 78 : cbi(ddrd, 0); cbi(portd, 0); 79 : sbi(ddrd, 3); sbi(portd, 3); sbi(ddrc, 6); sbi(portc, 6); 80 : outp(0x00, SFIOR); 81 : u08 touch = 0; 82 : while(1) 83 : { 84 : SensorDir = 1; 85 : ControlPortc = 1; 86 : PhotoSensorUpdate(); 118 of 138 (Continue )

119 87 : if( touch == 2){ 88 : touch = 0; 89 : motorcontrol(6); 90 : lcd_command(0x01); 91 : lcd_str_output(1," MOVING "); 92 : lcd_str_output(2,"stopped "); 93 : msecdelay(5); 94 : } else{ 95 : if( (0x01 & inp(pind)) == 0x01){ 96 : touch++; 97 : cbi(portd, 3); 98 : }else{ 99 : sbi(portd, 3); 100 : } 101 : } 102 : if(touch == 1){ 103 : if(forwardphotosensor == 0x01){ 104 : lcd_command(0x01); 105 : lcd_str_output(1," FINGER "); 106 : lcd_str_output(2," Right "); 107 : motorcontrol(3); delayms(100); 108 : motorcontrol(6); 109 : }else if(forwardphotosensor == 0x02){ 110 : lcd_command(0x01); 111 : lcd_str_output(1," FINGER "); 112 : lcd_str_output(2," Center "); 113 : motorcontrol(0); delayms(100); 114 : motorcontrol(6); 115 : }else if(forwardphotosensor == 0x04){ 116 : lcd_command(0x01); 117 : lcd_str_output(1," FINGER "); 118 : lcd_str_output(2," Left "); 119 : motorcontrol(2); delayms(100); 120 : motorcontrol(6); 121 : }else if(forwardphotosensor == 0x00){ 122 : lcd_command(0x01); 123 : lcd_str_output(1," FINGER "); 124 : lcd_str_output(2," Where? "); 125 : motorcontrol(6); delayms(100); 126 : } 127 : delayms(5); 128 : } 129 : } 130 : } Line : it is the program that follows an obstacle by driving the robot motor according to the location of detected obstacle. When the right-side sensor detects obstacle, it drives the left-side wheel of robot to turn in a clockwise direction, whereas it drives the right-side wheel to turn in a counter clockwise direction when the left-side sensor detects obstacle. In the case of no obstacles, robot maintains the stop condition until obstacle is detected. Stop function, motorcontrol(6), is included in each locomotion functions of robot because robot can move repeatedly without interruption. If the moving speed of robot is faster than the 119 of 138

120 moving speed of obstacle, robot may cause problems. Thus, it is a small prevention to avoid this type of situation. 120 of 138

121 5.4. Passing an Intersection Let s add a function that passes through an intersection by using line tracer implemented in the previous example. When robot meets an intersection, bottom sensor receives various values at once. If the proper algorithm is provided for each case, robot may go to one of the path according the provided algorithm at this moment. Since there are various methods to pass an intersection, it is up to you to add your individual method by applying the following example. In this example, the method of passing an intersection made up of a crossroads is omitted. In this case, there are methods to pass by turning to the left or right, and moving forward. You should implement this program to examine its results. Figure Flow chart for passing an intersection Line 1 40: the functions related to run the LCD module. 121 of 138

122 42 : #include "newbeetle.h" 43 : void lcd_command(unsigned char cmd) 44 : { 45 : delay(50); 46 : outp(0x04, PORTG); delay(50); 47 : outp(cmd, PORTA); delay(50); 48 : outp(0x00, PORTG); delay(50); 49 : } 50 : void lcd_initialization(void) 51 : { 52 : delayms(30); 53 : lcd_command(0x01); 54 : lcd_command(0x38); delayms(5); 55 : lcd_command(0x08); delayms(5); 56 : lcd_command(0x06); 57 : } 58 : void lcd_output(unsigned char data) 59 : { 60 : delay(5); 61 : outp(0x05, PORTG); delay(5); 62 : outp(data, PORTA); delay(5); 63 : outp(0x01, PORTG); delay(5); 64 : } 65 : void lcd_str_output(unsigned char line, unsigned char *msg) 66 : { 67 : lcd_line(line); 68 : while(*msg){ 69 : lcd_output(*(msg++)); 70 : delayms(5); 71 : } 72 : } 73 : void lcd_line(unsigned char line) 74 : { 75 : char address; 76 : if(line == 1){ 77 : address = 0x80; 78 : }else if(line == 2){ 79 : address = 0xc0; 80 : } 81 : lcd_command(address); 82 : } (Continue ) 122 of 138

123 87 : void motorcontrol(u08 dir) 88 : { 89 : u08 speed = 5; 90 : org_pwm[0] = speed; 91 : org_pwm[1] = speed; 92 : if(dir == 0) // forward 93 : { 94 : outp(0x6d, PORTB); 95 : } else if(dir == 1) // back 96 : { 97 : outp(0x9f, PORTB); 98 : } else if(dir == 2) // left 99 : { 100 : outp(0x2b,portb); 101 : } else if(dir == 3) // right 102 : { 103 : outp(0x4e, PORTB); 104 : } else if(dir == 4) // Lrotate 105 : { 106 : sbi(portb, 6); cbi(portb, 5); 107 : sbi(portb, 4); cbi(portb, 7); 108 : } else if(dir == 5) // Rrotate 109 : { 110 : cbi(portb, 4); sbi(portb, 7); 111 : sbi(portb, 5); cbi(portb, 6); 112 : } else if(dir == 6) // stop 113 : { 114 : cbi(portb, 4); cbi(portb, 5); cbi(portb, 6); cbi(portb, 7); 115 : } 116 : } 117 : void main(void) 118 : { 119 : Initialize(); 120 : sbi(ddrb, 4); sbi(ddrb, 5); sbi(ddrb, 6); sbi(ddrb, 7); 121 : sbi(ddre, 4); sbi(ddre, 5); // motor ref 122 : cbi(porte, 4); cbi(porte, 5); 123 : cbi(ddrd, 0); cbi(portd, 0); 124 : sbi(ddrd, 3); sbi(portd, 3); sbi(ddrc, 6); sbi(portc, 6); 125 : outp(0x00, SFIOR); 126 : u08 touch = 0; 127 : while(1) 128 : { 129 : SensorDir = 1; 130 : ControlPortc = 1; 131 : PhotoSensorUpdate(); (Continue ) Line 42 86: it is the motor control function and the initialization process from the main function for motor and LCD module. In the while loop, the value of infrared ray sensor is received through PhotoSensorUpdate function. 123 of 138

124 87 : if( touch == 2) 88 : { 89 : touch = 0; 90 : motorcontrol(6); 91 : lcd_command(0x01); 92 : lcd_str_output(1," MOVING "); 93 : lcd_str_output(2,"stopped "); 94 : msecdelay(5); 95 : } else{ 96 : if( (0x01 & inp(pind)) == 0x01) 97 : { 98 : touch++; 99 : cbi(portd, 3); 100 : }else{ 101 : sbi(portd, 3); 102 : } 103 : } 104 : if(touch == 1) 105 : { 106 : if(downwardphotosensor == 0x10) 107 : { 108 : lcd_command(0x01); 109 : lcd_str_output(1," LINE "); 110 : lcd_str_output(2," CENTER "); 111 : motorcontrol(0); 112 : delayms(50); 113 : motorcontrol(6); 114 : }else if(downwardphotosensor == 0x08){ 115 : lcd_command(0x01); 116 : lcd_str_output(1," LINE "); 117 : lcd_str_output(2," RIGHT "); 118 : motorcontrol(4); 119 : delayms(70); 120 : motorcontrol(6); 121 : }else if(downwardphotosensor == 0x20){ 122 : lcd_command(0x01); 123 : lcd_str_output(1," LINE "); 124 : lcd_str_output(2," LEFT "); 125 : motorcontrol(5); 126 : delayms(70); 127 : motorcontrol(6); 128 : }else if(downwardphotosensor == 0x30){ 129 : lcd_command(0x01); 130 : lcd_str_output(1," LINE "); 131 : lcd_str_output(2,"!l_cross"); 132 : motorcontrol(5); 133 : delayms(70); 134 : motorcontrol(6); (Continue ) Line : it describes the robot movement according to the location of line. Line 128: it is the counter plan when sensor detects an intersection. When the leftside sensor and frontal sensor detect a line at the same time, sensor transmits the value of It describes robot moving to the left on this occasion. 124 of 138

125 135 : if(downwardphotosensor == 0x38){ 136 : lcd_command(0x01); 137 : lcd_str_output(1," KEEP "); 138 : lcd_str_output(2," GOING! "); 139 : motorcontrol(2); 140 : delayms(70); 141 : motorcontrol(6); 142 : }else if(downwardphotosensor == 0x18){ 143 : lcd_command(0x01); 144 : lcd_str_output(1," LINE "); 145 : lcd_str_output(2,"!r_cross"); 146 : motorcontrol(4); 147 : delayms(70); 148 : motorcontrol(6); 149 : if(downwardphotosensor == 0x38){ 150 : lcd_command(0x01); 151 : lcd_str_output(1," KEEP "); 152 : lcd_str_output(2," GOING! "); 153 : motorcontrol(3); 154 : delayms(70); 155 : motorcontrol(6); 156 : } 157 : }else if(downwardphotosensor == 0x38){ 158 : lcd_command(0x01); 159 : lcd_str_output(1," LINE "); 160 : lcd_str_output(2,"!4_cross"); 161 : msecdelay(5); 162 : }else if(downwardphotosensor == 0x00){ 163 : lcd_command(0x01); 164 : lcd_str_output(1," LINE "); 165 : lcd_str_output(2,"?finding"); 166 : motorcontrol(5); 167 : delayms(70); 168 : motorcontrol(6); 169 : delayms(5); 170 : } 171 : } 172 : delayms(5); 173 : } 174 : } 175 : } Line 135: when robot executes the function in line 128, there is a case where all left, right, and frontal sensors detect a line. At this time, it provides the movestraight command to solve a deadlock. Line : it is the method when the right-hand intersection is detected. The method is generated exactly same as the left turn. Line 157: when robot meets a junction of three roads in the case of moving straight, the robot stays in stop condition. It is up to you to decide whether to make a left or right turn. Line 162: it is the counter plan when robot lost a line. In this example, robot turns left to find a line. However, it is up to you to find out and apply the optimal method. 125 of 138

126 5.5. Function Selectable Robot (Line Tracer + Obstacle Avoidance + Following a Finger) Let s find out a method to run one operation by selecting one of the previous exercises when line tracer, obstacle avoidance, and following a finger are all put together. The below example has assumed that there is a push switch in the 1 st slot, a LED in the 2 nd slot, and a touch sensor in the 4 th slot. In this example, the mode selecting function is included in between line 70 and 89, the mode selection according to the switch input is included in between line 112 and 138, and the practical examples from 5.1 to 5.3 are added lastly according to each mode. Analyze source code individually and try to apply a new operation for each mode. Figure Flow chart that allows selecting one of the three mode operations 126 of 138

127 1 : #include "newbeetle.h" 2 : void lcd_command(unsigned char cmd) 3 : { 4 : delay(50); 5 : outp(0x04, PORTG); delay(50); 6 : outp(cmd, PORTA); delay(50); 7 : outp(0x00, PORTG); delay(50); 8 : } 9 : void lcd_initialization(void) 10 : { 11 : delayms(30); 12 : lcd_command(0x01); 13 : lcd_command(0x38); delayms(5); 14 : lcd_command(0x08); delayms(5); 15 : lcd_command(0x06); 16 : } 17 : void lcd_output(unsigned char data) 18 : { 19 : delay(5); 20 : outp(0x05, PORTG); delay(5); 21 : outp(data, PORTA); delay(5); 22 : outp(0x01, PORTG); delay(5); 23 : } 24 : void lcd_str_output(unsigned char line, unsigned char *msg) 25 : { 26 : lcd_line(line); 27 : while(*msg){ 28 : lcd_output(*(msg++)); 29 : delayms(5); 30 : } 31 : } 32 : void lcd_line(unsigned char line) 33 : { 34 : char address; 35 : if(line == 1) 36 : { 37 : address = 0x80; 38 : }else if(line == 2){ 39 : address = 0xc0; 40 : } 41 : lcd_command(address); 42 : } (Continue ) 127 of 138

128 43 : void motorcontrol(u08 dir) 44 : { 45 : u08 speed = 5; 46 : org_pwm[0] = speed; 47 : org_pwm[1] = speed; 48 : if(dir == 0){ // forward 49 : sbi(portb, 5); sbi(portb, 6); 50 : cbi(portb, 4); cbi(portb, 7); 51 : } else if(dir == 1){ // back 52 : sbi(portb, 4); sbi(portb, 7); 53 : cbi(portb, 5); cbi(portb, 6); 54 : } else if(dir == 2){ // left 55 : sbi(portb, 5); 56 : cbi(portb, 4); cbi(portb, 6); cbi(portb, 7); 57 : } else if(dir == 3){ // right 58 : sbi(portb, 6); 59 : cbi(portb, 4); cbi(portb, 5); cbi(portb, 7); 60 : } else if(dir == 4){ // Lrotate 61 : sbi(portb, 6); cbi(portb, 5); 62 : sbi(portb, 4); cbi(portb, 7); 63 : } else if(dir == 5){ // Rrotate 64 : cbi(portb, 4); sbi(portb, 7); 65 : sbi(portb, 5); cbi(portb, 6); 66 : } else if(dir == 6){ // stop 67 : cbi(portb, 4); cbi(portb, 5); cbi(portb, 6); cbi(portb, 7); 68 : } 69 : } 70 : void mode_select(u08 mod) 71 : { 72 : if( mod == 0 ) 73 : { 74 : cbi(portd, 0); 75 : lcd_command(0x01); 76 : lcd_str_output(1," MODE "); 77 : lcd_str_output(2,"1:tracer"); 78 : } else if( mod == 1 ){ 79 : cbi(portd, 1); 80 : lcd_command(0x01); 81 : lcd_str_output(1," MODE "); 82 : lcd_str_output(2,"2: Avoid"); 83 : } else if( mod == 2 ){ 84 : cbi(portd, 2); 85 : lcd_command(0x01); 86 : lcd_str_output(1," MODE "); 87 : lcd_str_output(2,"3:follow"); 88 : } 89 : } (Continue ) 128 of 138

129 90 : void main(void) 91 : { 92 : Initialize(); 93 : sbi(ddre, 4); sbi(ddre, 5); // motor ref 94 : cbi(porte, 4); cbi(porte, 5); 95 : sbi(ddrb, 4); sbi(ddrb, 5); sbi(ddrb, 6); sbi(ddrb, 7); // Setting DDR for motor 96 : sbi(portb, 4); sbi(portb, 5); sbi(portb, 6); sbi(portb, 7); // Setting PORT for motor 97 : sbi(ddrd, 0); sbi(ddrd, 1); sbi(ddrd, 2); sbi(ddrd, 3); // Setting DDR for LED 98 : sbi(portd, 0); sbi(portd, 1); sbi(portd, 2); sbi(portd, 3); // Setting PORT for LED : off 99 : cbi(ddre, 0); sbi(ddre, 3); // Setting DDR for touch switch 100 : cbi(porte, 0); sbi(porte, 3); // Setting for touch switch port 101 : cbi(ddrb, 0); cbi(ddrb, 1); cbi(portb, 2); // Setting DDR for push switch 102 : sbi(portb, 0); sbi(portb, 1); sbi(portb, 2); // Setting port for push switch 103 : sbi(ddrc, 6); 104 : outp(0x00, SFIOR); 105 : lcd_command(0x01); 106 : lcd_str_output(1," SELECT "); 107 : lcd_str_output(2,"mode 1:3"); 108 : msecdelay(5); 109 : u08 touch1 = 0; u08 touch2 = 0; u08 touch3 = 0; u08 mode = 0; 110 : while(1) 111 : { 112 : if( (0x01 & inp(pinb)) == 0 ) 113 : { 114 : sbi(portd, 0); sbi(portd, 1); sbi(portd, 2); sbi(portd, 3); 115 : mode_select(0); 116 : mode = 1; 117 : SensorDir = 0; 118 : ControlPortc = 1; 119 : PhotoSensorUpdate(); 120 : sbi(portc, 6); 121 : } else if( (0x02 & inp(pinb)) == 0 ){ 122 : sbi(portd, 0); sbi(portd, 1); sbi(portd, 2); sbi(portd, 3); 123 : mode_select(1); 124 : mode = 2; 125 : SensorDir = 1; 126 : ControlPortc = 1; 127 : PhotoSensorUpdate(); 128 : sbi(portc, 6); 129 : } (Continue ) 129 of 138

130 130 : else if( (0x04 & inp(pinb)) == 0 ){ 131 : sbi(portd, 0); sbi(portd, 1); sbi(portd, 2); sbi(portd, 3); 132 : mode_select(2); 133 : mode = 3; 134 : SensorDir = 1; 135 : ControlPortc = 1; 136 : PhotoSensorUpdate(); 137 : sbi(portc, 6); 138 : } 139 : if( mode == 1 ) 140 : { 141 : if( touch1 == 2) 142 : { 143 : touch1 = 0; 144 : motorcontrol(6); 145 : lcd_command(0x01); 146 : lcd_str_output(1," MOVING "); 147 : lcd_str_output(2,"stopped "); 148 : msecdelay(5); 149 : } else{ 150 : if( (0x01 & inp(pine)) == 0x01) 151 : { 152 : touch1++; 153 : cbi(porte, 3); 154 : } else{ 155 : sbi(porte, 3); 156 : } 157 : } 158 : if( touch1 == 1){ 159 : if(downwardphotosensor == 0x10) 160 : { 161 : lcd_command(0x01); 162 : lcd_str_output(1," LINE "); 163 : lcd_str_output(2," CENTER "); 164 : motorcontrol(0); 165 : delayms(50); 166 : motorcontrol(6); 167 : }else if(downwardphotosensor == 0x08){ 168 : lcd_command(0x01); 169 : lcd_str_output(1," LINE "); 170 : lcd_str_output(2," RIGHT "); 171 : motorcontrol(4); 172 : delayms(70); 173 : motorcontrol(6); 174 : } 130 of 138 (Continue )

131 175 : else if(downwardphotosensor == 0x20){ 176 : lcd_command(0x01); 177 : lcd_str_output(1," LINE "); 178 : lcd_str_output(2," LEFT "); 179 : motorcontrol(5); 180 : delayms(70); 181 : motorcontrol(6); 182 : }else if(downwardphotosensor == 0x30){ 183 : lcd_command(0x01); 184 : lcd_str_output(1," LINE "); 185 : lcd_str_output(2,"!l_cross"); 186 : motorcontrol(5); 187 : delayms(70); 188 : motorcontrol(6); 189 : if(downwardphotosensor == 0x38){ 190 : lcd_command(0x01); 191 : lcd_str_output(1," KEEP "); 192 : lcd_str_output(2," GOING! "); 193 : motorcontrol(2); 194 : delayms(70); 195 : motorcontrol(6); 196 : } 197 : }else if(downwardphotosensor == 0x18){ 198 : lcd_command(0x01); 199 : lcd_str_output(1," LINE "); 200 : lcd_str_output(2,"!r_cross"); 201 : motorcontrol(4); 202 : delayms(70); 203 : motorcontrol(6); 204 : if(downwardphotosensor == 0x38){ 205 : lcd_command(0x01); 206 : lcd_str_output(1," KEEP "); 207 : lcd_str_output(2," GOING! "); 208 : motorcontrol(3); 209 : delayms(70); 210 : motorcontrol(6); 211 : } (Continue ) 131 of 138

132 212 : else if(downwardphotosensor == 0x38){ 213 : lcd_command(0x01); 214 : lcd_str_output(1," LINE "); 215 : lcd_str_output(2,"!4_cross"); 216 : msecdelay(5); 217 : }else if(downwardphotosensor == 0x00){ 218 : lcd_command(0x01); 219 : lcd_str_output(1," LINE "); 220 : lcd_str_output(2,"?finding"); 221 : motorcontrol(5); 222 : delayms(70); 223 : motorcontrol(6); 224 : delayms(5); 225 : } 226 : } 227 : } else if(mode == 2){ 228 : if( touch2 == 2) 229 : { 230 : touch2 = 0; 231 : motorcontrol(6); 232 : lcd_command(0x01); 233 : lcd_str_output(1," MOVING "); 234 : lcd_str_output(2,"stopped "); 235 : msecdelay(5); 236 : } else{ 237 : if( (0x01 & inp(pine)) == 0x01) 238 : { 239 : touch2++; 240 : cbi(porte, 3); 241 : } else{ 242 : sbi(porte, 3); 243 : } 244 : } (Continue ) 132 of 138

133 245 : if(touch2 == 1) 246 : { 247 : if(forwardphotosensor == 0x01) 248 : { 249 : lcd_command(0x01); 250 : lcd_str_output(1,"obstacle"); 251 : lcd_str_output(2," Right "); 252 : motorcontrol(6); //stop 253 : delayms(5); 254 : motorcontrol(1); // back 255 : msecdelay(3); 256 : motorcontrol(2); // moving left 257 : msecdelay(5); 258 : motorcontrol(5); // change direction 259 : msecdelay(2); 260 : motorcontrol(0); // straight 261 : delayms(5); 262 : motorcontrol(6); 263 : delayms(5); 264 : }else if(forwardphotosensor == 0x02){ 265 : lcd_command(0x01); 266 : lcd_str_output(1,"obstacle"); 267 : lcd_str_output(2," Center "); 268 : motorcontrol(6); //stop 269 : delayms(5); 270 : motorcontrol(1); // back 271 : msecdelay(3); 272 : motorcontrol(4); // change direction 273 : msecdelay(3); 274 : motorcontrol(0); // moving a little 275 : msecdelay(5); 276 : motorcontrol(5); // change direction 277 : msecdelay(3); 278 : motorcontrol(0); // straight 279 : delayms(5); 280 : }else if(forwardphotosensor == 0x04){ 281 : lcd_command(0x01); 282 : lcd_str_output(1,"obstacle"); 283 : lcd_str_output(2," Left "); 284 : delayms(5); 285 : motorcontrol(6); //stop 286 : delayms(15); 287 : motorcontrol(1); // back 288 : msecdelay(3); (Continue ) 133 of 138

134 289 : motorcontrol(3); // moving right 290 : msecdelay(2); 291 : motorcontrol(5); // change direction 292 : msecdelay(2); 293 : motorcontrol(0); // straight 294 : delayms(5); 295 : }else if(forwardphotosensor == 0x00){ 296 : lcd_command(0x01); 297 : motorcontrol(0); 298 : lcd_str_output(1,"obstacle"); 299 : lcd_str_output(2," Nothing"); 300 : delayms(50); 301 : motorcontrol(6); 302 : delayms(50); 303 : } 304 : delayms(5); 305 : } 306 : } else if( mode == 3){ 307 : if( touch3 == 2) 308 : { 309 : touch3 = 0; 310 : motorcontrol(6); 311 : lcd_command(0x01); 312 : lcd_str_output(1," MOVING "); 313 : lcd_str_output(2,"stopped "); 314 : msecdelay(5); 315 : } else{ 316 : if( (0x01 & inp(pine)) == 0x01) 317 : { 318 : touch3++; 319 : cbi(porte, 3); 320 : } else{ 321 : sbi(porte, 3); 322 : } 323 : } 324 : if(touch3 == 1) 325 : { 326 : if(forwardphotosensor == 0x01) 327 : { 328 : lcd_command(0x01); 329 : lcd_str_output(1," FINGER "); 330 : lcd_str_output(2," Right "); 331 : motorcontrol(3); 332 : delayms(100); (Continue ) 134 of 138

135 333 : motorcontrol(6); 334 : }else if(forwardphotosensor == 0x02){ 335 : lcd_command(0x01); 336 : lcd_str_output(1," FINGER "); 337 : lcd_str_output(2," Center "); 338 : motorcontrol(0); 339 : delayms(100); 340 : motorcontrol(6); 341 : }else if(forwardphotosensor == 0x04){ 342 : lcd_command(0x01); 343 : lcd_str_output(1," FINGER "); 344 : lcd_str_output(2," Left "); 345 : motorcontrol(2); 346 : delayms(100); 347 : motorcontrol(6); 348 : }else if(forwardphotosensor == 0x00){ 349 : lcd_command(0x01); 350 : lcd_str_output(1," FINGER "); 351 : lcd_str_output(2," Where? "); 352 : motorcontrol(6); 353 : delayms(100); 354 : } 355 : } 356 : delayms(5); 357 : } 358 : delayms(5); 359 : } 360 : } 135 of 138

136 Appendix1. Initialization Function All programs that we have exercised include the header file called, newbeetle.h. Essentially, this header file must be included in order to use MA-VIN, which stores all basic configurations of MA-VIN. You may remember that the main function of example programs always called Initialize() function. This function is defined in the header file and executes the necessary actions of initialization process in order to use MA-VIN. This section examines about this initialization function. 1 : void Initialize() 2 : { 3 : outp(0x40, DDRC); 4 : outp(0xff, PORTC); 5 : outp(0x00, TCNT0); 6 : outp(0x01, TCCR0); // 1 prescale 7 : outp(bv(toie0), TIMSK); // timer0 enable 8 : sei(); 9 : lcd_port_init(); 10 : lcd_init(); 11 : outp(ddrf_input,ddrf); // ADC Initialize 12 : InitADC(); // ADC mode setting 13 : lcd_str_out(1,1,empty); 14 : lcd_str_out(2,1,empty) 15 : delay(100); 16 : } Line 3: DDRC is set to for sensor trigger and PC #7 of MA-VIN is not used. PC #6 is used as sensor trigger and represents the configuration of DDR in order to receive PC5:0 as an input. Line 4: Setting PORTC to is related to DDRC in line #3 and it represents providing a HIGH value to PORTC. Line 5: TCNT0 is a timer/counter register, which increases its value according to the clock by setting this value to Line 6: TCCR0 is a timer/counter control register and the meaning of is shown as follows: F O C 0 W G M 0 0 C O M 0 1 C O M W G M 0 1 C S 0 2 C S 0 1 C S of 138

137 a. Force Output Compare: Activates when WGM bit is in non-pwm mode. When this bit is set to 1, the compare match immediately becomes a waveform generation unit, and the output of OC0 changes according to the configuration of COM1:0. FOC0 can be used as a strobe. FOC0 strobe does not generate any kinds of interrupt and clears the timer in CTC mode, which uses OCR0 as TOP. b. Timer/Counter Mode = Normal means that the counter is always in increasing mode and never gets cleared. When the value of counter becomes OxFF, it starts from 0x00 again. c. COM01:0 = Operates with the general parallel port. d. CS01:0 = clk TOS /(No prescaling): In other words, one of source clock is operated by the one of system clock. Line 7: TIMSK is a timer/counter interrupt mask register, which is the register that enables interrupt individually. When TOIE0 is set to 1 and system interrupt is set to ENABLE, overflow interrupt of normal mode activates. Line 8: sei() function enables global interrupt. Line 9: lcd_port_init() function initializes the values of DDR and PORT in order to operate the LCD module as shown in section 3.5 LCD. DDRG and DDRA are selected as an output, and PORTG and PORTA are set to 0. Line 10: lcd_init() function runs the functions such as Function Set, Display Clear, and Entry Mode Set to operate the LCD module. Keep in mind that enough delay time is necessary for each initialization process. Line 11: outp(ddrf_input, DDRF) / DDRF_INPUT is defined as ~(DDRF_OUTPUT) and DDRF_OUTPUT((1<<AD_0) (1<<AD_1) (1<<AD_2) (1<< AD_3) (1<<AD_4) (1<<M4_4_AD) (1<<MIC_IN) (1<<V_TEST)). Since DDRF_OUTPUT = and ~(DDRF_OUTPUT) = , DDRF = Line 12: in InitADC() function, ADSRA is a ADC Control Status Regiser A, and ADIF=0, ADEN = 1, ADIE = 1, and ADPS0 = 0 -> ADCSRA = A D E N A D S C A D F R A D I F A D I E A D P S 2 A D P S 1 A D P S Each meaning is shown as follows: a. ADEN = 1: ADC module becomes Enable. b. ADSC = 0: It does not conduct AD conversion. c. ADFR = 0: It is not Free Running Mode. d. ADIF = 0: Since there is no AD conversion, AD conversion termination 137 of 138

138 interrupt does not activate. e. ADIE = 1: Set AD conversion termination interrupts individually. f. ADPS2:0 = 001: Division of clock applied to the ADC module is 2. ADMUX is an ADC multiplexer selection register, which selects the analog input channel of ADC module, the reference voltage of ADC module, or the data saving format of converted result of register. The value of this register is set to and its meaning is shown as follows: R E F S 1 R E F S 0 A D L A R M U X a. REFS1:0 = 00: internal reference voltage OFF b. ADLAR = 0: align the result of ADC to the right c. MUX4:0 = 00000: use ADC channel 0 Line 13 14: we already know that the LCD module can display 8x2 characters in MA-VIN. It is the preparation process to display the desired character by clearing the first and second line of the LCD module. Now we have examined about the initialization function. The initialization function deals with the initial basic configurations of MA-VIN, which must be executed with the beginning of program simultaneously. M U X 3 M U X 2 M U X 1 M U X of 138

ET-BASE AVR ATmega64/128

ET-BASE AVR ATmega64/128 ET-BASE AVR ATmega64/128 ET-BASE AVR ATmega64/128 which is a Board Microcontroller AVR family from ATMEL uses MCU No.ATmega64 and ATmega128 64PIN. Board ET-BASE AVR ATmega64/128 uses MCU s resources on

More information

Microtronics technologies Mobile: 99707 90092

Microtronics technologies Mobile: 99707 90092 For more Project details visit: http://www.projectsof8051.com/rfid-based-attendance-management-system/ Code Project Title 1500 RFid Based Attendance System Synopsis for RFid Based Attendance System 1.

More information

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc. SKP16C62P Tutorial 1 Software Development Process using HEW Renesas Technology America Inc. 1 Overview The following tutorial is a brief introduction on how to develop and debug programs using HEW (Highperformance

More information

Lab Experiment 1: The LPC 2148 Education Board

Lab Experiment 1: The LPC 2148 Education Board Lab Experiment 1: The LPC 2148 Education Board 1 Introduction The aim of this course ECE 425L is to help you understand and utilize the functionalities of ARM7TDMI LPC2148 microcontroller. To do that,

More information

STEPPER MOTOR SPEED AND POSITION CONTROL

STEPPER MOTOR SPEED AND POSITION CONTROL STEPPER MOTOR SPEED AND POSITION CONTROL Group 8: Subash Anigandla Hemanth Rachakonda Bala Subramanyam Yannam Sri Divya Krovvidi Instructor: Dr. Jens - Peter Kaps ECE 511 Microprocessors Fall Semester

More information

Embedded Systems on ARM Cortex-M3 (4weeks/45hrs)

Embedded Systems on ARM Cortex-M3 (4weeks/45hrs) Embedded Systems on ARM Cortex-M3 (4weeks/45hrs) Course & Kit Contents LEARN HOW TO: Use of Keil Real View for ARM Use ARM Cortex-M3 MCU for professional embedded application development Understanding

More information

The Programming Interface

The Programming Interface : In-System Programming Features Program any AVR MCU In-System Reprogram both data Flash and parameter EEPROM memories Eliminate sockets Simple -wire SPI programming interface Introduction In-System programming

More information

Location-Aware and Safer Cards: Enhancing RFID Security and Privacy

Location-Aware and Safer Cards: Enhancing RFID Security and Privacy Location-Aware and Safer Cards: Enhancing RFID Security and Privacy 1 K.Anudeep, 2 Mrs. T.V.Anantha Lakshmi 1 Student, 2 Assistant Professor ECE Department, SRM University, Kattankulathur-603203 1 [email protected],

More information

2.0 Command and Data Handling Subsystem

2.0 Command and Data Handling Subsystem 2.0 Command and Data Handling Subsystem The Command and Data Handling Subsystem is the brain of the whole autonomous CubeSat. The C&DH system consists of an Onboard Computer, OBC, which controls the operation

More information

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide

Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide Data Acquisition Module with I2C interface «I2C-FLEXEL» User s Guide Sensors LCD Real Time Clock/ Calendar DC Motors Buzzer LED dimming Relay control I2C-FLEXEL PS2 Keyboards Servo Motors IR Remote Control

More information

Atmel Norway 2005. XMEGA Introduction

Atmel Norway 2005. XMEGA Introduction Atmel Norway 005 XMEGA Introduction XMEGA XMEGA targets Leadership on Peripheral Performance Leadership in Low Power Consumption Extending AVR market reach XMEGA AVR family 44-100 pin packages 16K 51K

More information

8051 MICROCONTROLLER COURSE

8051 MICROCONTROLLER COURSE 8051 MICROCONTROLLER COURSE Objective: 1. Familiarization with different types of Microcontroller 2. To know 8051 microcontroller in detail 3. Programming and Interfacing 8051 microcontroller Prerequisites:

More information

Display Message on Notice Board using GSM

Display Message on Notice Board using GSM Advance in Electronic and Electric Engineering. ISSN 2231-1297, Volume 3, Number 7 (2013), pp. 827-832 Research India Publications http://www.ripublication.com/aeee.htm Display Message on Notice Board

More information

EvB 5.1 v5 User s Guide

EvB 5.1 v5 User s Guide EvB 5.1 v5 User s Guide Page 1 Contents Introduction... 4 The EvB 5.1 v5 kit... 5 Power supply...6 Programmer s connector...7 USB Port... 8 RS485 Port...9 LED's...10 Pushbuttons... 11 Potentiometers and

More information

A 5 Degree Feedback Control Robotic Arm (Haptic Arm)

A 5 Degree Feedback Control Robotic Arm (Haptic Arm) A 5 Degree Feedback Control Robotic Arm (Haptic Arm) 1 Prof. Sheetal Nirve, 2 Mr.Abhilash Patil, 3 Mr.Shailesh Patil, 4 Mr.Vishal Raut Abstract: Haptics is the science of applying touch sensation and control

More information

Cell Phone Operated Land Rover

Cell Phone Operated Land Rover Cell Phone Operated Land Rover Sumona Biswas, Bipin Kumar, Aditya kushwaha, Debasish Sardar Department of Electronics and Communication Engineering, Birbhum Institute of Engineering& Technology, Suri(west

More information

GPS & GSM BASED REAL-TIME VEHICLE TRACKING SYSTEM.

GPS & GSM BASED REAL-TIME VEHICLE TRACKING SYSTEM. GPS & GSM BASED REAL-TIME VEHICLE TRACKING SYSTEM. Introduction: The Proposed design is cost-effective, reliable and has the function of accurate tracking. When large object or vehicles were spread out

More information

Lecture N -1- PHYS 3330. Microcontrollers

Lecture N -1- PHYS 3330. Microcontrollers Lecture N -1- PHYS 3330 Microcontrollers If you need more than a handful of logic gates to accomplish the task at hand, you likely should use a microcontroller instead of discrete logic gates 1. Microcontrollers

More information

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example

Microcontroller Systems. ELET 3232 Topic 8: Slot Machine Example Microcontroller Systems ELET 3232 Topic 8: Slot Machine Example 1 Agenda We will work through a complete example Use CodeVision and AVR Studio Discuss a few creative instructions Discuss #define and #include

More information

MICROPROCESSOR. Exclusive for IACE Students www.iace.co.in iacehyd.blogspot.in Ph: 9700077455/422 Page 1

MICROPROCESSOR. Exclusive for IACE Students www.iace.co.in iacehyd.blogspot.in Ph: 9700077455/422 Page 1 MICROPROCESSOR A microprocessor incorporates the functions of a computer s central processing unit (CPU) on a single Integrated (IC), or at most a few integrated circuit. It is a multipurpose, programmable

More information

Using Arduino Microcontrollers to Sense DC Motor Speed and Position

Using Arduino Microcontrollers to Sense DC Motor Speed and Position ECE480 Design Team 3 Using Arduino Microcontrollers to Sense DC Motor Speed and Position Tom Manner April 4, 2011 page 1 of 7 Table of Contents 1. Introduction ----------------------------------------------------------

More information

An Introduction to MPLAB Integrated Development Environment

An Introduction to MPLAB Integrated Development Environment An Introduction to MPLAB Integrated Development Environment 2004 Microchip Technology Incorporated An introduction to MPLAB Integrated Development Environment Slide 1 This seminar is an introduction to

More information

DS1104 R&D Controller Board

DS1104 R&D Controller Board DS1104 R&D Controller Board Cost-effective system for controller development Highlights Single-board system with real-time hardware and comprehensive I/O Cost-effective PCI hardware for use in PCs Application

More information

INTRODUCTION TO SERIAL ARM

INTRODUCTION TO SERIAL ARM INTRODUCTION TO SERIAL ARM A robot manipulator consists of links connected by joints. The links of the manipulator can be considered to form a kinematic chain. The business end of the kinematic chain of

More information

TURBO PROGRAMMER USB, MMC, SIM DEVELOPMENT KIT

TURBO PROGRAMMER USB, MMC, SIM DEVELOPMENT KIT TURBO PROGRAMMER USB, MMC, SIM DEVELOPMENT KIT HARDWARE GUIDE This document is part of Turbo Programmer documentation. For Developer Documentation, Applications and Examples, see http:/// PRELIMINARY (C)

More information

EXPERIMENT 2 TRAFFIC LIGHT CONTROL SYSTEM FOR AN INTERSECTION USING S7-300 PLC

EXPERIMENT 2 TRAFFIC LIGHT CONTROL SYSTEM FOR AN INTERSECTION USING S7-300 PLC YEDITEPE UNIVERSITY ENGINEERING & ARCHITECTURE FACULTY INDUSTRIAL ELECTRONICS LABORATORY EE 432 INDUSTRIAL ELECTRONICS EXPERIMENT 2 TRAFFIC LIGHT CONTROL SYSTEM FOR AN INTERSECTION USING S7-300 PLC Introduction:

More information

Von der Hardware zur Software in FPGAs mit Embedded Prozessoren. Alexander Hahn Senior Field Application Engineer Lattice Semiconductor

Von der Hardware zur Software in FPGAs mit Embedded Prozessoren. Alexander Hahn Senior Field Application Engineer Lattice Semiconductor Von der Hardware zur Software in FPGAs mit Embedded Prozessoren Alexander Hahn Senior Field Application Engineer Lattice Semiconductor AGENDA Overview Mico32 Embedded Processor Development Tool Chain HW/SW

More information

Controlling a Dot Matrix LED Display with a Microcontroller

Controlling a Dot Matrix LED Display with a Microcontroller Controlling a Dot Matrix LED Display with a Microcontroller By Matt Stabile and programming will be explained in general terms as well to allow for adaptation to any comparable microcontroller or LED matrix.

More information

Accurate Measurement of the Mains Electricity Frequency

Accurate Measurement of the Mains Electricity Frequency Accurate Measurement of the Mains Electricity Frequency Dogan Ibrahim Near East University, Faculty of Engineering, Lefkosa, TRNC [email protected] Abstract The frequency of the mains electricity supply

More information

AVR Butterfly Training. Atmel Norway, AVR Applications Group

AVR Butterfly Training. Atmel Norway, AVR Applications Group AVR Butterfly Training Atmel Norway, AVR Applications Group 1 Table of Contents INTRODUCTION...3 GETTING STARTED...4 REQUIRED SOFTWARE AND HARDWARE...4 SETTING UP THE HARDWARE...4 SETTING UP THE SOFTWARE...5

More information

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II Administration: o Prayer PicBasic Pro Programs Used in This Lesson: o General PicBasic Pro Program

More information

Module 2. Embedded Processors and Memory. Version 2 EE IIT, Kharagpur 1

Module 2. Embedded Processors and Memory. Version 2 EE IIT, Kharagpur 1 Module 2 Embedded Processors and Memory Version 2 EE IIT, Kharagpur 1 Lesson 5 Memory-I Version 2 EE IIT, Kharagpur 2 Instructional Objectives After going through this lesson the student would Pre-Requisite

More information

Chapter 13. PIC Family Microcontroller

Chapter 13. PIC Family Microcontroller Chapter 13 PIC Family Microcontroller Lesson 01 PIC Characteristics and Examples PIC microcontroller characteristics Power-on reset Brown out reset Simplified instruction set High speed execution Up to

More information

WIZ-Embedded WebServer User s Manual (Ver. 1.0)

WIZ-Embedded WebServer User s Manual (Ver. 1.0) [텍스트 입력] WIZ-Embedded WebServer User s Manual (Ver. 1.0) 2007 WIZnet Inc. All Rights Reserved. For more information, visit our website at www.wiznet.co.kr Document History Information Revision Data Description

More information

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT

PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT PROJECT PRESENTATION ON CELLPHONE OPERATED ROBOTIC ASSISTANT ELECTRONICS ENGINEERING DEPARTMENT SVNIT, SURAT-395007, INDIA Prepared by: Anurag Gupta (U05EC401) Dhrumeel Bakshi (U05EC326) Dileep Dhakal

More information

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16

Why using ATmega16? University of Wollongong Australia. 7.1 Overview of ATmega16. Overview of ATmega16 s schedule Lecture 7 - C Programming for the Atmel AVR School of Electrical, l Computer and Telecommunications i Engineering i University of Wollongong Australia Week Lecture (2h) Tutorial (1h) Lab (2h)

More information

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features.

APPLICATION NOTE. Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor. Atmel AVR 8-bit Microcontrollers. Features. APPLICATION NOTE Features Atmel AVR443: Sensor-based Control of Three Phase Brushless DC Motor Less than 5µs response time on Hall sensor output change Theoretical maximum of 1600k RPM Over-current sensing

More information

PolyBot Board. User's Guide V1.11 9/20/08

PolyBot Board. User's Guide V1.11 9/20/08 PolyBot Board User's Guide V1.11 9/20/08 PolyBot Board v1.1 16 pin LCD connector 4-pin SPI port (can be used as digital I/O) 10 Analog inputs +5V GND GND JP_PWR 3-pin logic power jumper (short top 2 pins

More information

Serial Communications

Serial Communications Serial Communications 1 Serial Communication Introduction Serial communication buses Asynchronous and synchronous communication UART block diagram UART clock requirements Programming the UARTs Operation

More information

MC433 Stepper Motor Controller

MC433 Stepper Motor Controller MC433 Stepper Motor Controller 4 Axis, 10A PWM Hardware Reference Guide PCB Rev 1.1,1.1b MC433 Rev 1-1(b) Hardware Reference Guide Manual Revision 0.95 Warranty Statement SOC Robotics warrants that the

More information

Chapter 6. Inside the System Unit. What You Will Learn... Computers Are Your Future. What You Will Learn... Describing Hardware Performance

Chapter 6. Inside the System Unit. What You Will Learn... Computers Are Your Future. What You Will Learn... Describing Hardware Performance What You Will Learn... Computers Are Your Future Chapter 6 Understand how computers represent data Understand the measurements used to describe data transfer rates and data storage capacity List the components

More information

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester

Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester Leonardo Journal of Sciences ISSN 1583-0233 Issue 20, January-June 2012 p. 31-36 Microcontroller Based Low Cost Portable PC Mouse and Keyboard Tester Ganesh Sunil NHIVEKAR *, and Ravidra Ramchandra MUDHOLKAR

More information

How to read this guide

How to read this guide How to read this guide The following shows the symbols used in this Quick start guide with descriptions and examples. Symbol Description Example P oint Reference Caution [ ] This symbol explains information

More information

Interfacing Analog to Digital Data Converters

Interfacing Analog to Digital Data Converters Converters In most of the cases, the PIO 8255 is used for interfacing the analog to digital converters with microprocessor. We have already studied 8255 interfacing with 8086 as an I/O port, in previous

More information

Serial Communications

Serial Communications April 2014 7 Serial Communications Objectives - To be familiar with the USART (RS-232) protocol. - To be able to transfer data from PIC-PC, PC-PIC and PIC-PIC. - To test serial communications with virtual

More information

MICROPROCESSOR AND MICROCOMPUTER BASICS

MICROPROCESSOR AND MICROCOMPUTER BASICS Introduction MICROPROCESSOR AND MICROCOMPUTER BASICS At present there are many types and sizes of computers available. These computers are designed and constructed based on digital and Integrated Circuit

More information

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR

AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR AUTOMATIC NIGHT LAMP WITH MORNING ALARM USING MICROPROCESSOR INTRODUCTION This Project "Automatic Night Lamp with Morning Alarm" was developed using Microprocessor. It is the Heart of the system. The sensors

More information

STK500... User Guide

STK500... User Guide STK500... User Guide Table of Contents Section 1 Introduction... 1-1 1.1 Starter Kit Features...1-1 1.2 Device Support...1-2 Section 2 Getting Started... 2-1 2.1 Unpacking the System...2-1 2.2 System

More information

TX GSM SMS Auto-dial Alarm System. Installation and User Manual

TX GSM SMS Auto-dial Alarm System. Installation and User Manual TX GSM SMS Auto-dial Alarm System Installation and User Manual Product Features: 1. 16 wireless zones, 3 wired zones alarm system, suitable for small to medium size offices and homes. 2. The system uses

More information

DeviceNet Bus Software Help for Programming an Allen Bradley Control System

DeviceNet Bus Software Help for Programming an Allen Bradley Control System FBP FieldBusPlug V7 DeviceNet Bus Software Help for Programming an Allen Bradley Control System DeviceNet Software Help for Programming an Allen Bradley Control System Contents Page General Purpose...

More information

Access Control Using Smartcard And Passcode

Access Control Using Smartcard And Passcode IOSR Journal of Electrical and Electronics Engineering (IOSR-JEEE) e-issn: 2278-1676 Volume 4, Issue 5 (Jan. - Feb. 2013), PP 29-34 Access Control Using Smartcard And Passcode Omorogiuwa Eseosa 1., Uhunmwangho

More information

Handout 17. by Dr Sheikh Sharif Iqbal. Memory Unit and Read Only Memories

Handout 17. by Dr Sheikh Sharif Iqbal. Memory Unit and Read Only Memories Handout 17 by Dr Sheikh Sharif Iqbal Memory Unit and Read Only Memories Objective: - To discuss different types of memories used in 80x86 systems for storing digital information. - To learn the electronic

More information

Micro-Step Driving for Stepper Motors: A Case Study

Micro-Step Driving for Stepper Motors: A Case Study Micro-Step Driving for Stepper Motors: A Case Study N. Sedaghati-Mokhtari Graduate Student, School of ECE, University of Tehran, Tehran, Iran n.sedaghati @ece.ut.ac.ir Abstract: In this paper, a case study

More information

Firmware version: 1.10 Issue: 7 AUTODIALER GD30.2. Instruction Manual

Firmware version: 1.10 Issue: 7 AUTODIALER GD30.2. Instruction Manual Firmware version: 1.10 Issue: 7 AUTODIALER GD30.2 Instruction Manual Firmware version: 2.0.1 Issue: 0.6 Version of the GPRS transmitters configurator: 1.3.6.3 Date of issue: 07.03.2012 TABLE OF CONTENTS

More information

Serial port interface for microcontroller embedded into integrated power meter

Serial port interface for microcontroller embedded into integrated power meter Serial port interface for microcontroller embedded into integrated power meter Mr. Borisav Jovanović, Prof. dr. Predrag Petković, Prof. dr. Milunka Damnjanović, Faculty of Electronic Engineering Nis, Serbia

More information

DESIGN OF SMS ENABLED CAR SECURITY SYSTEM

DESIGN OF SMS ENABLED CAR SECURITY SYSTEM DESIGN OF SMS ENABLED CAR SECURITY SYSTEM K. A. Amusa Federal University of Agriculture, Abeokuta, O. O. Nuga Federal University of Agriculture, Abeokuta, A. A. Adetomi Federal University of Agriculture,

More information

Freescale Semiconductor, Inc. Product Brief Integrated Portable System Processor DragonBall ΤΜ

Freescale Semiconductor, Inc. Product Brief Integrated Portable System Processor DragonBall ΤΜ nc. Order this document by MC68328/D Microprocessor and Memory Technologies Group MC68328 MC68328V Product Brief Integrated Portable System Processor DragonBall ΤΜ As the portable consumer market grows

More information

Computer Organization and Components

Computer Organization and Components Computer Organization and Components IS1500, fall 2015 Lecture 5: I/O Systems, part I Associate Professor, KTH Royal Institute of Technology Assistant Research Engineer, University of California, Berkeley

More information

AC-PG-USBASP USBASP AVR Programmer

AC-PG-USBASP USBASP AVR Programmer AC-PG-USBASP-UG TABLE OF CONTENTS 1. OVERVIEW... 1 1.1. Introduction... 1 1.2. References... 1 1.2.1. Referenced Web Pages... 1 1.2.2. Acronyms and Abbreviations... 1 1.3. Supported Microcontrollers...

More information

Computer Automation Techniques. Arthur Carroll

Computer Automation Techniques. Arthur Carroll Computer Automation Techniques Arthur Carroll 1 Three Types of Computers Micro-Controller Single Board Computer Desktop Computer 2 The Micro-Controller Small inexpensive DIP or surface mount chips Roughly

More information

Design of an Insulin Pump. Purpose of an Insulin Pump:

Design of an Insulin Pump. Purpose of an Insulin Pump: Design of an Insulin Pump Purpose of an Insulin Pump: Insulin is a hormone central to regulating carbohydrate and fat metabolism in the body. It is secreted regularly within the body and aids in converting

More information

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver

1. Learn about the 555 timer integrated circuit and applications 2. Apply the 555 timer to build an infrared (IR) transmitter and receiver Electronics Exercise 2: The 555 Timer and its Applications Mechatronics Instructional Laboratory Woodruff School of Mechanical Engineering Georgia Institute of Technology Lab Director: I. Charles Ume,

More information

Implementing a Digital Answering Machine with a High-Speed 8-Bit Microcontroller

Implementing a Digital Answering Machine with a High-Speed 8-Bit Microcontroller Implementing a Digital Answering Machine with a High-Speed 8-Bit Microcontroller Zafar Ullah Senior Application Engineer Scenix Semiconductor Inc. Leo Petropoulos Application Manager Invox TEchnology 1.0

More information

BE635 User Manual. Rev. V1.0. 2013-2014 Bolymin, Inc. All Rights Reserved.

BE635 User Manual. Rev. V1.0. 2013-2014 Bolymin, Inc. All Rights Reserved. BE635 User Manual Rev. V1.0 2013-2014 Bolymin, Inc. All Rights Reserved. Copyright Copyright 2013-2014 BOLYMIN, INC. All rights reserved. No part of the materials may be reproduced, copied or translated

More information

Microcontrollers in Practice

Microcontrollers in Practice M. Mitescu I. Susnea Microcontrollers in Practice With 117 Figures, 34 Tables and CD-Rom 4y Springer Contents Resources of Microcontrollers, 1 1.1 In this Chapter 1 1.2 Microcontroller Architectures 1

More information

Inwall Room Temperature Unit

Inwall Room Temperature Unit Inwall Room Temperature Unit TM11B01KNX TM11B11KNX TM11B21KNX Product Handbook Product: Inwall Room Temperature Unit Order Code: TM11B01KNX TM11B11KNX TM11B21KNX Application Program ETS: TM11B_1KNX Inwall

More information

Logical Operations. Control Unit. Contents. Arithmetic Operations. Objectives. The Central Processing Unit: Arithmetic / Logic Unit.

Logical Operations. Control Unit. Contents. Arithmetic Operations. Objectives. The Central Processing Unit: Arithmetic / Logic Unit. Objectives The Central Processing Unit: What Goes on Inside the Computer Chapter 4 Identify the components of the central processing unit and how they work together and interact with memory Describe how

More information

RF CONTROLLED VEHICLE ROBOT WITH METAL DETECTOR

RF CONTROLLED VEHICLE ROBOT WITH METAL DETECTOR RF CONTROLLED VEHICLE ROBOT WITH METAL DETECTOR PAGE NO. 1. ABSTRACT 10 2. INTRODUCTION TO EMBEDDED SYSTEMS 13 3. BLOCK DIAGRAM OF PROJECT 4. HARDWARE REQUIREMENTS 4.1 VOLTAGE REGULATOR 4.2 MICROCONTROLLER

More information

Fondamenti su strumenti di sviluppo per microcontrollori PIC

Fondamenti su strumenti di sviluppo per microcontrollori PIC Fondamenti su strumenti di sviluppo per microcontrollori PIC MPSIM ICE 2000 ICD 2 REAL ICE PICSTART Ad uso interno del corso Elettronica e Telecomunicazioni 1 2 MPLAB SIM /1 MPLAB SIM is a discrete-event

More information

Business/Home GSM Alarm System. Installation and User Manual

Business/Home GSM Alarm System. Installation and User Manual Business/Home GSM Alarm System Installation and User Manual Brief Introduction: GSM 900/1800/1900 bands, can be used in most parts of the world Full duplex communication with the host Monitor the scene

More information

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module

Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module Display Board Pulse Width Modulation (PWM) Power/Speed Controller Module RS0 Microcontroller LEDs Motor Control Pushbuttons Purpose: To demonstrate an easy way of using a Freescale RS0K2 microcontroller

More information

Computer Systems Structure Main Memory Organization

Computer Systems Structure Main Memory Organization Computer Systems Structure Main Memory Organization Peripherals Computer Central Processing Unit Main Memory Computer Systems Interconnection Communication lines Input Output Ward 1 Ward 2 Storage/Memory

More information

HD44780-Based LCD Modules. Introduction to the LM018L

HD44780-Based LCD Modules. Introduction to the LM018L HD44780-Based LCD Modules Hitachi LM018L 40 character x 2 lines Built-in LSI HD44780 controller +5volt single power supply Display Colour: Grey LM018L: Introduction Interfacing Display Pattern and Character

More information

MARTECH SPI Tools. MARTECH SPI Tools User Manual v1.0. User Manual

MARTECH SPI Tools. MARTECH SPI Tools User Manual v1.0. User Manual MARTECH SPI Tools v1.0 Contents 1. Basic informations about the product...3 1.1 Memory types supported by SPI Tool...3 2. Main features and application possibilities...4 2.1 Technical Support activation...4

More information

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK

User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK User s Manual of Board Microcontroller ET-MEGA2560-ADK ET-MEGA2560-ADK Because Arduino that is the development project on AVR MCU as Open Source has been published, it is popular and widespread shortly.

More information

Allows the user to protect against inadvertent write operations. Device select and address bytes are Acknowledged Data Bytes are not Acknowledged

Allows the user to protect against inadvertent write operations. Device select and address bytes are Acknowledged Data Bytes are not Acknowledged Write Protect CAT24WCxxx I 2 C Serial EEPROMs. Allows the user to protect against inadvertent write operations. WP = V CC : Write Protected Device select and address bytes are Acknowledged Data Bytes are

More information

8051 hardware summary

8051 hardware summary 8051 hardware summary 8051 block diagram 8051 pinouts + 5V ports port 0 port 1 port 2 port 3 : dual-purpose (general-purpose, external memory address and data) : dedicated (interfacing to external devices)

More information

Palaparthi.Jagadeesh Chand. Associate Professor in ECE Department, Nimra Institute of Science & Technology, Vijayawada, A.P.

Palaparthi.Jagadeesh Chand. Associate Professor in ECE Department, Nimra Institute of Science & Technology, Vijayawada, A.P. Patient Monitoring Using Embedded Palaparthi.Jagadeesh Chand Associate Professor in ECE Department, Nimra Institute of Science & Technology, Vijayawada, A.P Abstract The aim of this project is to inform

More information

INTRODUCTION: ABSTRACT:

INTRODUCTION: ABSTRACT: INDUSTRIAL INTELLIGENT LINE FOLLOWER ROBOT WITH AUTO GO DOWN DETECTION, AUTO OBSTACLES DETECTION, WIRELESS VEHICLE STATUS DATA TRANFER TO SERVER AND MANY MORE FEATURES INTRODUCTION: This project is based

More information

Home Security System Using Gsm Modem

Home Security System Using Gsm Modem RESEARCH ARTICLE OPEN ACCESS Home Security System Using Gsm Modem Mehek Potnis 1, Ayesha Chimnani 1, Vishal Chawla 1 Mr. Amit Hatekar 2 1. Undergraduate Students, Department of EXTC, Thadomal Shahani Engineering

More information

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation.

8-bit Microcontroller. Application Note. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer. Features. Theory of Operation. AVR134: Real-Time Clock (RTC) using the Asynchronous Timer Features Real-Time Clock with Very Low Power Consumption (4µA @ 3.3V) Very Low Cost Solution Adjustable Prescaler to Adjust Precision Counts Time,

More information

Mobile Operated Landrover Using Dtmf Decoder

Mobile Operated Landrover Using Dtmf Decoder Vol.3, Issue.2, March-April. 2013 pp-898-902 ISSN: 2249-6645 K.Aruna, 1 A.Sri Ramsagar, 2 G.Venkateswarlu 3 Department of Electronics and Communication Engineering, Bapatla Engineering College, Bapatla,

More information

Thermostat Application Module Kit

Thermostat Application Module Kit Thermostat Application Module Kit PUG0040-00 Product User Guide Kit Contents Overview Thermostat Application Module CD-ROM: Software Examples and Documentation The Thermostat Application Module provides

More information

Arduino Motor Shield (L298) Manual

Arduino Motor Shield (L298) Manual Arduino Motor Shield (L298) Manual This DFRobot L298 DC motor driver shield uses LG high power H-bridge driver Chip L298P, which is able to drive DC motor, two-phase or four phase stepper motor with a

More information

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE

AT15007: Differences between ATmega328/P and ATmega328PB. Introduction. Features. Atmel AVR 8-bit Microcontrollers APPLICATION NOTE Atmel AVR 8-bit Microcontrollers AT15007: Differences between ATmega328/P and ATmega328PB APPLICATION NOTE Introduction This application note assists the users of Atmel ATmega328 variants to understand

More information

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai 2007. Jens Onno Krah

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai 2007. Jens Onno Krah (DSF) Soft Core Prozessor NIOS II Stand Mai 2007 Jens Onno Krah Cologne University of Applied Sciences www.fh-koeln.de [email protected] NIOS II 1 1 What is Nios II? Altera s Second Generation

More information

Tutorial for MPLAB Starter Kit for PIC18F

Tutorial for MPLAB Starter Kit for PIC18F Tutorial for MPLAB Starter Kit for PIC18F 2006 Microchip Technology Incorporated. All Rights Reserved. WebSeminar Title Slide 1 Welcome to the tutorial for the MPLAB Starter Kit for PIC18F. My name is

More information

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V]

[F/T] [5] [KHz] [AMP] [3] [V] 4 ) To set DC offset to -2.5V press the following keys [OFS] [+/-] [2] [.] [5] [V] FG085 minidds Function Generator Manual of Operation Applicable Models: 08501, 08501K, 08502K, 08503, 08503K Applicable Firmware Version: 1 ) 113-08501-100 or later (for U5) 2 ) 113-08502-030 or later

More information

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram

PC Base Adapter Daughter Card UART GPIO. Figure 1. ToolStick Development Platform Block Diagram TOOLSTICK VIRTUAL TOOLS USER S GUIDE RELEVANT DEVICES 1. Introduction The ToolStick development platform consists of a ToolStick Base Adapter and a ToolStick Daughter card. The ToolStick Virtual Tools

More information

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence : 0660-3

MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence : 0660-3 MODULE BOUSSOLE ÉLECTRONIQUE CMPS03 Référence : 0660-3 CMPS03 Magnetic Compass. Voltage : 5v only required Current : 20mA Typ. Resolution : 0.1 Degree Accuracy : 3-4 degrees approx. after calibration Output

More information

Guangzhou HC Information Technology Co., Ltd. Product Data Sheet

Guangzhou HC Information Technology Co., Ltd. Product Data Sheet Guangzhou HC Information Technology Co., Ltd. Product Data Sheet Rev 1 Module Data Sheet 1.0 2.0 2.1 2.2 2006/6/18 2006/9/6 2010/4/22 2011/4/6 DRAWN BY : Ling Xin MODEL : HC-06 CHECKED BY : Eric Huang

More information

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware

A+ Guide to Managing and Maintaining Your PC, 7e. Chapter 1 Introducing Hardware A+ Guide to Managing and Maintaining Your PC, 7e Chapter 1 Introducing Hardware Objectives Learn that a computer requires both hardware and software to work Learn about the many different hardware components

More information

Android Controlled Based Interface

Android Controlled Based Interface Android Controlled Based Interface Objective Fix Foba Build Rofi (Fifth Generation Robot) Develop, Build, and Implement a Dynamic Balanced Biped Robot Table of Contents Objective... 1 Android Controlled

More information

How to design an insulin pump

How to design an insulin pump How to design an insulin pump Learn about the purpose of an insulin pump, its overall workings, and the requirements needed for its design as well as implementation. By Asha Ganesan Applications Engineer

More information

GSM Interfacing Board

GSM Interfacing Board Campus Component Pvt. Ltd. DISCLAIMER Information furnished is believed to be accurate and reliable at the time of publication. However, Campus Component Pvt. Ltd. assumes no responsibility arising from

More information

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA

8-Bit Flash Microcontroller for Smart Cards. AT89SCXXXXA Summary. Features. Description. Complete datasheet available under NDA Features Compatible with MCS-51 products On-chip Flash Program Memory Endurance: 1,000 Write/Erase Cycles On-chip EEPROM Data Memory Endurance: 100,000 Write/Erase Cycles 512 x 8-bit RAM ISO 7816 I/O Port

More information

POCKET SCOPE 2. The idea 2. Design criteria 3

POCKET SCOPE 2. The idea 2. Design criteria 3 POCKET SCOPE 2 The idea 2 Design criteria 3 Microcontroller requirements 3 The microcontroller must have speed. 3 The microcontroller must have RAM. 3 The microcontroller must have secure Flash. 3 The

More information

Table 1 Comparison of DC, Uni-Polar and Bi-polar Stepper Motors

Table 1 Comparison of DC, Uni-Polar and Bi-polar Stepper Motors Electronics Exercise 3: Uni-Polar Stepper Motor Controller / Driver Mechatronics Instructional Laboratory Woodruff School of Mechanical Engineering Georgia Institute of Technology Lab Director: I. Charles

More information

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB

Block 3 Size 0 KB 0 KB 16KB 32KB. Start Address N/A N/A F4000H F0000H. Start Address FA000H F8000H F8000H F8000H. Block 2 Size 8KB 16KB 16KB 16KB APPLICATION NOTE M16C/26 1.0 Abstract The following article describes using a synchronous serial port and the FoUSB (Flash-over-USB ) Programmer application to program the user flash memory of the M16C/26

More information

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC6504 - Microprocessor & Microcontroller Year/Sem : II/IV

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC6504 - Microprocessor & Microcontroller Year/Sem : II/IV DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Question Bank Subject Name: EC6504 - Microprocessor & Microcontroller Year/Sem : II/IV UNIT I THE 8086 MICROPROCESSOR 1. What is the purpose of segment registers

More information