Sie sind auf Seite 1von 33

CHAPTER 1 INTRODUCTION

1.1 INTRODUCTION TO EMBEDDED SYSTEM

We are living in the Embedded World. We are surrounded with many embedded products and our daily life largely depends on the proper functioning of these gadgets. Television, Radio, CD player of your living room, Washing Machine or Microwave Oven in your kitchen, Card readers, Access Controllers, Palm devices of your work space enable us to do many of our tasks very effectively. Apart from all these, many controllers embedded in our car take care of car operations between the bumpers and most of the times we tend to ignore all these controllers. In recent days, we are showered with variety of information about these embedded controllers in many places. All kinds of magazines and journals regularly dish out details about latest technologies, new devices, fast applications which make us to believe that our basic survival is controlled by these embedded products. Now you can agree to the fact that these embedded products have successfully invaded into our world. One must be wondering about these embedded controllers or systems. What is this Embedded System? The computer is used to compose mails, or create a document or analyze the database is known as the standard desktop computer. These desktop computers are manufactured to serve many purposes and applications. We need to install the relevant software to get the required processing facility. So, these desktop computers can do many things. In contrast, embedded controllers carryout a specific work for which they are designed. Most of the time, engineers design these embedded controllers with a specific goal in mind. So these controllers cannot be used in any other place. Theoretically, an embedded controller is a combination of a piece of microprocessor based hardware and the suitable software to undertake a specific task. These days designers have many choices in microprocessors/microcontrollers. Especially, in 8 bit and 32 bit, the available variety really may overwhelm even an experienced designer. Selecting a right microprocessor may turn out as a most difficult first step and it is getting complicated as new devices continue to pop-up very often.
6-week Institutional training in Microcontroller & Embedded System Page 1

In the 8 bit segment, the most popular and used architecture is Intel's 8051. Market acceptance of this particular family has driven many semiconductor manufacturers to develop something new based on this particular architecture. Even after 25 years of existence, semiconductor manufacturers still come out with some kind of device using this 8051 core.

1.2 MICROCONTROLLERS FOR EMBEDDED SYSTEMS

Microprocessors and Microcontrollers are widely used in embedded system products. An embedded system product uses a microprocessor (or Microcontroller) to do one task only. A printer is an example of embedded system since the processor inside it performs one task only; namely getting the data and printing it. Contrast this with a Pentium based PC. A PC can be used for any number of applications such as word processor, print-server, bank teller terminal, Video game, network server, or Internet terminal. Software for a variety of applications can be loaded and run. of course the reason a pc can perform myriad tasks is that it has RAM memory and an operating system that loads the application software into RAM memory and lets the CPU run it. In an Embedded system, there is only one application software that is typically burned into ROM. An x86 PC contains or is connected to various embedded products such as keyboard, printer, modem, disk controller, sound card, CD-ROM drives, mouse, and so on. Each one of these peripherals has a Microcontroller inside it that performs only one task. For example, inside every mouse there is a Microcontroller to perform the task of finding the mouse position and sending it to the PC. Table 1-1 lists some embedded products.
Table 1.1: List of Embedded

Products Home Appliances Intercom Washing Machines Security systems Answering machines Fax machines Home computers DVD/CD player TV's

Office Telephones Copier Computers Security systems Fax Machine Scanner Paging Laser Printer

Automobiles Trip Computer Engine control Air bag ABS (Automatic Brake System) Entertainment Keyless Entry Climate control Transmission control Security systems Instrumentation

6-week Institutional training in Microcontroller & Embedded System

Page 2

CHAPTER 2 INTELS 8051 MICROCONTROLLER


2.1 BLOCK DIAGRAM OF 8051 MICROCONTROLLER

Fig. 2.1 Block diagram of 8051 Microcontroller

6-week Institutional training in Microcontroller & Embedded System

Page 3

2.2 ARCHITECTURE

The generic 8051 architecture sports a Harvard architecture, which contains two separate buses for both program and data. So, it has two distinctive memory spaces of 64K 8 size for both program and data. It is based on an 8-bit central processing unit with an 8 bit Accumulator and another 8-bit B register as main processing blocks. Other portions of the architecture include few 8-bit and 16-bit registers and 8-bit memory locations. Each 8051 device has some amount of data RAM built in the device for internal processing. This area is used for stack operations and temporary storage of data. This base architecture is supported with on chip peripheral functions like I/O ports, timers/counters, versatile serial communication port. So it is clear that this 8051 architecture was designed to cater many real time embedded needs.

