You are on page 1of 37


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


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.


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.


Embedded System
An 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 microkernel Embedded systems are designed around a C which integrates Memory & Peripherals

Embedded systems: What are they?

A special purpose computer built into a larger device Special purpose Embedded 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 capabilities


It 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 process Avoids 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 Computers


Sophisticated functionality Real-Time Operation Low Manufacturing Cost Low Power Consumption Eliminates Necessity of Complex Circuitry Smarter Products Smaller Size User Friendly

Four General Embedded Systems Types

General Computing Applications similar to desktop computing, but in an embedded package Video games, set- top boxes, wearable computers, automatic tellers Control Systems Closed- loop feedback control of real- time system Vehicle engines, chemical processes, nuclear power, flight control Signal Processing Computations involving large data streams Radar, Sonar, video compression Communication & Networking Switching and information transmission Telephone system, Internet EMBEDDED SYSTEMS COMPONENTS MICRO 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 Instruction READ ONLY MEMORY (ROM):Permanently Loaded With Instructions (FIRMWARE) RANDOM ACCESS MEMORY (RAM) STORES DATA IN PROCESSING / SHARES DATA WITH EXTERNAL PARTNERS REAL TIME CLOCK (RTC) COMMUNICATIONS CIRCUITRY - Ethernet Port, Printer

Port, Communications Port (RS232, RS485, RS422)


Automatic Teller Machines or ATM's & Bank Vaults Blue Tooth enabled Network Synchronization Application Control 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) systems Telecommunications (Private Branch Exchanges, Custom Premises Equipment)


A procedure for designing a system Understanding your methodology helps you ensure you didnt skip anything. Compilers, software engineering tools, computer-aided design (CAD) tools, etc., can be used to: help automate methodology steps;keep track of the methodology itself.


Overall speed, deadlines. Performance. Overall speed, deadlines. Functionality and user interface. Manufacturing cost. Power consumption. Other requirements (physical size, etc.)


Late 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 Computer

Microcontroller operation is controlled by a user-written program interacting with the fixed hardware architecture resident within the microcontroller. A specific microcontroller architecture can be categorized as accumulatorbased, registerbased, stack-based, or a pipeline architecture. The Atmel ATmega16 is a registerbased architecture. In this type of architecture, both operands of an operation are stored in registers collocated with the central processing unit (CPU). This means that before an operation is performed, the computer loads all necessary data for the 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 minimizes slower 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 executed in 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 registers that 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 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. Characteristics 8051 PIC AVR AVR 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 applications 2. 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 the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the ATtiny25/45/85 achieves throughputs approaching 1 MIPS per MHz allowing the system designer to optimize power consumption versus processing 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 three software selectable power saving modes. Idle mode stops the CPU while allowing the SRAM, Timer/Counter, ADC, Analog Comparator, and Interrupt system to continue functioning. Powerdown 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 minimize switching 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 selfprogrammability 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 Features
Broad 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, insystem 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 memory 1KB of SRAM 512 Bytes of EEPROM Available in 40-Pin DIP 8-Channel 10-bit ADC Two 8-bit Timers/Counters One 16-bit Timer/Counter 4 PWM Channels In System Programmer (ISP) Serial USART SPI Interface Digital to Analog Comparator.

Architecture of AVR
The 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 equipped with 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 AVR can 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 Family I/O Ports: Atmega16 has four (PORTA, PORTB, PORTC and PORTD) 8-bit input-output ports. Internal Calibrated Oscillator: Atmega16 is equipped with an internal oscillator for driving its clock. By default Atmega16 is set to operate at internal calibrated oscillator of 1 MHz. The maximum frequency of internal oscillator is 8Mhz. Alternatively, ATmega16 can be operated using an external crystal oscillator with a maximum frequency of 16MHz. In this case you need to modify the fuse bits. (Fuse Bits will be explained in a separate tutorial).

Architecture of ATmega16 - AVR Microcontrollers

ADC Interface: Atmega16 is equipped with an 8 channel ADC (Analog to Digital Converter) with a resolution of 10-bits. ADC reads the analog input for e.g., a sensor input and converts it into digital information which is understandable 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 delays

between two operations.


