+ All Categories
Home > Documents > Embedded Systems

Embedded Systems

Date post: 25-Nov-2015
Category:
Upload: pranay-shree
View: 18 times
Download: 0 times
Share this document with a friend
Description:
its a trainning report on avr micro controller
Popular Tags:
49
EMBEDDED SYSTEMS WITH AVR A Training report submitted in partial fulfillment of the requirements for the award of the degree of ELECTRONICS AND COMUNICATION BACHELOR OF THECHNOLOGY BY PRANAY SHREE REGISTRATION NO. 11006736 LOVELY PROFESSIONAL UNIVERSITY PHAGWARA, PUNJAB , 144402, INDIA 1
Transcript

EMBEDDED SYSTEMS WITH AVR

A Training report submitted in partial fulfillment of the requirements for the award of the degree of ELECTRONICS AND COMUNICATION BACHELOR OF THECHNOLOGY

BY PRANAY SHREE REGISTRATION NO. 11006736

LOVELY PROFESSIONAL UNIVERSITY PHAGWARA, PUNJAB , 144402, INDIA 2013

DECLRATION

I hereby declare that I have completed my six weeks summer training at Riscin Technologies pvt ltd from 3 june to 14 july under the guidance of Mr. Vichitra kumar .I have worked with full dedication during these six weeks and my learning outcomes fulfill the requirements of training.

(signature of student) Name of student Pranay shree Registration no.11006736 Date :5 August 2013

OBJECTIVE OF TRIANING 1. Main objective of the training was to interface Avr microcontroller with Lcd , Led, switches etc.2. Programming section in C language to interface the different electronic devices.3. Advantage and disadvantage of Avr and other CPU.

RESULT :-By this training session , I could learn the basic of the subject and able to learn the future scope of the Embedded system . learnt about the up coming personality those helped India to boost in Embedded system like Pranav Mistry, research and development director in Samsung.

Last but not the least I could able to learn engineering behavior in industry.Conclision :-1. better knowledge of subject.2. Enhanced professional behavior.3. Eager to learn more version of microcontroller like Pic etc.

TABLE OF CONTENT

SERIAL NO.TITLEPAGE NO.

1.LIST OF TABLE

2.LIST OF FIGURES

3.CHAPTER 1 INTODUCTION1

4.CHAPTER 2 COMPANY OVERVIEW18

5.CHAPTER3 IDENTIFICATION OF TRAINNIG20

6.CHAPTER4IMPLEMENTION DETAILS25

Acknowledgement

It is a great pleasure and matter of immense satisfaction for me to represent the dissertation of my training report.

I am highly indebted RISCIN TECHNOLOGIES PVT LTD , for letting us undertake in their company for training.

I specially thanks to Mr. Vichitra kumar for providing me with such learning atmosphere in RISCIN and support us whenever we needed help at every point of my training.

CHAPTER 1 INTRODUCTIONEmbedded SystemAn embedded system is a special-purpose computer system, which is completely encapsulated by the device it controls. An embedded system has specific requirements and performs pre-defined tasks, unlike a general-purpose personal computer.An embedded system is a programmed hardware device. A programmable hardware chip is the 'raw material' and it is programmed with particular applications. This is to be understood in comparison to older systems with full functional hardware or systems with general purpose hardware and externally loaded software. Embedded systems are a combination of hardware and software which facilitates mass production and variety of application . A combination of computer hardware and software, and perhaps additional mechanical or other parts, designed to perform a dedicated function.In some cases, embedded systems are part of a larger system or product, as in the case of an anti lock braking system in a car.EMBEDDED SYSTEM is a combination of SOFTWARE and HARDWARE.An Embedded system is a system, that has a computing device embedded into it.These are the controllers, processors, arrays or other hardware using dedicated (embedded) logic or programming (code) called firmware or a microkernelEmbedded systems are designed around a C which integrates Memory & PeripheralsEmbedded systems:What are they?A special purpose computer built into a larger device Special-purposeEmbedded systems have a (more or less) well-defined purpose Contrast with: general purpose computers (PCs etc)Built into a larger device Embedded systems are (usually) part of a larger device, augmenting its capabilitiesWHY EMBEDDED SYSTEMSIt is EMBEDDED because the Micro Controller is inside some other system. For Example a Micro Controller is EMBEDDED into your TV, car, or appliance The consumer need not think about how to make it perform or processAvoids lots of Electronics Components Built in rich Features Reduces the cost, space Less Down Time for Maintenance Probability of Failure is reduced .Easy interface with ComputersCHARACTERISTICS OF AN EMBEDDED SYSTEMSophisticated functionalityReal-Time OperationLow Manufacturing CostLow Power ConsumptionEliminates Necessity of Complex CircuitrySmarter ProductsSmaller SizeUser Friendly