The following list gives the features of the 8051 architecture: Optimized 8 bit CPU for control applications. Extensive Boolean processing capabilities. 64KB Program Memory address space. 64KB Data Memory address space. 128 bytes of on chip Data Memory. 32-bit Bi-directional and individually addressable I/O lines. Two 16 bit timer/counters. Full Duplex UART. 6 source / 5 vector interrupt structure with priority levels. On chip clock oscillator. Now you may be wondering about not mentioning of memory space meant for the program storage, the most important part of any embedded controller. Originally this 8051 architecture was introduced with on chip, `one time programmable' version of Program Memory of size 4K X 8. Intel delivered all these microcontrollers (8051) with user's program fused inside the device. The memory portion was mapped at the lower end of the Program Memory area. But, after getting devices, customers couldn't change any thing in their program code, which was already made available inside during device fabrication. So, very soon Intel introduced the 8051 devices (8751) with re-programmable type of Program Memory using built in EPROM of size 4K X 8. Like a regular EPROM, this memory can be re programmed many times.

6-week Institutional training in Microcontroller & Embedded System

Page 4

Later on Intel started manufacturing these 8051 devices without any on chip Program Memory.

2.2.1 Central Processing Unit

The CPU is the brain of the microcontrollers reading user's programs and executing the expected task as per instructions stored there in. Its primary elements are an 8-bit Arithmetic Logic Unit (ALU), Accumulator (Acc), few more 8 bit registers, B register, Stack Pointer (SP), Program Status Word (PSW) and 16-bit registers, Program Counter (PC) and Data Pointer Register (DPTR). The ALU (Acc) performs arithmetic and logic functions on 8-bit input variables. Arithmetic operations include basic addition, subtraction, multiplication and division. Logical operations are AND, OR, Exclusive OR as well as rotate, clear, complement and etc. Apart from all the above, ALU is responsible in conditional branching decisions, and provides a temporary place in data transfer operations within the device. B register is mainly used in multiply and divide operations. During execution, B register hold one of the two inputs and then retains a portion of the result. For other instructions, it can be used as another general purpose register. 2.2.2 Timers/Counters 8051 has two 16-bit Timers/Counters capable of working in different modes. Each consists of a `High' byte and a `Low' byte which can be accessed under software. There is a mode control register and a control register to configure these timers/counters in number of ways. These timers can be used to measure time intervals, determine pulse widths or initiate events with one microsecond resolution up to a maximum of 65 millisecond (corresponding to 65, 536 counts). Use software to get longer delays. Working as counter, they can accumulate occurrences of external events (from DC to 500 KHz) with 16-bit precision. In our project we are using 8 bit microcontroller AT89C51, it is the advanced 8 bit microcontroller from ATMEL, which incorporates Flash Rom, and Timer etc.

2.2.4 Features of AT89C51 Compatible with MCS-51 Products 4 Kbytes of In-System Reprogrammable Flash Memory Endurance: 1,000 Write/Erase Cycles Fully Static Operation: 0 Hz to 24 MHz
6-week Institutional training in Microcontroller & Embedded System Page 5

Three-Level Program Memory Lock 256 X 8-Bit Internal RAM 32 Programmable I/O Lines Two 16-Bit Timer/Counters Six Interrupt Sources Programmable Serial Channel Low Power Idle and Power Down Modes The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 8 Kbytes of Flash Programmable and Erasable Read Only Memory (PEROM). The device is manufactured using Atmels high density nonvolatile memory technology and is compatible with the industry standard MCS-51 instruction set and pin out. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the Atmel AT89C51 is a powerful microcomputer which provides a highly flexible and cost effective solution to many embedded control applications. The AT89C51 provides the following standard features: 4 Kbytes of Flash, 128 bytes of RAM, 32 I/O lines, two 16-bit timer/counters, a five vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator and clock circuitry. In addition, the AT89C51 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port and interrupt system to continue functioning. The Power Down Mode saves the RAM contents but freezes the oscillator disabling all other chip functions until the next hardware reset.

6-week Institutional training in Microcontroller & Embedded System

Page 6

2.2.5 Pin Configuration of 8051

Fig. 2.2 Pin diagram of 8051 Microcontroller

ALE/PROG: Address Latch Enable output pulse for latching the low byte of the address during accesses to external memory. ALE is emitted at a constant rate of 1/6 of the oscillator frequency, for external timing or clocking purposes, even when there are no accesses to external memory. (However, one ALE pulse is skipped during each access to external Data Memory.) This pin is also the program pulse input (PROG) during EPROM programming. PSEN: Program Store Enable is the read strobe to external Program Memory. When the device is executing out of external Program Memory, PSEN is activated twice each machine cycle (except that two PSEN activations are skipped during accesses to external Data Memory). PSEN is not activated when the device is executing out of internal Program Memory. EA/VPP: When EA is held high the CPU executes out of internal Program Memory (unless the Program Counter exceeds 0FFFH in the 80C51). Holding EA low forces the CPU to execute out of external memory regardless of the Program Counter value. In the 80C31, EA must be externally wired low. In the EPROM devices, this pin also receives the programming supply voltage (VPP) during EPROM programming. XTAL1: Input to the inverting oscillator amplifier.
6-week Institutional training in Microcontroller & Embedded System Page 7