Watchdog Timer:Watchdog timer is present with internal oscillator. Watchdog timer continuously monitors and resets the controller if the code gets stuck at any execution action for more than a defined time interval. Interrupts:Atmega16 consists of 21 interrupt sources out of which four are external. The remaining are internal interrupts which support the peripherals like USART, ADC, Timers etc. USART: Universal Synchronous and Asynchronous Receiver and Transmitter interface is available for interfacing with external device capable of communicating serially (data transmission bit by bit). General Purpose Registers: Atmega16 is equipped with 32 general purpose registers which are coupled directly with the Arithmetic Logical Unit (ALU) of CPU. Memory: Atmega16 consist of three different memory sections: 1. Flash EEPROM: Flash EEPROM or simple flash memory is used to store the program dumped or burnt by the user on to the microcontroller. It can be easily erased electrically as a single unit. Flash memory is non-volatile i.e., it retains the program even if the power is cut-off. Atmega16 is available with 16KB of in system programmable Flash EEPROM. 2. Byte Addressable EEPROM: This is also a nonvolatile memory used to store data like values of certain variables. Atmega16 has 512 bytes of EEPROM, this memory can be useful for storing the lock code if we are designing an application like electronic door lock. 3. SRAM: Static Random Access Memory, this is the volatile memory of microcontroller i.e., data is lost as soon as power is turned off. Atmega16 is

equipped with 1KB of internal SRAM. A small portion of SRAM is set aside for general purpose registers used by CPU and some for the peripheral subsystems of the microcontroller. 4. ISP: AVR family of controllers have In System Programmable Flash Memory which can be programmed without removing the IC from the circuit, ISP allows to reprogram the controller while it is in the application circuit. 5. SPI: Serial Peripheral Interface, SPI port is used for serial communication between two devices on a common clock source. The data transmission rate of SPI is more than that of USART.

6. 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, the devices can simultaneously transmit and receive and have their own unique address.

PIN Configuration of ATMEGA 16


Pin Descriptions VCC ----- Digital supply voltage. GND ----Ground Port 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 not used. Port pins can provide internal pull-up resistors (selected for each bit). The Port A output buffers have sym-metrical drive characteristics with both high sink and source capability. When pins PA0 to PA7 are used as inputs and are externally pulled low, they will source current if the internal pull-up resistors are activated. 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 pullup resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. 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 pullup resistors (selected for each bit). The Port C output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port C pins that are externally pulled low will source current if the pull-up resistors are activated. 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 internal pull-up resistors (selected for each bit). The Port D output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port D pins that are externally pulled low will source current if the pullup resistors are activated. The Port D pins are tri-stated when a reset condition becomes active, even if the clock is not running. RESET ---- Reset Input. A low level on this pin for longer than the minimum pulse length will generate a reset, even if the clock is not running. XTAL1 ----- Input to the inverting Oscillator amplifier and input to the internal clock 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 the ADC 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.



RISCIN TECHNOLOGIES PRIVATE LIMITED a leading company of present scenario of innovation enhancing in field of "Automation & Robotics" to develop the country, to enrich the living standards of people providing One Stop Solution to its customers. The common capital in India is deprived of the latest technology due to its exorbitant price, RISCIN provides costeffective, reliable, user friendly & high quality products to its customers which exceeds the expectation of the customers. Its aim of innovation & development in the field of education to new pathway of providing training & techno solutions to the students all over the India upcoming with the educational products & target to bring the entrepreneurship for the students & other entrepreneurs. Our company provide the students of the colleges & schools with training programs & seminars of advanced reading with the practical exploration in industrialization covering the subjects of the various disciplines of technology i.e. Embedded systems, Mechanical Design & Web development. The seminars covers the understanding of the latest technologies & training programs will provide the guidance for the


implementation of the various techniques available. Moreover, we also allow a laser focus on the production of the educational kits, home automation products & gadgets. Based on our experiences & statistics, our services have always exceed the expectations of our learners.




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 only difference is that only one of the two bits needs to be a 1 for that position's bit in the 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 = 11111000 and consequently 72 | 184 = 248

The Bitwise Complement ~

The bitwise complement operator, the tilde, ~, flips every bit. A useful way to remember this is that the tilde is sometimes called a twiddle, and the bitwise complement twiddles every bit: if you have a 1, it's a 0, and if you have a 0, it's a 1. This turns out to be a great way of finding the largest possible value for an unsigned 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 about sign 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 a simple explanation. The exclusive-or operation takes two inputs and returns a 1 if either one or the other of the inputs is a 1, but not if both are. That is, if both inputs are 1 or both inputs are 0, it returns 0. Bitwise exclusive-or, with the operator 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 and 01110010 then taking the bitwise XOR results in 11011000. It's easier to see this if the bits are lined up correctly: 01110010 ^ 10101010 = 11011000 You 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 <<

It is the equivalent of moving all the bits of a number a specified number of places to the left [variable]<<[number of places] 01001000 << 1 = 10010000 10010000 << 2 = 01000000

The Right Shift Operator >>

It is the equivalent of moving all the bits of a number a specified number of places

to the right [variable]>>[number of places] 01001000 >> 1 = 00100100 00100100 >> 2 = 00001001

Data Types In Embedded C

There are different data type which are used in embedded C. Some of them are given as:-