Four General Embedded Systems TypesGeneral Computing Applications similar to desktop computing, but in an embedded package Video games, set- top boxes, wearable computers, automatic tellersControl Systems Closed- loop feedback control of real- time system Vehicle engines, chemical processes, nuclear power, flight controlSignal Processing Computations involving large data streams Radar, Sonar, video compressionCommunication & Networking Switching and information transmission Telephone system, Internet

EMBEDDED SYSTEMS COMPONENTSMICRO CONTROLLERS (C)MICRO PROCESSORS (P)DIGITAL SIGNAL CONTROLLERS (DSC)DIGITAL SIGNAL PROCESSORS (DSP)BUSSES (Data, Address, Input/output)SYSTEM CLOCK - Steps C / P Through Each InstructionREAD ONLY MEMORY (ROM):Permanently Loaded With Instructions (FIRMWARE)RANDOM ACCESS MEMORY (RAM)STORES DATA IN PROCESSING / SHARES DATA WITHEXTERNAL PARTNERSREAL TIME CLOCK (RTC)COMMUNICATIONS CIRCUITRY - Ethernet Port, Printer Port, Communications Port (RS232, RS485, RS422)EXAMPLES OF EMBEDDED SYSTEMSAutomatic Teller Machines or ATM's & Bank Vaults Blue Tooth enabled Network Synchronization ApplicationControl Systems (Manufacturing, Cryogenics, Electric Power) Controls for Digital Equipment: CD Players, TV Remote,Programmable Sprinklers, Household Appliances, etc.Computer motherboards (BIOS chips, RTCs)Global Positioning and Navigation Systems Household Appliances Medical instruments controls - CT scanners, MRI Scanners, ECG,Pacemakers and implanted pumps, implanted heart monitors, etc. Supervisory Control and Data Acquisition (SCADA) systemsTelecommunications (Private Branch Exchanges, Custom Premises Equipment)

EMBEDDED - DESIGN METHODOLOGIESA procedure for designing a systemUnderstanding your methodology helps you ensure you didnt skipanything.Compilers, software engineering tools, computer-aided design (CAD)tools, etc., can be used to: help automate methodology steps;keep track of the methodology itself.EMBEDDED DESIGN GOALSOverall speed, deadlines. Performance.Overall speed, deadlines.Functionality and user interface.Manufacturing cost.Power consumption.Other requirements (physical size, etc.)EMBEDDED SYSTEMS - EARLY HISTORYLate 1940s: MIT Whirlwind computer was designed for real-time operations. Originally designed to control an aircraft simulator First microprocessor was Intel 4004 in early 1970s.HP-35 calculator used several chips to implement a microprocessor in 1972.Automobiles used microprocessor - based engine controllers starting in 1970s. Control fuel/air mixture, engine timing, etc. Multiple modes of operation: warm-up, cruise, hill climbing, etc.Provides lower emissions, better fuel efficiency.Reduced Instruction Set ComputerMicrocontroller operation is controlled by a user-written program interacting withthe fixed hardware architecture resident within the microcontroller. A specificmicrocontroller architecture can be categorized as accumulator-based, register-based, stack-based, or a pipeline architecture. The Atmel ATmega16 is a register-based architecture. In this type of architecture, both operands of an operation arestored in registers collocated with the central processing unit (CPU). This meansthat before an operation is performed, the computer loads all necessary data forthe operation to its CPU. The result of the operation is also stored in a register.During program execution, the CPU interacts with the register set and minimizesslower memory accesses. Memory accesses are typically handled as background operations.Coupled with the register-based architecture is an instruction set based on the RISC concept. A RISC processor is equipped with a complement of very simple and efficient basic operations. More complex instructions are built up from these very basic operations. This allows for efficient program operation. The Atmel ATmega16 is equipped with 131 RISC-type instructions. Most can be executedin a single clock cycle. The ATmega16 is also equipped with additional hardware to allow for the multiplication operation in two clock cycles. In many other microcontroller architectures, multiplication typically requires many more clock cycles. The Atmel ATmega16 is equipped with 32 general purpose 8-bit registersthat are tightly coupled to the processors arithmetic logic unit within the CPU.Also, the processor is designed following the Harvard Architecture format. That is, it is equipped with separate, dedicated memories and buses for program and data information. The register-based Harvard Architecture coupled with the RISC-based instruction set allows for fast and efficient program execution and allows the processor to complete an assembly language instruction every clock cycle. Atmel indicates the ATmega16 can execute 16 million instructions per second when operating at a clock speed of 16 MHz.AVR SERIES OF MICROCONTROLLERHistory of AVRAVR was developed in the year 1996 by Atmel Corporation. The architecture of AVR was developed by Alf-Egil Bogen and Vegard Wollan. AVR derives its name from its developers and stands for Alf-Egil Bogen Vegard Wollan RISC microcontroller, also known as Advanced Virtual RISC. The AT90S8515 was the first microcontroller which was based on AVR architecture however the first microcontroller to hit the commercial market was AT90S1200 in the year 1997.