XTAL2: Output from the inverting oscillator amplifier. Port 0: Port 0 is an 8-bit open drain bidirectional port. As an open drain output port, it can sink eight LS TTL loads. Port 0 pins that have 1s written to them float, and in that state will function as high impedance inputs. Port 0 is also the multiplexed low-order address and data bus during accesses to external memory. In this application it uses strong internal pullups when emitting 1s. Port 0 emits code bytes during program verification. In this application, external pullups are required. Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pullups. Port 1 pins that have 1s written to them are pulled high by the internal pullups, and in that state can be used as inputs. As inputs, port 1 pins that are externally being pulled low will source current because of the internal pullups. Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pullups. Port 2 emits the highorder address byte during accesses to external memory that use 16-bit addresses. In this application, it uses the strong internal pullups when emitting 1s. Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pullups. It also serves the functions of various special features of the 80C51 Family as follows: Port Pin Alternate Function P3.0 RxD (serial input port) P3.1 TxD (serial output port) P3.2 INT0 (external interrupt 0) P3.3 INT1 (external interrupt 1) P3.4 T0 (timer 0 external input) P3.5 T1 (timer 1 external input) P3.6 WR (external data memory write strobe) P3.7 RD (external data memory read strobe) VCC: Supply voltage VSS: Circuit ground potential

6-week Institutional training in Microcontroller & Embedded System

Page 8

CHAPTER 3 8051 SIMULATOR & COMPILER


Many of the simulators for the 8051 that you will find are industry-standard. They are used by professional 8051-based embedded systems designers. While they show the state of the registers, memory and the port pins while code is being debugged, they do not have graphical representations of peripherals that can be used interactively to communicate with the 8051. EdSim51 have filled that need. The student can learn how to scan a keypad, multiplex 7-segment displays, control a motor and count its revolutions, etc. Another compiler, Keil development tools for the 8051 Microcontroller Architecture support every level of software developer from the professional applications engineer to the student just learning about embedded software development. The industry-standard Keil C Compilers, Macro Assemblers, Debuggers, Real-time Kernels, Singleboard Computers, and Emulators support all 8051 derivatives and help you get your projects completed on schedule.

6-week Institutional training in Microcontroller & Embedded System

Page 9

Keil C Programming Steps 1. Double Click on the icon present on the desktop.

2. The following window will be popped-up

3. Go to the project & click on new project

6-week Institutional training in Microcontroller & Embedded System

Page 10

4.

Make a folder on desktop & give file name.

5. when you click on the save button ,following window opens

6-week Institutional training in Microcontroller & Embedded System

Page 11

6. Select Philips & 89v51RD2xx

7. Then select NO on the pop-up given below.

6-week Institutional training in Microcontroller & Embedded System

Page 12

8.

Then make a New File.

9. Write or copy your code there & save it with extension .c or .asm depending on your coding.

6-week Institutional training in Microcontroller & Embedded System

Page 13

10. Go to target & then source group, right click on there & click on the option add files to the project.

11. Select your asm or c file which you want to add.

Example is with .c extension file

6-week Institutional training in Microcontroller & Embedded System

Page 14

12. Go to the option for target, click on output &tick on create hex file option

13. Now build target. (Click on the pointed option)..

6-week Institutional training in Microcontroller & Embedded System

Page 15

14. It will show you 0 errors & 0 warning on Output Window.

After performing all these steps the chip will be configured through Flash Magic .Let us hand on the steps of chip configuration through Flash Magic Special Notes:

Make all the DIP switches in off position before burning the program in the controller. Connect the Programming Cable on your Kit (prog. Conn.)And other side of cable with the COM Port of the Computer. Burn the Program in the microcontroller with help of FLASH MAGIC or ECE FLASH as explained in the next section.

6-week Institutional training in Microcontroller & Embedded System

Page 16

CHAPTER 4 EMBEDDED C PROGRAMMING


The C programming language is perhaps the most popular programming language for programming embedded systems. C remains a very popular language for micro-controller developers due to the code efficiency and reduced overhead and development time. C offers low-level control and is considered more readable than assembly. Many free C compilers are available for a wide variety of development platforms. The compilers are part of an IDEs with ICD support, breakpoints, single-stepping and an assembly window. The performance of C compilers has improved considerably in recent years, and they are claimed to be more or less as good as assembly, depending on who you ask. Most tools now offer options for customizing the compiler optimization. Additionally, using C increases portability, since C code can be compiled for different types of processors.

6-week Institutional training in Microcontroller & Embedded System

Page 17

LCD PROGRAMMING

/*This program is written for Technido`s Embedded launch pad board to demonstrate LCD functioning Connections : P0 to Data port & P1 to control port of LCD display module */ #include<reg51.h> //Header file inclusion for 8051 //Data and Command port Selection #define LCDdata P0 //Declaring LCDdata sbit LCDrs = P1^0; //The Register select Pin sbit LCDrw = P1^1; //The Read/Write Pin sbit LCDen = P1^2; //The Enable Pin /* +---------------------------------------------------------+ | Prototype: void MSdelay(unsigned int); | | Return Type: void | | Arguments: unsigned int | | Description: Generates time delay in milliseconds | | | +---------------------------------------------------------+ */ void delay(unsigned int rtime) { unsigned int r,s; for(r=0;r<rtime;r++) for(s=0;s<1275;s++); } /* +---------------------------------------------------------+ | Prototype: void lcdcmd (unsigned char); | | Return Type: void | | Arguments: unsigned char | | Description: Issue commands to LCD |
6-week Institutional training in Microcontroller & Embedded System Page 18

