• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Micro Controller 8051 of Speedo Meter using KEIL Code
 

Micro Controller 8051 of Speedo Meter using KEIL Code

on

  • 2,964 views

 

Statistics

Views

Total Views
2,964
Views on SlideShare
2,964
Embed Views
0

Actions

Likes
1
Downloads
146
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Micro Controller 8051 of Speedo Meter using KEIL Code Micro Controller 8051 of Speedo Meter using KEIL Code Document Transcript

    • SPEEDO METER RVCE MICROCONTROLLERA microcontroller is a small computer on a single integrated circuit containing a processorcore, memory, and programmable input/output peripherals. Program memory in the form ofNOR flash or OTP ROM is also often included on chip, as well as a typically small amountof RAM. Microcontrollers are designed for embedded applications, in contrast to themicroprocessors used in personal computers or other general purpose applications.Microcontrollers are used in automatically controlled products and devices, such asautomobile engine control systems, implantable medical devices, remote controls, officemachines, appliances, power tools, toys and other embedded systems. By reducing the sizeand cost compared to a design that uses a separate microprocessor, memory, and input/outputdevices, microcontrollers make it economical to digitally control even more devices andprocesses. Mixed signal microcontrollers are common, integrating analog components neededto control non-digital electronic systems.Some microcontrollers may use four-bit words and operate at clock rate frequencies as low as4 kHz, for low power consumption (milli watts or microwatts). They will generally have theability to retain functionality while waiting for an event such as a button press or otherinterrupt; power consumption while sleeping (CPU clock and most peripherals off) may bejust nanowatts, making many of them well suited for long lasting battery applications. Othermicrocontrollers may serve performance-critical roles, where they may need to act more likea digital signal processor (DSP), with higher clock speeds and power consumptionA microcontroller can be considered a self-contained system with a processor, memory andperipherals and can be used as an embedded system. The majority of microcontrollers in useDepart of CSE 1
    • SPEEDO METER RVCEtoday are embedded in other machinery, such as automobiles, telephones, appliances, andperipherals for computer systems. These are called embedded systems. While someembedded systems are very sophisticated, many have minimal requirements for memory andprogram length, with no operating system, and low software complexity.Typical input and output devices include switches, relays, solenoids, LEDs, small or customLCD displays, radio frequency devices, and sensors for data such as temperature, humidity,light level etc. Embedded systems usually have no keyboard, screen, disks, printers, or otherrecognizable I/O devices of a personal computer, and may lack human interaction devices ofany kind.MICROCONTROLLER FEATURES: 1. (It is similar to 8051 microcontroller i.e. having same instruction set, pin configuration, architecture). 2. It is also 8-bit microcontroller. Its cost is only Rs10 more than that of 8051. 3. It uses EPROM (erasable programmable read only memory) or FLASH memory. 4. It is multiple time programmable (MTP). The AT89C51 is a low-power, high-performance CMOS 8-bit microcomputer with 4Kbytes of Flash programmable and erasable read only memory (PEROM). The device ismanufactured using Atmel’s high-density nonvolatile memory technology and is compatiblewith the industry-standard MCS-51 instruction set and pinout. The on-chip Flash allows theprogram memory to be reprogrammed in-system or by a conventional nonvolatile memoryprogrammer. By combining a versatile 8-bit CPU with Flash on a monolithic chip, the AtmelAT89C51 is a powerful microcomputer which provides a highly-flexible and cost-effectivesolution to many embedded control applications.The AT89C51 provides the following standard features: 4K bytes of Flash, 128 bytes ofRAM, 32 I/O lines, two 16-bit timer/counters, a five vector two-level interrupt architecture, afull duplex serial port, on-chip oscillator and clock circuitry. In addition, the AT89C51 isdesigned with static logic for operation down to zero frequency and supports two softwareselectable power saving modes.The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port andinterrupt system to continue functioning. The Power-down Mode saves the RAM contents butfreezes the oscillator disabling all other chip functions until the next hardware reset.Depart of CSE 2
    • SPEEDO METER RVCE How to make a digital speedometer using microcontrollerThe 8051 may not be the best for this task, in that you can get types with lower power andsmall size (8/16 pin dip etc). That is not the only family, but it is popular with hobbyists sothere are plenty of software examples on the internet. You can use this software as anexample for other microprocessors too. The first decision is selecting a display that suits yourmicroprocessor and hardware.The most basic concept is a frequency counter. Use a magnetic pickup from the wheel. Thiscan be mounted on a spoke. You can use a fixed coil of wire or a hall effect device to detectthe magnet. This can be mounted on a wheel fork, so the spoke passes close by. The coilvoltage will need signal processing, like voltage limiting, an op-amp and filter, to convert todigital pulses for the Processor input.You could use an optical method instead, using LED and reflection from spokes.Count the pulses, it is best to measure period between pulses to avoid having to count for nseconds to get a meaningful result. A problem to overcome is converting this to speed, as youwill have to implement maths (multiply and divide), or use a lookup table. Use a high levellanguage like C or basic and you have maths easily. The driving of an LCD display dependson which type you have. You could look that up on the internet.For odometer, just count the impulses and totalize them, then multiply by the factor to getmiles, km etc. You may want to add some sort of push button to the I/O to control thedisplay.The power supply may be a battery, if the microprocessor uses little power, or if you use thebike power (whatever it is) it will need attention to protect everything from spikes in voltage.Good filtering before any regulator. A pic micro is the way to go. Check out www.microchip.com You should find some ideasand details in their applications section, and you can even procure a free sample or two oftheir controllers on their website. An easy way of counting the pulses from the wheel that will not affect tire balance might beto use a photo sensor. A simple infrared led and photo transistor, and you wont need muchcircuitry to condition the pulse back to the micro controller.Depending on the color and reflectivity of your tires rim, you would either attach a smallsection of flat black tape or a section of reflective tape to the rim in one spot. The photosensor could be set up to either count a pulse of reflected light as a signal or the absence of alight signal as the count.Basically count the revolutions of the wheel, calculate the wheels effective circumference,and you can compute the distance traveled per pulse. Using the micro controllers oscillator asa time base, you can calculate the number of pulses per unit of time, and using the distancetraveled per pulse, figure out the speed.Depart of CSE 3
    • SPEEDO METER RVCELCD interfacing with Microcontrollers tutorial►IntroductionThe most commonly used Character based LCDs are based on Hitachis HD44780 controlleror other which are compatible with HD44580. In this tutorial, we will discuss about characterbased LCDs, their interfacing with various microcontrollers, various interfaces (8-bit/4-bit),programming, special stuff and tricks you can do with these simple looking LCDs which cangive a new look to your application.►Pin DescriptionThe most commonly used LCDs found in the market today are 1 Line, 2 Line or 4 Line LCDswhich have only 1 controller and support at most of 80 charachers, whereas LCDs supportingmore 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 pinsare extra in both for back-light LED connections). Pin description is shown in the tablebelow. Figure 1: Character LCD type HD44780 Pin diagram Pin No. Name Description Pin no. 1 VSS Power supply (GND) Pin no. 2 VCC Power supply (+5V) Pin no. 3 VEE Contrast adjust 0=Instruction input Pin no. 4 RS 1 = Data input 0 = Write to LCD module Pin no. 5 R/W 1 = Read from LCD module Pin no. 6 EN Enable signal Pin no. 7 D0 Data bus line 0 (LSB) Pin no. 8 D1 Data bus line 1 Pin no. 9 D2 Data bus line 2 Pin no. 10 D3 Data bus line 3 Pin no. 11 D4 Data bus line 4 Pin no. 12 D5 Data bus line 5Depart of CSE 4
    • SPEEDO METER RVCE Pin no. 13 D6 Data bus line 6 Pin no. 14 D7 Data bus line 7 (MSB) Table 1: Character LCD pins with 1 Controller Pin No. Name Description Pin no. 1 D7 Data bus line 7 (MSB) Pin no. 2 D6 Data bus line 6 Pin no. 3 D5 Data bus line 5 Pin no. 4 D4 Data bus line 4 Pin no. 5 D3 Data bus line 3 Pin no. 6 D2 Data bus line 2 Pin no. 7 D1 Data bus line 1 Pin no. 8 D0 Data bus line 0 (LSB) Pin no. 9 EN1 Enable signal for row 0 and 1 (1stcontroller) 0 = Write to LCD module Pin no. 10 R/W 1 = Read from LCD module 0 = Instruction input Pin no. 11 RS 1 = Data input Pin no. 12 VEE Contrast adjust Pin no. 13 VSS Power supply (GND) Pin no. 14 VCC Power supply (+5V) Pin no. 15 EN2 Enable signal for row 2 and 3 (2ndcontroller) Pin no. 16 NC Not Connected Table 2: Character LCD pins with 2 Controller Usually these days you will find single controller LCD modules are used more in themarket. So in the tutorial we will discuss more about the single controller LCD, the operationand everything else is same for the double controller too. Lets take a look at the basicinformation which is there in every LCD.►Sending Data to LCDTo send data we simply need to select the data register. Everything is same as the commandroutine. Following are the steps:  Move data to LCD port  select data register  select write operation  send enable signal  wait for LCD to process the dataKeeping these steps in mind we can write LCD command routine as.Depart of CSE 5
    • SPEEDO METER RVCECODE:;Ports used are same as the previous example;Routine to send data (single character) to LCDLCD_senddata: mov LCD_data,A ;Move the command to LCD port setb LCD_rs ;Selected data register clr LCD_rw ;We are writing setb LCD_en ;Enable H->L clr LCD_en acall LCD_busy ;Wait for LCD to process the data ret ;Return from busy routine; Usage of the above routine; A will carry the character to display on LCD; e.g. we want to print A on LCD;; mov a,#A ;Ascii value of A will be loaded in accumulator; acall LCD_senddata ;Send dataThe equivalent C code Keil C compiler. Similar code can be written for SDCC.CODE:void LCD_senddata(unsigned char var){ LCD_data = var; //Function set: 2 Line, 8-bit, 5x7 dots LCD_rs = 1; //Selected data register LCD_rw = 0; //We are writing LCD_en = 1; //Enable H->L LCD_en = 0; LCD_busy(); //Wait for LCD to process the command}// Using the above function is really simple// we will pass the character to display as argument to function// e.g.//// LCD_senddata(A);Depart of CSE 6
    • SPEEDO METER RVCEInductive Proximity SensorInductive Proximity Sensors Inductive proximity sensors operate under the electrical principle of inductance.Inductance is the phenomenon where a fluctuating current, which by definition has amagnetic component, induces an electromotive force (emf) in a target object. To amplify adevice’s inductance effect, a sensor manufacturer twists wire into a tight coil and runs acurrent through it. An inductive proximity sensor has four components; The coil, oscillator,detection circuit and output circuit. The oscillator generates a fluctuating magnetic field the shape of a doughnut aroundthe winding of the coil that locates in the device’s sensing face. When a metal object movesinto the inductive proximity sensor’s field of detection, Eddy circuits build up in the metallicobject, magnetically push back, and finally reduce the Inductive sensor’s own oscillationfield. The sensor’s detection circuit monitors the oscillator’s strength and triggers an outputfrom the output circuitry when the oscillator becomes reduced to a sufficient level.Depart of CSE 7
    • SPEEDO METER RVCEInterfacing of 8051 micro controller with Stepper motorA Unipolar Stepper Motor is rotated by energizing the stator coils in a sequence. In unipolarstepper, the direction of current in stator coils is not required to be controlled by the drivingcircuit. Just applying the voltage signals across the motor coils or motor leads in a sequenceis sufficient to drive the motor.A two phase unipolar stepper motor has a total of six wires/leads of which four are end wires(connected to coils) and two are common wires. The color of common wires in the steppermotor used here is Green. Each common wire is connected to two end leads thus forming twophases. The end leads corresponding to each phase have to be identified.In some cases, when the leads cannot be directly identified in the motor, the identification ofendpoints and common points can be done by measuring the resistance between the leads.The leads of different phase will show open circuited condition with respect to each other.This way the leads corresponding to different phase can be separated. The resistance betweenany two end points of same phase will be twice the resistance between a common point andan end point. This way the common and end points of both the phases can be identified.Depart of CSE 8
    • SPEEDO METER RVCETo work with the unipolar stepper motor, the common points are connected to either Groundor Vcc and the end points of both the phases are usually connected through the port pins ofa microcontroller. In present case the common (Green) wires are connected to Vcc. The endpoints receive the control signals as per the controllers output in a particular sequence todrive the motor.Depart of CSE 9
    • SPEEDO METER RVCE Source codeMAIN.SRC#include <test_header.h>ORG 0000HLJMP MAINSTR1: DB "COUNTER =$"STR2: DB "DISTANCE=$"MAIN: LCALL INIT_RVCARD LCALL LCD_INIT MOV A,#00H MOV DPTR,#STR1 LCALL LCD_PUTS_LINE1 MOV DPTR,#STR2 LCALL LCD_PUTS_LINE2SENSOR_RELAY11: ; this is to demonostrate the use of SENSOR and RELAY ; P1.7 -- connected to Relay input ; P3.7 -- connected to Opto Isolator input i.e sensor input ; this program reads from the sensor and controls ac device connected to relay ; continuously and it is of indefinite loopAAGAIN:JB P3.7,AAGAIN /*MOV A,#25H MOV B,#65H MUL AB MOV P0,B LCALL DELAY MOV P0,A*/REL_ON1: MOV P0,#0FFH ADD A,#01 MOV R3,A PUSH 0E0H LCALL BINARY_TO_HEX MOV A,#8DH LCALL LCD_CWRITE MOV A,R2 LCALL LCD_DWRITE MOV A,R1 LCALL LCD_DWRITE MOV A,R0 LCALL LCD_DWRITEDepart of CSE 10
    • SPEEDO METER RVCE MOV A,#02 //2*3.142*r(radius)*f(rotations per second) MOV B,#01 //B contains radius 1 cm MUL AB MOV R4,A MOV A,#03// ASSUMING PI VALUE AS 3 MOV B,R3 //NO OF ROTATIONS PER SECOND MUL AB MOV B,R4 MUL AB LCALL BINARY_TO_HEX MOV A,#8DH ADD A,#40H LCALL LCD_CWRITE MOV A,R2 LCALL LCD_DWRITE MOV A,R1 LCALL LCD_DWRITE MOV A,R0 LCALL LCD_DWRITE POP 0E0H //LCALL DISP_DISTAGAIN1: JNB P3.7,AGAIN1 SJMP SENSOR_RELAY11 SJMP $ ENDDepart of CSE 11
    • SPEEDO METER RVCESTEPPER.SRC#include <test_header.h>ORG 0000HLJMP AASTR1: DB "STEPPER MOTOR$"AA: LCALL INIT_RVCARD LCALL LCD_INIT MOV DPTR,#STR1 LCALL LCD_PUTS_LINE1STEP: MOV A,#88H MOV R0,#100 ;100 steps in the clockwise directionCONT: MOV P0,A LCALL DELAYMS LCALL DELAYMS RR A ;rotate the pattern in clockwise direction //LCALL SENSOR_RELAY11 DJNZ R0,CONT SJMP STEP //LCALL SENSOR_RELAY11*// SJMP $ ENDDepart of CSE 12