Whats special about AVR?They are fast: AVR microcontroller executes most of the instructions in single execution cycle. AVRs are about 4 times faster than PICs, they consume less power and can be operated in different power saving modes. Lets do the comparison between the three most commonly used families of microcontrollers.Characteristics8051PICAVRAVR is an 8-bit microcontroller belonging to the family of Reduced Instruction Set Computer (RISC). In RISC architecture the instruction set of the computer are not only fewer in number but also simpler and faster in operation. The other type of categorization is CISC (Complex Instruction Set Computers).AVR microcontrollers are available in three categories:1.TinyAVR Less memory, small size, suitable only for simpler applications2. MegaAVR These are the most popular ones having good amount of memory (upto 256 KB), higher number of inbuilt peripherals and suitable for moderate to complex applications.3.XmegaAVR Used commercially for complex applications, which require large program memory and high speed

The ATtiny25/45/85 is a low-power CMOS 8-bit microcontroller based on theAVR enhanced RISC architecture. By executing powerful instructions in a singleclock cycle, the ATtiny25/45/85 achieves throughputs approaching 1 MIPS perMHz allowing the system designer to optimize power consumption versusprocessing speed.The ATtiny25/45/85 provides the following features: 2/4/8K bytes of In-System Programmable Flash, 128/256/512 bytes EEPROM, 128/256/256 bytes SRAM, 6 general purpose I/O lines, 32 general purpose working registers, one 8-bit Timer/Counter with compare modes, one 8-bit high speed Timer/Counter, Universal Serial Interface, Internal and External Interrupts, a 4-channel, 10-bit ADC, a programmable Watchdog Timer with internal Oscillator, and threesoftware selectable power saving modes. Idle mode stops the CPU while allowing the SRAM, Timer/Counter, ADC, Analog Comparator, and Interrupt system to continue functioning. Power-down mode saves the register con-tents, disabling all chip functions until the next Interrupt or Hardware Reset. ADC Noise Reduction mode stops the CPU and all I/O modules except ADC, to minimizeswitching noise during ADC conversions.

When your designs need some extra muscle, you need the megaAVR. Ideal for applications requiring large amounts of code, the megaAVR offers substantial program and data memories with performance up to 20 MIPS. Innovative picoPower technology minimizes power consumption. All megaAVRs offer self- programmability for fast, secure, cost-effective in-circuit upgrades You can even upgrade the flash while running your application.Based on industry-leading, proven technology, the megaAVR family offers our widest selection of devices in terms of memories, pin counts and peripherals.Choose from general-purpose devices to models with specialized peripherals like USB, or LCD controllers, or CAN, LIN and Power Stage Controllers. It's easy to find the perfect fit for your project in the megaAVR product family.Key FeaturesBroad family megaAVR offers our widest selection of devices in terms of memories, pin counts and peripherals, enabling reuse of code and knowledge across projects.Pico Power technology Selected megaAVR features ultra low power consumption and individually selectable low-power sleep modes that make it ideal for battery-powered applications. High integration The megaAVR features on-chip flash, SRAM, internal EEPROM, SPI, TWI, and USART, USB, CAN, and LIN, watchdog timer, a choice of internal or external precision oscillator,and general purpose I/O pins,simplifying your design and reducing bill-of-materials.Analog functions Advanced analog capabilities, such as ADC, DAC, built-in temperature sensor and internal voltage reference, brown out detector, a fast analog comparator and a programmable analog gain amplifier. The high level of integration allows designs with fewer external analog components. Rapid developmentmegaAVR microcontrollers speed development with powerful in-system programming and on-chip debug. In addition, in-system programming simplifies production line programming and field upgrades.Some Mega series controller are:Atmega8, Atmega16, Atmega32, Atmega64, Atmega128, Atmega640,Atmega1280.In our journey with the AVR we will be working on Atmega16 microcontroller, which is a 40-pin IC and belongs to the megaAVR category of AVR family. Some of the features of Atmega16 are:16KB of Flash memory1KB of SRAM512 Bytes of EEPROMAvailable in 40-Pin DIP8-Channel 10-bit ADCTwo 8-bit Timers/CountersOne 16-bit Timer/Counter4 PWM ChannelsIn System Programmer (ISP)Serial USARTSPI InterfaceDigital to Analog Comparator.Architecture of AVRThe AVR microcontrollers are based on the advanced RISC architecture and consist of 32 x 8-bit general purpose working registers. Within one single clock cycle, AVR can take inputs from two general purpose registers and put them to ALU for carrying out the requested operation, and transfer back the result to an arbitrary register. The ALU can perform arithmetic as well as logical operations over the inputs from the register or between the register and a constant. Single register operations like taking a complement can also be executed in ALU. We can see that AVR does not have any register like accumulator as in 8051 family of microcontrollers; the operations can be performed between any of the registers and can be stored in either of them.AVR follows Harvard Architecture format in which the processor is equippedwith separate memories and buses for Program and the Data information. Here while an instruction is being executed, the next instruction is pre-fetched from the program memory.Since AVR can perform single cycle execution, it means that AVcan execute 1 million instructions per second if cycle frequency is 1MHz. The higher is the operating frequency of the controller, the higher will be its processing speed. We need to optimize the power consumption with processing speed and hence need to select the operating frequency accordingly.There are two flavours for Atmega16 microcontroller:1.Atmega16:- Operating frequency range is 0 16 MHz.2.Atmega16L:- Operating frequency range is 0 8 MHz.If we are using a crystal of 8 MHz = 8 x 10^6 Hertz = 8 Million cycles, then AVRcan execute 8 million instructions.Naming Convention.!The AT refers to Atmel the manufacturer, Mega means that the microcontroller belong to MegaAVR category, 16 signifies the memory of the controller, which is 16KB.