| | +---------------------------------------------------------+ */ void lcdcmd(unsigned char DATA) { LCDrs=0; LCDrw=0; LCDen=1; //Strobe the enable pin LCDdata = DATA; LCDrs=0; LCDrw=0; LCDen=0; } /* +---------------------------------------------------------+ | Prototype: void initialize (void); | | Return Type: void | | Arguments: None | | Description: Initialize LCD | | | +---------------------------------------------------------+ */ void initialize(void) { lcdcmd(0x30); //1 line and 5x7 matrix delay(1); lcdcmd(0x38); delay(1); lcdcmd(0x0c); delay(1); lcdcmd(0x01); delay(1); lcdcmd(0x06); delay(1); //2 line and 5x7 matrix //Put the value on the pins

//Display on, cursor off

//Clear display Screen

//shift cursor to right

} /* +---------------------------------------------------------+ | Prototype: void lcddat (unsigned int) | | Return Type: void | | Arguments: unsigned int | | Description: Display data on LCD | | +---------------------------------------------------------+ */

6-week Institutional training in Microcontroller & Embedded System

Page 19

void lcddat(unsigned int DATA) { LCDrs = 1; LCDrw = 0; LCDen = 1; //Strobe the enable pin LCDdata = DATA; LCDrs = 1; LCDrw = 0; LCDen = 0; } /* +-----------------------------------------------------------+ | Prototype: void display_lcd (unsigned char,unsigned char) | | Return Type: void | | Arguments: unsigned char & unsigned char* | | Description: Diplay the argument character string on | | given location using lcddat(unsigned int) | +-----------------------------------------------------------+ */ void display_lcd(unsigned char location, unsigned char *d) { lcdcmd(0x80 | location); delay(1); //10mS delay generation while(*d) { lcddat(*d++); delay(1); } } void main(void) { initialize(); //Put the value on the pins

//10mS delay generation

//initilaze LCD

display_lcd(0x00,"www.technido.com"); //Display character String from location specified display_lcd(0x40," INDIA "); //Display character String from location specified while(1)} HEX FILE
:100869007777772E746563686E69646F2E636F6D31 :1008790000202020202020494E44494120202020CA :0208890020004D :10088B00E4FDFCC3ED9FEC9E5015E4FBFA0BBB00A3

6-week Institutional training in Microcontroller & Embedded System

Page 20

:0F089B00010ABA04F8BBFBF50DBD00010C80E4A7 :0108AA00222B :0F08DF00C290C291D2928F80C290C291C29222D7 :100839007F301208DF7F017E0012088B7F38120893 :10084900DF7F0112088B7F0C1208DF7F0112088BF2 :100859001208DF12088B7F061208DF7F0102088B5E :0F08EE00D290C291D2928F80D290C291C29222A8 :100800008B088A09890AEF4480FF1208DF7F017E86 :10081000008020AB08AA09A90A1208C6601A050AB6 :10082000E50A7002050914F91208C6FF7E001208D5 :09083000EE7F0112088B80DB222F :1008AB001208397BFF7A087969E4FF1208007BFF95 :0B08BB007A08797A7FC012080080FEE6 :030000000208FDF6 :0C08FD00787FE4F6D8FD75810A0208AB94 :1008C600BB010689828A83E0225002E722BBFE0230 :0908D600E32289828A83E4932263 :00000001FF

SEVENSEGMENT PROGRAMMING

/*This program is written for Technido`s Embedded launch pad to demonstration working of Seven segement Display

Connections: Port P0 to first connector Port P1 to Second Connector of Seven segment display */

//Header file inclusion #include<reg51.h> //Select seven segment display sbit E1=P0^0;
6-week Institutional training in Microcontroller & Embedded System Page 21

sbit E2=P0^1;

/* +---------------------------------------------------------+ | Prototype: void delay(unsigned int); | | Return Type: void | | Arguments: unsigned int | | Description: Generates time delay in milliseconds | | +---------------------------------------------------------+ */ void delay(unsigned int rtime) { unsigned int r,s; for(r=0;r<rtime;r++) for(s=0;s<275;s++); } /* +---------------------------------------------------------+ | Prototype: void display(unsigned int); | | Return Type: void | | Arguments: unsigned int | | Description: Display an argument on seven segment | display | +---------------------------------------------------------+ */ void display(unsigned int value) { unsigned int refresh,tens,ones; tens=value/10; ones=value%10;

//Seperate number into place value form

for(refresh=0;refresh<=35;refresh++) { E1=1; E2=0; switch(tens) { case 0: P1=0x42; break; case 1: P1=0x77; break; case 2:
6-week Institutional training in Microcontroller & Embedded System Page 22

P1=0xC1; break; case 3: P1=0x51; break; case 4: P1=0x74; break; case 5: P1=0x58; break; case 6: P1=0x48; break; case 7: P1=0x73; break; case 8: P1=0x40; break; case 9: P1=0x50; break; } delay(1); E1=0; E2=1; switch(ones) { case 0: P1=0x42; break; case 1: P1=0x77; break; case 2: P1=0xC1; break;

6-week Institutional training in Microcontroller & Embedded System

Page 23

case 3: P1=0x51; break; case 4: P1=0x74; break; case 5: P1=0x58; break; case 6: P1=0x48; break; case 7: P1=0x73; break; case 8: P1=0x40; break; case 9: P1=0x50; break; } delay(1); } } //Main function void main(void) { unsigned int counter; while(1) { for(counter=0;counter<=99;counter++) { display(counter); } } } HEX FILE
:100D28006E6F2E656E746572656420697300256444

//Counter that count from 0 to 99

6-week Institutional training in Microcontroller & Embedded System

Page 24

:010D380000BA :050CDE00120D457F0A24 :100CE300E4FDFCD3ED9FEC9E5015E4FBFA0BBB0037 :0F0CF300010ABA04F8BBFCF50DBD00010C80E44A :010D020022CE :0B0D4500C280C281D2828F90C2822245 :0B0D5000D280C281D2828F90C282222A :100D03007F30120D457F0A7E00120CE37F38120CF0 :100D1300DE7F0C120CDE7F06120CDE7F01120D4506 :050D23007F0A020CE351 :060C7E007B007A007924DE :100C84008B088A09890AEF4480FF120D457F017E93 :100C940000120CE3AB08AA09A90A120B5C60130545 :100CA4000AE50A7002050914F9120B5CFF120D50D3 :030CB40080E222B9 :100BEA00D2A5C2A720A0057E007F012220A1057EF2 :100BFA00007F042220A2057E007F0722D2A7C2A678 :100C0A0020A0057E007F022220A1057E007F05220A :100C1A0020A2057E007F0822D2A6C2A520A0057EBA :100C2A00007F032220A1057E007F062220A2B17E3A :040C3A00007F09220C :100C3E00120D03120BEA8E228F23750BFF750C0D0E :100C4E00750D287B007A00792412085C7F80120CC7 :100C5E007E750BFF750C0D750D3685220E85230FD7 :100C6E007B007A00792412085C7FC7120C7E80C349 :03000000020D39B5 :0C0D3900787FE4F6D8FD758133020C3E93 :100B5C00BB010689828A83E0225002E722BBFE0297 :090B6C00E32289828A83E49322CA :10080000E517240BF8E60517227808300702780B65 :10081000E475F001120BB4020B5C2000EB7F2ED2CA :10082000008018EF540F2490D43440D4FF30040BD0 :10083000EF24BFB41A0050032461FFE518600215CD :1008400018051BE51B7002051A30070D7808E475C2 :10085000F001120BB4EF020BA2020CB77403D20723 :100860008003E4C207F5178B088A09890AE4F518A2 :10087000F51AF51BE51860077F2012083B80F57517 :1008800019FFC201C200C202C203C205C206C208E9 :10089000120809FF700D3007057F0012084CAF1BCE :1008A000AE1A22B4255FC2D5C204120809FF24D0B3 :1008B000B40A00501A75F00A781830D50508B6FF4A :1008C0000106C6A426F620D5047002D20380D924DE :1008D000CFB41A00EF5004C2E5D204020A4CD20190 :1008E00080C6D20080C0D20280BCD2D580BAD205E8 :1008F00080B47F2012083B2002077401B518004025 :10090000F1120800FF12083B020874D208D20680D8 :1009100095120800FB120800FA120800F94A4B7001 :1009200006791D7A0B7BFF20022EE518602A7E00D7 :100930008E82758300120B7560060EEE651970F0DD :10094000C2D5EBC0E0EAC0E0E9C0E0EE120A93D005 :10095000E0F9D0E0FAD0E0FB120B5CFF60AAEBC03C :10096000E0EAC0E0E9C0E012083BD0E02401F9D0A1 :10097000E03400FAD0E0FBE5190460DCD519D98039 :10098000877BFF7A0A798FD202809C791080027966 :1009900008C206C2088008D2D5790A8004790AC242 :1009A000D5E519047002F519E4FAFDFEFF120800FE :1009B000FC7B08200113120800FD7B1030000A1296 :1009C0000800FE120800FF7B20EC3382D592D55040 :1009D00013C3E43000069FFFE49EFEE42001039D64 :1009E000FDE49CFCE4CBF8C201EC700CCFCECDCC86

6-week Institutional training in Microcontroller & Embedded System

Page 25

:1009F000E824F8F870F38017C3EF33FFEE33FEED11 :100A000033FDEC33FCEB33FB994002FB0FD8E9EBF1 :100A1000300105F8D0E0C448B201C0E00AEC4D4E08 :100A20004F78207B0070C2EAB5190040BCC0E012CC :100A30000A95D0F0D0E0200104C4C0E0C4B201C0E7 :100A4000F0120824D0F0D5F0EB020874120BC409A0 :100A50001153098B5808E24C08DE42098F4F099761 :0F0A60004409974908F743099D550981460981C3 :100A6F00450981470B3D5008E62D08EA2E090D2B4D :100A7F0008EE23090B200B262A08A64800000905BB :100A8F003F3F3F00790AA2D5200314300509B91062 :100A9F00020404B9080104A2D52006025001042063 :100AAF0002689202B518005034C0E07F203003195D :100ABF007F30A20272067205500F120AECC202C2F8 :100ACF0006C205C2087F30800F300503E9C0E0126F :100ADF00083B300503D0E0F9D0E0B518CC3005174E :100AEF007F30B9100C12083B7F583004077F788095 :100AFF0003B9080312083B3002057F2D02083B7F24 :100B0F00202008F87F2B2006F322920280CF286E38 :100B1F00756C6C2900D2011208003001F8C20178FF :100B2F001830D50108F60208A62D5043495812086F :100B3F00002403B405004001E4900B389312082CF5 :0D0B4F00743A12082CD20375180402098BA9 :100B7500BB010CE58229F582E5833AF583E0225035 :100B850006E92582F8E622BBFE06E92582F8E2227F :0D0B9500E58229F582E5833AF583E4932299 :100BA200BB010689828A83F0225002F722BBFE0132 :020BB200F3222C :100BB400FAE6FB0808E6F925F0F618E6CA3AF62242 :100BC400D083D082F8E4937012740193700DA3A3C0 :100BD40093F8740193F5828883E4737402936860D4 :060BE400EFA3A3A380DFD4 :100CB700EFB40A07740D120CC2740A309811A89980 :100CC700B8130CC2983098FDA899C298B811F6309D :070CD70099FDC299F5992275 :00000001FF

CALCULATOR

/* This program is written for Technido`s Embedded Launch pad to demonstrate Keypad interfacing
6-week Institutional training in Microcontroller & Embedded System Page 26

Connections : Port P0 to Data port of LCD Port P1 to Control port of LCD Port P2 to Keypad module Its an electronics door lock with password as 626 */ #include<reg51.h> #include<stdio.h> //lcd control pins sbit RS=P1^0;//resister select sbit RW=P1^1;//read/write sbit EN=P1^2;//enable sfr lcddata = 0x80; // 80H is Port0 address.so data and commands will go through P0. // col3col2col1 sbit r1=P2^0; //first row 3 2 1 row1 sbit r2=P2^1; //2nd row 6 5 4 row2 sbit r3=P2^2;//3rd row 9 8 7 row3 sbit r4=P2^3;//4th row 0 row4 sbit c4=P2^4; sbit c3=P2^5;//3rd coloumn sbit c2=P2^6;//2nd coloumn sbit c1=P2^7;//1st coloumn /* +---------------------------------------------------------+ | Prototype: void MSdelay(unsigned int); | | Return Type: void | | Arguments: unsigned int | | Description: Generates time delay in milliseconds | | | +---------------------------------------------------------+ */ void delay(unsigned int time) { unsigned int a,b; for(a=0;a<=time;a++) { for(b=0;b<=1275;b++)//1275 provides delay of 10ms and it time=2, then delay=20ms {} } } //This function makes one column to GND one by one and check the rows for key press int keypress() { while(1) {
6-week Institutional training in Microcontroller & Embedded System Page 27

c1=0;c2=1;c3=1;// coloumn 1 selected if(r1==0){return 1;}//if r1=0, means key 1 is pressed if(r2==0){return 4;}//if r2=0, means key 4 is pressed if(r3==0){return 7;}//if r3=0, means key 7 is pressed c1=1;c2=0;c3=1; if(r1==0){return 2;} if(r2==0){return 5;} if(r3==0){return 8;} if(r4==0){return 0;} c1=1;c2=1;c3=0; if(r1==0){return 3;} if(r2==0){return 6;} if(r3==0){return 9;} } } /* +---------------------------------------------------------+ | Prototype: void lcdcmd (unsigned char); | | Return Type: void | Arguments: unsigned char | | Description: Issue commands to LCD | +---------------------------------------------------------+ */

| | |

void lcdcmd(unsigned char DATA) { RS=0;RW=0;EN=1; lcddata=DATA; EN=0; } /* +---------------------------------------------------------+ | Prototype: void lcddat (unsigned int) | | Return Type: void | | Arguments: unsigned int | | Description: Display data on LCD | | +---------------------------------------------------------+ */ void lcddat(unsigned char DATA) { RS=1;RW=0;EN=1; lcddata=DATA; EN=0; }

6-week Institutional training in Microcontroller & Embedded System

Page 28

/* +---------------------------------------------------------+ | Prototype: void initialize (void); | | Return Type: void | Arguments: None | | Description: Initialize LCD | +---------------------------------------------------------+ */ void initialize() { lcdcmd(0x30); delay(1); lcdcmd(0x38); delay(1); lcdcmd(0x0C); delay(1); lcdcmd(0x01); delay(1); lcdcmd(0x06); delay(1); } void display(unsigned char location,unsigned char *d) { lcdcmd(0x80|location); delay(1); while(*d) { lcddat(*d++); } } void main() { int p,q,r,s,t; unsigned char abc[2]; initialize(); while(1) { display(0x00,"Enter Data "); p = keypress(); delay(200); q = keypress(); t= p*10+q; sprintf(abc,"%d",t);

| | |

//Send data to serial port


Page 29

6-week Institutional training in Microcontroller & Embedded System

display(0xc0,abc);

delay(200); q = keypress(); sprintf(abc,"%d",q); display(0xc7,abc); //Send data to serial port

delay(200); display(0x00,"Select Opertn"); delay(200); display(0x00,"1.Add 2.Sub "); delay(200); display(0x00," 3.Mul 4.Div"); delay(200); r = keypress();

switch(r) {

case 1: display(0xc4,"+"); s = p+q; break; case 2: display(0xc4,"-"); s = p-q; break; case 3: display(0xc4,"*"); s = p*q; break; case 4:
6-week Institutional training in Microcontroller & Embedded System Page 30

display(0xc4,"/"); s = p/q; break; } delay(200); display(0x49,"="); sprintf(abc,"%d",s); display(0xcB,abc); delay(200); lcdcmd(0x01); } } HEX FILE
:03000000020F16D6 :0C0F1600787FE4F6D8FD75813D020B5C8D :100E2300456E74657220446174612000256400532B :100E3300656C656374204F706572746E00312E416A :100E4300646420322E537562200020332E4D756C5E :100E530020342E446976002B002D002A002F003DFC :010E6300008E :040EF2007FC87E0037 :100EF600E4FDFCD3ED9FEC9E5015E4FBFA0BBB0022 :0F0F0600010ABA04F8BBFCF50DBD00010C80E434 :010F150022B9 :100DC200C2A7D2A6D2A520A0057E007F012220A123 :100DD200057E007F042220A2057E007F0722D2A783 :100DE200C2A6D2A520A0057E007F022220A1057EF8 :100DF200007F052220A2057E007F082220A304E4B2 :100E0200FEFF22D2A7D2A6C2A520A0057E007F03A4 :100E12002220A1057E007F062220A2A47E007F0957 :010E220022AD :0B0F2200C290C291D2928F80C2922236 :0B0F2D00D290C291D2928F80C292221B :100E9B007F30120F227F017E00120EF67F38120F69 :100EAB00227F01120EF67F0C120F227F01120EF61B :100EBB00120F22120EF67F06120F227F01020EF680 :040E64007BFFE4FF2D :100E68008B2A8A2B892CEF4480FF120F227F017E68 :100E780000120EF6AB2AAA2BA92C120C97601305A8 :100E88002CE52C7002052B14F9120C97FF120F2D6C :030E980080E222D3 :100B5C00120E9B7A0E7923120E64120DC28E228F06 :100B6C0023752DFF752E0E752F2F85223085233181 :100B7C007B007A00792812085C7B007A0079287F48 :100B8C00C0120E68120EF2120DC28E248F25752D16 :100B9C00FF752E0E752F2F8524308525317B007A1D :100BAC0000792812085C7B007A0079287FC7120E26 :100BBC0068120EF27A0E7932120E64120EF27BFF6C

//Send data to serial port

6-week Institutional training in Microcontroller & Embedded System

Page 31

:100BCC007A0E7940E4FF120E68120EF27BFF7A0E59 :100BDC00794DE4FF120E68120EF2120DC2EE707413 :100BEC00EF24FE602314603A14604F240370657B7D :100BFC00FF7A0E795A7FC4120E68E5232525F52756 :100C0C00E5223524F526804C7BFF7A0E795C7FC477 :100C1C00120E68C3E5239525F527E5229524F526C4 :100C2C0080327BFF7A0E795E7FC4120E68AC24ADE5 :100C3C0025AE22AF23120CB080167BFF7A0E7960A2 :100C4C007FC4120E68AC24AD25AE22AF23120CC2A9 :100C5C008E268F27120EF27BFF7A0E79627F491255 :100C6C000E68752DFF752E0E752F2F852630852756 :100C7C00317B007A00792812085C7B007A00792895 :0B0C8C007FCB120E68120EF2020B5F0D :100C9700BB010689828A83E0225002E722BBFE025B :090CA700E32289828A83E493228E :100CB000EF8DF0A4A8F0CF8CF0A428CE8DF0A42E58 :020CC000FE2212 :100CC200C2D5EC30E709B2D5E4C39DFDE49CFCEE4D :100CD20030E715B2D5E4C39FFFE49EFE120D37C381 :100CE200E49DFDE49CFC8003120D3730D507C3E47C :060CF2009FFFE49EFE22BC :10080000E539242DF8E6053922782A300702782DBB :10081000E475F001120D8C020C972000EB7F2ED2B4 :10082000008018EF540F2490D43440D4FF30040BD0 :10083000EF24BFB41A0050032461FFE53A600215AB :100840003A053DE53D7002053C30070D782AE47518 :10085000F001120D8CEF020D25020ECB7403D207AE :100860008003E4C207F5398B2A8A2B892CE4F53AF8 :10087000F53CF53DE53A60077F2012083B80F575B1 :100880003BFFC201C200C202C203C205C206C208C7 :10089000120809FF700D3007057F0012084CAF3DAC :1008A000AE3C22B4255FC2D5C204120809FF24D091 :1008B000B40A00501A75F00A783A30D50508B6FF28 :1008C0000106C6A426F620D5047002D20380D924DE :1008D000CFB41A00EF5004C2E5D204020A4CD20190 :1008E00080C6D20080C0D20280BCD2D580BAD205E8 :1008F00080B47F2012083B2002077401B53A004003 :10090000F1120800FF12083B020874D208D20680D8 :1009100095120800FB120800FA120800F94A4B7001 :1009200006791D7A0B7BFF20022EE53A602A7E00B5 :100930008E82758300120CF860060EEE653B70F037 :10094000C2D5EBC0E0EAC0E0E9C0E0EE120A93D005 :10095000E0F9D0E0FAD0E0FB120C97FF60AAEBC000 :10096000E0EAC0E0E9C0E012083BD0E02401F9D0A1 :10097000E03400FAD0E0FBE53B0460DCD53BD980F5 :10098000877BFF7A0A798FD202809C791080027966 :1009900008C206C2088008D2D5790A8004790AC242 :1009A000D5E53B047002F53BE4FAFDFEFF120800BA :1009B000FC7B08200113120800FD7B1030000A1296 :1009C0000800FE120800FF7B20EC3382D592D55040 :1009D00013C3E43000069FFFE49EFEE42001039D64 :1009E000FDE49CFCE4CBF8C201EC700CCFCECDCC86 :1009F000E824F8F870F38017C3EF33FFEE33FEED11 :100A000033FDEC33FCEB33FB994002FB0FD8E9EBF1 :100A1000300105F8D0E0C448B201C0E00AEC4D4E08 :100A20004F78207B0070C2EAB53B0040BCC0E012AA :100A30000A95D0F0D0E0200104C4C0E0C4B201C0E7 :100A4000F0120824D0F0D5F0EB020874120D9C09C6 :100A50001153098B5808E24C08DE42098F4F099761 :0F0A60004409974908F743099D550981460981C3

6-week Institutional training in Microcontroller & Embedded System

Page 32

:100A6F00450981470B3D5008E62D08EA2E090D2B4D :100A7F0008EE23090B200B262A08A64800000905BB :100A8F003F3F3F00790AA2D5200314300509B91062 :100A9F00020404B9080104A2D52006025001042063 :100AAF0002689202B53A005034C0E07F203003193B :100ABF007F30A20272067205500F120AECC202C2F8 :100ACF0006C205C2087F30800F300503E9C0E0126F :100ADF00083B300503D0E0F9D0E0B53ACC3005172C :100AEF007F30B9100C12083B7F583004077F788095 :100AFF0003B9080312083B3002057F2D02083B7F24 :100B0F00202008F87F2B2006F322920280CF286E38 :100B1F00756C6C2900D2011208003001F8C20178FF :100B2F003A30D50108F60208A62D5043495812084D :100B3F00002403B405004001E4900B389312082CF5 :0D0B4F00743A12082CD203753A0402098B87 :100CF800BB010CE58229F582E5833AF583E02250B1 :100D080006E92582F8E622BBFE06E92582F8E222FA :0D0D1800E58229F582E5833AF583E4932214 :100D2500BB010689828A83F0225002F722BBFE01AD :020D3500F322A7 :100D3700BC000BBE0029EF8DF084FFADF022E4CCA0 :100D4700F875F008EF2FFFEE33FEEC33FCEE9DEC69 :100D5700984005FCEE9DFE0FD5F0E9E4CEFD22EDAF :100D6700F8F5F0EE8420D21CFEADF075F008EF2FF9 :100D7700FFED33FD4007985006D5F0F222C398FDEA :050D87000FD5F0EA2287 :100D8C00FAE6FB0808E6F925F0F618E6CA3AF62268 :100D9C00D083D082F8E4937012740193700DA3A3E6 :100DAC0093F8740193F5828883E4737402936860FA :060DBC00EFA3A3A380DFFA :100ECB00EFB40A07740D120ED6740A309811A89954 :100EDB00B8130CC2983098FDA899C298B811F63087 :070EEB0099FDC299F599225F :00000001FF

6-week Institutional training in Microcontroller & Embedded System

Page 33

Das könnte Ihnen auch gefallen