The 1st Feature that needs to be learnt in any microcontroller is its Input-Output function. Lets know about the specific case of AVR series microcontroller, ATmega16. Though we are discussing specific to a microcontroller here, try to understand the general concept behind I/O Ports, its usage, Its functionality in the following discussion. ATmega16 has 40 pins. Out of these, 32 pins can be used as Input or Output. These pins are divided into 4 ports : PORT A - 8 pins PORT B - 8 pins PORT C - 8 pins PORT D - 8 pins Each of these pins can can be individually programmed as Inputs or Outputs. So


you can use all 32 pins as input or all 32 pins as outputs or any how... But there are some steps that we need to perform to configure the pins as either. Each port is associated with 3 registers: DDRx, PORTx, PINx. Each bit of these registers correspond to each pin of the port. For example, the pin 3 of port D is associated with BIT 3 of DDRD, BIT 3 of PORTD and BIT 3 of PIND Here, we review how to configure pins as required.

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 0 on those pins respectively: DDRB: 76543210 Data: 00011110 =1E(Hexadecimal) PORTB: 7 6 5 4 3 2 1 0 Data: 0 0 0 1 0 1 0 0 = 14 (Hexadecimal) Code: DDRD = 0x1E; PORTD = 0x14;

DDRx: Data Direction Register Whichever pin is supposed to be an input, write 0 in the corresponding DDRx bit. PORTx: To enable pull up registers, (which should always be done if not for any special 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 at the pins. DDRD: 76543210 Data: 00000000 =00(Hexadecimal) PORTB: 7 6 5 4 3 2 1 0 Data: 0 0 0 0 1 1 1 1 = 0F (Hexadecimal)

Code: DDRD = 0x00; PORTD = 0x0F; Value = PIND; //read status of Input Pins Value = 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 expected logic level even if they are disconnected from the input switches. If Pull Up resistors are not used, the voltage level at the input pin will be floating in such a case and hence the outcome of the circuit is unpredictable.



LCD Programming
Introduction LCD or Liquid Crystal Display is nowadays fast becoming a preferred choice for an interface device due to its ease of use, cheap rates and value for money performance. Every LCD needs a LCD driver to interface between the microcontroller and LCD module. This driver is included on the LCD module. The most commonly used Character based LCDs are based on Hitachi's HD44780 controller or other which are compatible with HD44580. Pin Description The most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 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 HD44780 controllers. 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 is shown in the table below.


DDRAM - Display Data RAM

Description (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 8bit 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 ROM Now you might be thinking that when you send an ascii value to DDRAM, how the character is displayed on LCD? so the answer is CGROM. The character generator 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 character patterns and 32 5 x 10 dot character patterns. User defined character

patterns are

also available by mask-programmed ROM.

CGRAM and Character Building As already explained, all character based LCD of type HD44780 has CGRAM area to create user defined patterns. For making custom patterns we need to write values to the CGRAM area defining which pixel to glow. These values are to be written in the CGRAM address starting from 0x40. If you are wondering why it starts 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 from 0x40, where the address of CGRAM (Acg) starts from 0x00.

CGRAM has a total of 64 Bytes. When you are using LCD as 5x8 dots in function set then you can define a total of 8 user defined patterns (1 Byte for each row and 8 rows for each pattern), where as when LCD is working in 5x10 dots, you can define 4 user defined patterns. Lets take an of building a custom pattern. All we have to do is make a pixel-map of 7x5 and get the hex or decimal value or hex value for each row, bit value is 1 if pixel is glowing and bit value is 0 if pixel is off. The final 7 values are loaded to the CGRAM one by one. As i said there are 8 rows for each pattern, so last row is usually left blank (0x00) for the cursor. If you are not using cursor then you can 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 make a "Bell" pattern as shown below. Now we get the values for each row as shown.

Bit: 4 3 2 1 0 - Hex Row1: 0 0 1 0 0 - 0x04 Row2: 0 1 1 1 0 - 0x0E Row3: 0 1 1 1 0 - 0x0E Row4: 0 1 1 1 0 - 0x0E Row5: 1 1 1 1 1 - 0x1F

Row6: 0 0 0 0 0 - 0x00 Row7: 0 0 1 0 0 - 0x04 Row8: 0 0 0 0 0 - 0x00 We are not using row 8 as in our pattern it is not required. if you are using cursor then 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 place you want to store in. Following is the memory map for custom patterns in CGRAM.

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 1 st memory. Code for accessing the above pattern lcd_char(1);


It is a basic circuitry used to control the direction of DC motor. Its shape is similar to alphabet H as shown in figure below When 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. 2. 3. 4.


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 filter undesired 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 ADC
ADC 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.


The 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.

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

Basics of Serial Communication When 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.



#include<avr/io.h> #include<avr/delay.h> void 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); } }


#include<avr/io.h> #include<util/delay.h> #include<LCD_mega16.h> #include<avr/interrupt.h> unsigned 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 MazidI 2. 3. 4. 5. 6. 7. 8. 9.