Naming Convention of ATmega16 - AVR FamilyI/O Ports: Atmega16 has four (PORTA, PORTB, PORTC and PORTD) 8-bitinput-output ports.Internal Calibrated Oscillator: Atmega16 is equipped with an internaloscillator for driving its clock. By default Atmega16 is set to operate at internalcalibrated oscillator of 1 MHz. The maximum frequency of internal oscillator is8Mhz. Alternatively, ATmega16 can be operated using an external crystaloscillator with a maximum frequency of 16MHz. In this case you need to modifythe fuse bits. (Fuse Bits will be explained in a separate tutorial).Architecture of ATmega16 - AVR MicrocontrollersADC Interface: Atmega16 is equipped with an 8 channel ADC (Analog toDigital Converter) with a resolution of 10-bits. ADC reads the analog input fore.g., a sensor input and converts it into digital information which isunderstandable by the microcontroller.Timers/Counters:Atmega16 consists of two 8-bit and one 16-bit timer/counter.Timers are useful for generating precision actions for e.g., creating time delaysbetween two operations.RISCIN TECHNOLOGIES PVT. LTDEMBEDDED SYSTEM WITH AVR14 | P a g eWatchdog Timer:Watchdog timer is present with internal oscillator. Watchdogtimer continuously monitors and resets the controller if the code gets stuck at anyexecution action for more than a defined time interval.Interrupts:Atmega16 consists of 21 interrupt sources out of which four areexternal. The remaining are internal interrupts which support the peripherals likeUSART, ADC, Timers etc.USART: Universal Synchronous and Asynchronous Receiver and Transmitterinterface is available for interfacing with external device capable ofcommunicating serially (data transmission bit by bit).General Purpose Registers: Atmega16 is equipped with 32 general purposeregisters which are coupled directly with the Arithmetic Logical Unit (ALU) ofCPU.Memory: Atmega16 consist of three different memory sections:1. Flash EEPROM: Flash EEPROM or simple flash memory is used to store theprogram dumped or burnt by the user on to the microcontroller. It can be easilyerased electrically as a single unit. Flash memory is non-volatile i.e., it retains theprogram even if the power is cut-off. Atmega16 is available with 16KB of insystem programmable Flash EEPROM.2. Byte Addressable EEPROM: This is also a nonvolatile memory used to storedata like values of certain variables. Atmega16 has 512 bytes of EEPROM, thismemory can be useful for storing the lock code if we are designing an applicationlike electronic door lock.3. SRAM: Static Random Access Memory, this is the volatile memory ofmicrocontroller i.e., data is lost as soon as power is turned off. Atmega16 isequipped with 1KB of internal SRAM. A small portion of SRAM is set aside forgeneral purpose registers used by CPU and some for the peripheral subsystemsof the microcontroller.4. ISP: AVR family of controllers have In System Programmable Flash Memorywhich can be programmed without removing the IC from the circuit, ISP allowsto reprogram the controller while it is in the application circuit.5. SPI: Serial Peripheral Interface, SPI port is used for serial communicationbetween two devices on a common clock source. The data transmission rate ofSPI is more than that of USART.RISCIN TECHNOLOGIES PVT. LTDEMBEDDED SYSTEM WITH AVR15 | P a g e6. TWI: Two Wire Interface (TWI) can be used to set up a network of devices,many devices can be connected over TWI interface forming a network, thedevices can simultaneously transmit and receive and have their own uniqueaddress.PIN Configuration of ATMEGA 16

Pin DescriptionsVCC-----Digital supply voltage.GND -----GroundPort A (PA7..PA0) : Port A serves as the analog inputs to the A/D Converter.Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is notused. Port pins can provide internal pull-up resistors (selected for each bit). ThePort A output buffers have sym-metrical drive characteristics with both high sinkand source capability. When pins PA0 to PA7 are used as inputs and areexternally pulled low, they will source current if the internal pull-up resistors areactivated. The Port A pins are tri-stated when a reset condition becomes active,even if the clock is not running.Port B (PB7..PB0): Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetricaldrive characteristics with both high sink and source capability. As inputs, Port Bpins that are externally pulled low will source current if the pull-up resistors areactivated. The Port B pins are tri-stated when a reset condition becomes active,even if the clock is not running.Port C (PC7..PC0): Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port C output buffers have symmetricaldrive characteristics with both high sink and source capability. As inputs, Port Cpins that are externally pulled low will source current if the pull-up resistors areactivated. The Port C pins are tri-stated when a reset condition becomes active,even if the clock is not running.If the JTAG interface is enabled, the pull-up resistors on pins PC5 (TDI),PC3(TMS) and PC2(TCK) will be activated even if a reset occurs.Port D (PD7..PD0) ---- Port D is an 8-bit bi-directional I/O port with internalpull-up resistors (selected for each bit). The Port D output buffers havesymmetrical drive characteristics with both high sink and source capability. Asinputs, Port D pins that are externally pulled low will source current if the pull-up resistors are activated. The Port D pins are tri-stated when a reset conditionbecomes active, even if the clock is not running.RESET ---- Reset Input. A low level on this pin for longer than the minimumpulse length will generate a reset, even if the clock is not running.XTAL1 ----- Input to the inverting Oscillator amplifier and input to the internalclock operating circuit.XTAL2 ------ Output from the inverting Oscillator amplifier.AVCC -------AVCC is the supply voltage pin for Port A and the A/D Converter.It should be externally con-nected to VCC, even if the ADC is not used. If theADC is used, it should be connected to VCC through a low-pass filter.AREF ------- AREF is the analog reference pin for the A/D Converter.

CHPATER 2 OVERVIEW OF THE COMPANY

RISCIN TECHNOLOGIES PRIVATE LIMITED a leading company ofpresent scenario of innovation enhancing in field of "Automation & Robotics" todevelop the country, to enrich the living standards of people providing One StopSolution to its customers. The common capital in India is deprived of the latesttechnology due to its exorbitant price, RISCIN provides cost-effective, reliable,user friendly & high quality products to its customers which exceeds theexpectation of the customers. Its aim of innovation & development in the fieldof education to new pathway of providing training & techno solutions to thestudents all over the India upcoming with the educational products & target tobring the entrepreneurship for the students & other entrepreneurs. Our companyprovide the students of the colleges & schools with training programs & seminarsof advanced reading with the practical exploration in industrialization coveringthe subjects of the various disciplines of technology i.e. Embedded systems,Mechanical Design & Web development. The seminars covers the understandingof the latest technologies & training programs will provide the guidance for theimplementation of the various techniques available. Moreover, we also allow alaser focus on the production of the educational kits, home automation products& gadgets. Based on our experiences & statistics, our services have alwaysexceed the expectations of our learners.

CHAPTER 3

IDENTIFICATION OF TRIANING

BITWISE OPERATIONSBitwise AND & :The bitwise AND operator is a single ampersand: &. A handy mnemonic is that small version of the boolean AND, &&, works on smaller pieces (bits instead of bytes, chars, integers, etc). In essence, a binary AND simply takes the logical AND of the bits in each position of a number in binary form. For instance, working with a byte (the char type):01001000 & 10111000 = 00001000 The most significant bit of the first number is 0, so we know the most significant bit of the result must be 0; in the second most significant bit, the bit of second number is zero, so we have the same result. The only time where both bits are 1, which is the only time the result will be 1, is the fifth bit from the left.Consequently, 72 & 184 = 8.

Bitwise OR |Bitwise OR works almost exactly the same way as bitwise AND. The onlydifference is that only one of the two bits needs to be a 1 for that position's bit inthe result to be 1. (If both bits are a 1, the result will also have a 1 in that position.)The symbol is a pipe: ' | '01001000 | 10111000 = 11111000and consequently72 | 184 = 248

The Bitwise Complement ~ The bitwise complement operator, the tilde, ~, flips every bit. A useful way toremember this is that the tilde is sometimes called a twiddle, and the bitwisecomplement twiddles every bit: if you have a 1, it's a 0, and if you have a 0, it's a1. This turns out to be a great way of finding the largest possible value for anunsigned number:unsigned int max = ~0;0, of course, is all 0s: 00000000 00000000. Once we twiddle 0, we get all 1s:11111111 11111111. Since max is an unsigned int, we don't have to worry aboutsign bits or twos complement. We know that all 1s is the largest possible number.Bitwise Exclusive-Or (XOR) ^ There is no Boolean operator counterpart to bitwise exclusive-or, but there is asimple explanation. The exclusive-or operation takes two inputs and returns a 1if either one or the other of the inputs is a 1, but not if both are. That is, if bothinputs are 1 or both inputs are 0, it returns 0. Bitwise exclusive-or, with theoperator of a carrot ^ performs the exclusive-or operation on each pair of bits.Exclusive-or is commonly abbreviated XOR.For instance, if you have two numbers represented in binary as 10101010 and01110010 then taking the bitwise XOR results in 11011000. It's easier to see thisif the bits are lined up correctly:01110010 ^ 10101010 = 11011000You can think of XOR in the following way: you have some bit, either 1 or 0,that we'll call A. When you take A XOR 0, then you always get A back: if A is 1,you get 1, and if A is 0, you get 0. On the other hand, when you take A XOR 1,you flip A. If A is 0, you get 1; if A is 1, you get 0.

The Left Shift Operator 1 = 0010010000100100 >> 2=00001001

Data Types In Embedded CThere are different data type which are used in embedded C. Some of them aregiven as:-

I/O PORTsThe 1st Feature that needs to be learnt in any microcontroller is its Input-Outputfunction. Lets know about the specific case of AVR series microcontroller,ATmega16. Though we are discussing specific to a microcontroller here, try tounderstand the general concept behind I/O Ports, its usage, Its functionality inthe following discussion. ATmega16 has 40 pins. Out of these, 32 pins can beused as Input or Output. These pins are divided into 4 ports :PORT A - 8 pinsPORT B - 8 pinsPORT C - 8 pinsPORT D - 8 pinsEach of these pins can can be individually programmed as Inputs or Outputs. Soyou can use all 32 pins as input or all 32 pins as outputs or any how... But thereare some steps that we need to perform to configure the pins as either. Each portis associated with 3 registers: DDRx, PORTx, PINx. Each bit of these registerscorrespond to each pin of the port.For example, the pin 3 of port D is associated with BIT 3 of DDRD, BIT 3 ofPORTD and BIT 3 of PINDHere, we review how to configure pins as required.

Output:DDRx: Data Direction Register Whichever pin is supposed to be an output,write 1 in the corresponding DDRx bit.PORTx: Write whatever data that needs to be output in the corresponding pins.Example: Make pins 1,2,3 and 4 of PORTB as an output port and write 1 0 1 0on those pins respectively:DDRB: 76543210Data:00011110 =1E(Hexadecimal)PORTB: 7 6 5 4 3 2 1 0Data:0 0 0 1 0 1 0 0 = 14 (Hexadecimal)Code:DDRD = 0x1E;PORTD = 0x14;Input:DDRx: Data Direction Register Whichever pin is supposed to be an input, write0 in the corresponding DDRx bit.PORTx: To enable pull up registers, (which should always be done if not for anyspecial cases), write 1 in the corresponding PORTx bit.PINx: Read the input of the pins at the corresponding bits.Example: Configure the pins 0,1,2 & 3 of port D as input and read the value atthe pins.DDRD: 76543210Data:00000000 =00(Hexadecimal)

PORTB: 7 6 5 4 3 2 1 0Data:0 0 0 0 1 1 1 1 = 0F (Hexadecimal)Code:DDRD = 0x00;PORTD = 0x0F;Value = PIND;//read status of Input PinsValue = Value & 0x0F; // to mask the higher 4 bits.The Concept of Pull Up Resistors:Pull up resistors are used on the input side so that the input pins are at an expectedlogic level even if they are disconnected from the input switches. If Pull Upresistors are not used, the voltage level at the input pin will be floating in such acase and hence the outcome of the circuit is unpredictable.

CHAPTER 4

IMPLEMENTATION DETAILS

LCD ProgrammingIntroductionLCD or Liquid Crystal Display is nowadays fast becoming a preferred choice foran interface device due to its ease of use, cheap rates and value for moneyperformance. Every LCD needs a LCD driver to interface between themicrocontroller and LCD module. This driver is included on the LCD module.The most commonly used Character based LCDs are based on Hitachi's HD44780controller or other which are compatible with HD44580.Pin DescriptionThe most commonly used LCDs found in the market today are 1 Line, 2 Line or4 Line LCDs which have only 1 controller and support at most of 80 charachers,whereas LCDs supporting more than 80 characters make use of 2 HD44780controllers.Most LCDs with 1 controller has 14 Pins and LCDs with 2 controller has 16 Pins(two pins are extra in both for back-light LED connections). Pin description isshown in the table below.

DDRAM - Display Data RAMDescription(GND) Power supply (+5V) Contrast adjust 0 = Command input 1 = Data input 0 = Write to LCD module 1 = Read from LCD module Enable signal Data bus line 0 (LSB) Data bus line 1 Data bus line 2 Data bus line 3 Data bus line 4 Data bus line 5 Data bus line 6 Data bus line 7 (MSB)Display data RAM (DDRAM) stores display data represented in 8-bit character codes. Its extended capacity is 80 X 8 bits, or 80 characters. The area in display data RAM (DDRAM) that is not used for display can be used as general data RAM. So whatever you send on the DDRAM is actually displayed on the LCD. For LCDs like 1x16, only 16 characters are visible, so whatever you write after 16 chars is written in DDRAM but is not visible to the user.

CGROM - Character Generator ROMNow you might be thinking that when you send an ascii value to DDRAM, howthe character is displayed on LCD? so the answer is CGROM. The charactergenerator ROM generates 5 x 8 dot character patterns from 8-bit character codes(see Figure 5 and Figure 6 for more details). It can generate 208 5 x 8 dot characterpatterns and 32 5 x 10 dot character patterns. User defined character patterns arealso available by mask-programmed ROM.

CGRAM and Character BuildingAs already explained, all character based LCD of type HD44780 has CGRAMarea to create user defined patterns. For making custom patterns we need to writevalues to the CGRAM area defining which pixel to glow. These values are to bewritten in the CGRAM address starting from 0x40. If you are wondering why itstarts from 0x40? Then the answer is given below.

Bit 7 is 0 and Bit 6 is 1, due to which the CGRAM address command starts from0x40, where the address of CGRAM (Acg) starts from 0x00. CGRAM has a totalof 64 Bytes. When you are using LCD as 5x8 dots in function set then you candefine a total of 8 user defined patterns (1 Byte for each row and 8 rows for eachpattern), where as when LCD is working in 5x10 dots, you can define 4 userdefined patterns.Lets take an of building a custom pattern. All we have to do is make a pixel-mapof 7x5 and get the hex or decimal value or hex value for each row, bit value is 1if pixel is glowing and bit value is 0 if pixel is off. The final 7 values are loadedto the CGRAM one by one. As i said there are 8 rows for each pattern, so last rowis usually left blank (0x00) for the cursor. If you are not using cursor then youcan make use of that 8th row also. so you get a bigger pattern.To explain the above explaination in a better way. Take an example. Lets makea "Bell" pattern as shown below. Now we get the values for each row as shown.

Bit:4 3 2 1 0 - HexRow1: 0 0 1 0 0 - 0x04Row2: 0 1 1 1 0 - 0x0ERow3: 0 1 1 1 0 - 0x0ERow4: 0 1 1 1 0 - 0x0ERow5: 1 1 1 1 1 - 0x1FRow6: 0 0 0 0 0 - 0x00Row7: 0 0 1 0 0 - 0x04Row8: 0 0 0 0 0 - 0x00We are not using row 8 as in our pattern it is not required. if you are using cursorthen it is recommended not to use the 8th row. Now as we have got the values.We just need to put these values in the CGRAM. You can decided which placeyou want to store in. Following is the memory map for custom patterns inCGRAM.

We can point the cursor to CGRAM address by sending command, which is 0x40 + CGRAM address. Lets say we want to write the Bell pattern at second pattern location. So we send the command as 0x48 (0x40 + 0x08), and then we send the pattern data. Below is a small programming example to do this.lcd_cmd(0x48);lcd_char(0x04);lcd_char(0x0E);lcd_char(0x0E);lcd_char(0x0E);lcd_char(0x1F);lcd_char(0x00);lcd_char(0x04);lcd_char(0x00);To display the above pattern we have to access 1st memory. Code for accessing the above patternlcd_char(1);

H-BridgeIt is a basic circuitry used to control the direction of DC motor. Its shape is similar to alphabet H as shown in figure belowWhen SW-1 and SW-4 are closed then motor will rotate in clockwise direction and when SW-2 and SW-3 are close then motor will rotate in counter clockwise direction.

1. USED TO DRIVE THE MOTOR.2. FOUR INPUT AND OUTPUT PINS.3. CAN DRIVE FOUR RELAYS.4. CAN DRIVE FORWARD AND REVERSE DIRECTION.

IR Sensor

Infrared radiation is the portion of electromagnetic spectrum having wavelengths longer than visible light wavelengths, but smaller than microwaves, i.e., the region roughly from 0.75m to 1000 m is the infrared region. Infrared waves are invisible to human eyes. The wavelength region of 0.75m to 3 m is called near infrared, the region from 3 m to 6 m is called mid infrared and the region higher than 6 m is called far infrared.

The TSOP 1738 is a member of IR remote control receiver series. This IR sensor module consists of a PIN diode and a pre amplifier which are embedded into a single package. The output of TSOP is active low and it gives +5V in off state. When IR waves, from a source, with a centre frequency of 38 kHz incident on it, its output goes low.

Lights coming from sunlight, fluorescent lamps etc. may cause disturbance to it and result in undesirable output even when the source is not transmitting IR signals. A bandpass filter, an integrator stage and an automatic gain control are used to suppress such disturbances.TSOP module has an inbuilt control circuit for amplifying the coded pulses from the IR transmitter. A signal is generated when PIN photodiode receives the signals. This input signal is received by an automatic gain control (AGC). For a range of inputs, the output is fed back to AGC in order to adjust the gain to a suitable level. The signal from AGC is passed to a band pass filter to filterundesired frequencies. After this, the signal goes to a demodulator and this demodulated output drives an npn transistor. The collector output of the transistor is obtained at pin 3 of TSOP module.Members of TSOP17xx series are sensitive to different centre frequencies of the IR spectrum. For example TSOP1738 is sensitive to 38 kHz whereas TSOP1740 to 40 kHz centre frequency.

Introduction to ADCADC stands for analog to digital converters. Analog to digital converters are the most widely used devices for data acquisition. Digital Computers use binary (discrete) values, but in physical world everything is analog (continuous). Temperature, pressure (wind or liquid), humidity, and the velocity are a few examples of physical quantities that we deal with everyday. A physical quantity is converted to electrical (voltage, current) signals using a device called transducer. Transducers are also referred to as sensors. Sensors ofor temperature, velocity, pressure, light and many other natural quantities produce an is voltage (cot current). Therefore we neeed an analog to digital converter to translate the analog signals to digital numbers so that the microcontroller read and process them.

ResolutionThe ADC has n-bit resolution, where n can be 8, 10, 12, 16, or Higher-resolution as shown in table. ADCs provide a smaller step size, where step size is the smallest change that can be discerned by an ADC. Although the resolution of an ADC chip is decided at the time of its design and cannot be changed, we can control with the help of what is called Vref.

INTERRUPT PROGRAMMING IN CIn C language there is no instruction to manage the interrupts. So, in winAVR thefollowing have been added to manage the interrupts:1. Interrupt include file: We should include the interrupt header file if we want touse interrupts in our program. Use the following instruction:#inc1ude .2. cli ( ) and sei ( ): clear and set the I bit of the SREG register, respectively3. Defining ISR: To write an ISR (interrupt Service Routine) for an interrupt weuse the following structure:ISR (Interrupt Vector Name){//Program}

SERIAL COMMUNICATIONBasics of Serial CommunicationWhen a microprocessor communicates with the outside world, it provides the data in byte-sized chunks. For some devices, such as printers, the information is simply grabbed from the 8-bit data bus and presented to the 8-bit data bus of the device. This can work only if the cable is not too long, because long cables diminish and even distort signals. Furthermore, an 8-bit data path is expensive.For these reasons, serial communication is used for transferring data between two systems located at distances of hundreds of feet to millions of miles apart. This diagram shows serial versus parallel data transfers.Serial data communication uses two methods, asynchronous and synchronous.The synchronous method transfers a block of data (characters) at a time, whereas the asynchronous method transfers a single byte at a time. It is possible to write software to use either of these methods, but the programs can be tedious and long. For this reason, special IC chips are made by many manufacturers for serial data communications. These chips are commonly referred to as UART (universal asynchronous receiver-transmitter) and USART (universal synchronous asynchronous receiver-transmitter). The AVR chip has a built-in USART.

CHAPTER 5 PROJECT OVERVIEW

7-SEGMENT DISPLAY PROGRAMMING IN C USING KIT#include#includevoid main (){while(1){DDRC=0Xff;PORTC=0b00000110;_delay_ms(50);PORTC=0b01011011;_delay_ms(50);PORTC=0b01001111;_delay_ms(50);PORTC=0b01100110;_delay_ms(50);PORTC=0b01101101;_delay_ms(50);PORTC=0b01111101;_delay_ms(50);PORTC=0b00000111;_delay_ms(50);PORTC=0b01111111;_delay_ms(50);PORTC=0b01101111;_delay_ms(50);}}ANALOG TO DIGITAL CONVERSION PROGRAMMING DONE IN C AND IMPLEMENTED ON KIT #include#include#include#includeunsigned char temp;void main(){sei();DDRA=0x00;DDRC=0xff;lcd_init();ADMUX=0b11100111;ADCSRA=0b11101111;while(1){lcd_gotoxy1(0);lcd_string("temperature");

lcd_gotoxy1(12);_delay_ms(5000); lcd_showvalue(temp);

} }ISR(ADC_vect){ temp=ADCH;ADCSRA=0b11101111;}

BIBLOGRAPHY:1. The AVR Microcontrollers and Embedded System-Muhammad ali MazidI2. www.engineergarage.com3. http://en.wikipedia.org/wiki/Intel_MCS-514. www.mikroe.com/chapters/view/65/5. en.wikibooks.org/wiki/Embedded_Systems/AVR_Microcontroller6. www.slideshare.net/yayavaram/AVR-microcontroller-notes7. www.viit.ac.in/8051_Micro_controller.pdf8. www.newagepublishers.com/samplechapter/002079.pdf9. nptel.iitm.ac.in/courses/.../IIT.../microcontrollers/.../Course_home2_5.ht...

1


Recommended