light snsor31
TRANSCRIPT
-
7/27/2019 Light Snsor31
1/50
SUMMER TRAINING PROJECT REPORTON
INTERFACING OF LIGHT SENSOR ROBOTWITH AN 8051 MICROCONTROLLER
TO
NORTHERN INDIA ENGINEERING COLLEGE,NEW DELHI
For the degree
Of Bachelor in TechnologyIn
Electronics & Communication
NORTHERN INDIA ENGINEERING COLLEGE,FC-26, SHASTRI PARK, NEW DELHI-53
MAY 2010
SUBMITTED BY:
SHRUTI AWASTHI 1311562808(ECE-S4)
-
7/27/2019 Light Snsor31
2/50
contents
1. Certificate2. Acknowledgement3. Requirements4. Introduction5. Data Table6. ICS7. Coding8. Conclusion
-
7/27/2019 Light Snsor31
3/50
CERTIFICATE
This is to certify that Project Report titled INTERFACING OF LIGHTSENSOR ROBOT WITH AN 8051 MICROCONTROLLER, which issubmitted by following students of Bachelors in Technology in Electronicsand Communication Engg. Of NORTHERN INDIA ENGINEERINGCOLLEGE, NEW DELHI, under my supervision.
Projecte:
SHRUTI AWASTHI 1311562808(ECE-S4)
Head of the department Supervisor/Guide
-
7/27/2019 Light Snsor31
4/50
ACKNOWLEDGEMENT
We feel highly privileged to express our deep sense of gratitude to allthose who helped us during our project work. We would like to expressour grateful thanks for the help and advice given to us byMS.POOJA, HOD ECE Dept., for their valuable guidance in our project.
We express our gratitude and reverence to the preceptor and projectGuide for his advice, guidance and support which helped us incompleting our project.
We are also highly thankful to the management of NORTHERN INDIAENGINEERING COLLEGE, for providing necessary facilities andinfrastructure.
-
7/27/2019 Light Snsor31
5/50
REQUIREMENTS
Computer Interfacing.
ADC (PCF 8591)
IC MAX232, LN - 293D
P89V51RD2FN microcontroller.
-
7/27/2019 Light Snsor31
6/50
INTRODUCTION
Microcontrollers are "special purpose computers." Microcontrollers do one thingwell. There are a number of other common characteristics that definemicrocontrollers. If a computer matches a majority of these characteristics, thenyou can call it a "microcontroller":
Microcontrollers are " embedded " inside some other device (often aconsumer product) so that they can control the features or actions of the product.Another name for a microcontroller, therefore, is "embedded controller."
Microcontrollers are dedicated to one task and run one specific program.The program is stored in (read-only memory) and generally does not change.
Microcontrollers are often low-power devices . A desktop computer isalmost always plugged into a wall socket and might consume 50 watts of electricity. A battery-operated microcontroller might consume 50 milliwatts.
A microcontroller has a dedicated input device and often (but not always)has a small LED or LCD display for output . A microcontroller also takes inputfrom the device it is controlling and controls the device by sending signals todifferent components in the device.
In our project we are using P89C51RD2 MICROCONTROLLER.
P89V51RD2FN MICROCONTROLLER
The P89C51RD2 is a low-power, high-performance CMOS 8-bitmicrocontroller with 8K bytes of Flash programmable and erasable read onlymemory (PEROM). The device is manufactured using Philips high-densitynonvolatile memory technology and is compatible with the industry-standardMCS-51 instruction set and pinout. The on-chip Flash allows the program memoryto be reprogrammed in-system or by a conventional nonvolatile memory
-
7/27/2019 Light Snsor31
7/50
programmer. By combining a versatile 8-bit CPU with Flash on a monolithic chip,the Philips P89V51RD2FN is a powerful microcomputer which provides a highly-flexible and cost-effective solution to many embedded control applications.
The P89V51RD2FN provides the following standard features: 64 kBflash microcontroller with 1024 byte RAM; Clock type: 12-clk (6-clk opt.) ;External interrupt: 2; I/O pins: 32 ; Memory type: FLASH ; Number of pins: 40 ;Operating frequency: 0~20/40 (6clk/12clk) MHz; Operating temperature: -40~85Cel; Power supply: 4.5~5.5V ; Program security: yes; Serial interface: UART ;Series: 80C51 family
PIN DIAGRAM
-
7/27/2019 Light Snsor31
8/50
PIN DESCRIPTION
-
7/27/2019 Light Snsor31
9/50
VCC:Supply voltage.
GND:Ground.
Port 0:Port 0 is an 8-bit open-drain bi-directional I/O port. As an output port, each pin cansink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used ashigh impedance inputs.Port 0 may also be configured to be the multiplexed low order address/data busduring accesses to external program and data memory. In this mode P0 has internal
pull ups.Port 0 also receives the code bytes during Flash programming, and outputs thecode bytes during program verification. External pull ups are required during
program verification.
Port 1:Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1 pins are
pulled high by the internal pull-ups when 1s are written to them and can be usedas inputs in this state. As inputs, Port 1 pins that are externally pulled LOW willsource current (I IL) because of the internal pull-ups. P1.5, P1.6, P1.7 have high
current drive of 16 mA. Port 1 also receives the low-order address bytes during theexternal host mode programming and verification.
Port 2:Port 2 is an 8-bit bi-directional I/O port with internal pull ups. The Port 2 output
buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins theyare pulled high by the internal pull ups and can be used as inputs. As inputs, Port 2
pins that are externally being pulled low will source current (IIL) because of theinternal pull ups. Port 2 emits the high-order address byte during fetches fromexternal program memory and during accesses to external data memory that use16-bit addresses. In this application, it uses strong internal pull ups when emitting1s. During accesses to external data memory that use 8-bit addresses (MOVX @RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 alsoreceives the high-order address bits and some control signals during Flash
programming and verification.
-
7/27/2019 Light Snsor31
10/50
Port 3:Port 3 is an 8-bit bi-directional I/O port with internal pull ups. The Port 3 output
buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins theyare pulled high by the internal pull ups and can be used as inputs. As inputs, Port 3
pins that are externally being pulled low will source current (IIL) because of the pull ups. Port 3 also serves the functions of various special features of theAT89C51 as listed below:
Port 3 also receives some control signals for Flash programming and verification.
RST:Reset input. A high on this pin for two machine cycles while the oscillator isrunning resets the device.
ALE/PROG:Address Latch Enable output pulse for latching the low byte of the address duringaccesses to external memory. This pin is also the program pulse input (PROG)during Flash programming. In normal operation ALE is emitted at a constant rateof 1/6 the oscillator frequency, and may be used for external timing or clocking
purposes. Note, however, that one ALE pulse is skipped during each access toexternal Data Memory.
If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH.With the bit set, ALE is active only during a MOVX or MOVC instruction.Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effectif the microcontroller is in external execution mode.
PSEN:
-
7/27/2019 Light Snsor31
11/50
Program Store Enable is the read strobe to external program memory. When themicrocontroller is executing code from external program memory, PSEN isactivated twice each machine cycle, except that two PSEN activations are skippedduring each access to external data memory.EA/VPP:External Access Enable. EA must be strapped to GND in order to enable the deviceto fetch code from external program memory locations starting at 0000H up toFFFFH. Note, however, that if lock bit 1 is programmed, EA will be internallylatched on reset.EA should be strapped to VCC for internal program executions. This pin alsoreceives the 12-volt programming enable voltage(VPP) during Flash programming,for parts that require12-volt VPP.
XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock operatingcircuit.
XTAL2:Output from the inverting oscillator amplifier.
DATA TABLE:
BLOCK DIAGRAM OF IC:
-
7/27/2019 Light Snsor31
12/50
RECOMMENDED OPERATING CONDITIONS:
OPERATING RANGE:
-
7/27/2019 Light Snsor31
13/50
RELIABILITY CHARACTERISTICS:
POWER-UP TIMING:
-
7/27/2019 Light Snsor31
14/50
PIN IMPEDANCE:
STATIC CHARACTERISTICS:
-
7/27/2019 Light Snsor31
15/50
SPECIAL FUNCTION REGISTERS:
-
7/27/2019 Light Snsor31
16/50
-
7/27/2019 Light Snsor31
17/50
-
7/27/2019 Light Snsor31
18/50
-
7/27/2019 Light Snsor31
19/50
ICS
1. MAX 232
INTRODUCTION:
The MAX232 is a dual driver/receiver that includes a capacitive voltage generator to supply TIA/EIA-232-FVoltage levels from a single 5-V supply. Each receiver converts TIA/EIA-232-F
inputs to 5-V TTL/CMOS levels.These receivers have a typical threshold of 1.3 V, a typical hysteresis of 0.5 V, andcan accept 30-V inputs.Each driver converts TTL/CMOS input levels into TIA/EIA-232-F levels.
They aresupplied in 16
pin plastic DIP packages with acopper leadframe to reducethermal
resistance.
PIN CONNECTION:
-
7/27/2019 Light Snsor31
20/50
FUNCTION TABLE:
-
7/27/2019 Light Snsor31
21/50
2. PCF8591
INTRODUCTION
-
7/27/2019 Light Snsor31
22/50
The PCF8591 is a single-chip, single-supply low power 8-bit CMOS data
acquisition device with four analog inputs, one analog output and a serial I2C-businterface. Three address pins A0, A1 and A2 are used for programming thehardware address, allowing the use of up to eight devices connected to the I2C-buswithout additional hardware. Address, control and data to and fromthe device are transferred serially via the two-line bidirectional I2C-bus.The functions of the device include analog input multiplexing, on-chip track andhold function, 8-bit analog-to-digital conversion and an 8-bit digital-to-analogconversion. The maximum conversion rate is given by the maximum speed of theI2C-bus
FEATURES
Single power supply Operating supply voltage 2.5 V to 6 V Low standby current Serial input/output via I2C-bus Address by 3 hardware address pins Sampling rate given by I2C-bus speed 4 analog inputs programmable as single-ended or differential inputs Auto-incremented channel selection Analog voltage range from VSS to VDD On-chip track and hold circuit 8-bit successive approximation A/D conversion Multiplying DAC with one analog output
APPLICATIONS
Closed loop control systems
-
7/27/2019 Light Snsor31
23/50
Low power converter for remote data acquisition Battery operated equipment Acquisition of analog values in automotive, audio and TV applications.
PIN CONNECTION:
Block Diagram:
-
7/27/2019 Light Snsor31
24/50
The block diagram structure of this Light Sensor Robot circuit can be shown as
-
7/27/2019 Light Snsor31
25/50
Motor I
Motor II
3.Motor Driver(IC-293D):
The Device is a monolithic integrated high voltage,high current four channel driver designed to acceptstandard DTL or TTL logic levels and driveinductive loads (such as solenoids, DC motors) and
Sensor array
Pcf8591A/D, D/AConverter
Microcontroller
8051Motor driver
L293d
M
111Analog
signal
Binary signalAction toperform
-
7/27/2019 Light Snsor31
26/50
switching power transistors. To simplify use as two bridges each pair of channels is equipped with anenable input. A separate supply input is provided for the logic, allowing operation at a lower voltage andinternal clamp diodes are included. This device issuitable for use in switching applications atfrequencies up to 5 kHz. The L293D is assembled ina 16 lead plastic package which has 4 center pinsconnected together and used for heat sinking.
600mA output current capability per channel1.2A peak output current per channelEnable facilityOver temperature protectionLogical 0 input voltage up to 1.5VHigh noise immunityInternal clamping diodes
The block diagram is given as:
-
7/27/2019 Light Snsor31
27/50
PIN DAIGRAM LM-293 D: (motor driver)
-
7/27/2019 Light Snsor31
28/50
Brain: The 8051 microcontroller
-
7/27/2019 Light Snsor31
29/50
Microcontroller & Microprocessor :Both are the digital structure that can perform some operation or action depending upon thefirmware program (loaded into its memory and a clock circuit.They are also called general purpose digital computer or a computer on a chip. Both are made
by same people, and are sold to same type of designers and programmers but there are
differences b/w the two.
Difference b/w Microcontroller and Microprocessor Microprocessor is a simple chip consist of Arithmetic logic unit (ALU), programcounter(PC), a stack pointer (SP), some working registers, a clock timing circuit, andinterrupt circuits.
Fig.1-6 Block diagram of microprocessor
Whereas microcontroller is a microprocessor chip along with memory(ROM & RAM) and I/Odevices(to take i/p and give o/p).
Arithmetic and logic unitAccumulator working register(s)
Program counter stack pointer
Clock circuit interrupt circuits
Arithmetic and logic unitAccumulator working register(s)
Program counter stack pointer
Clock circuit interrupt circuits
Internal RAMInternal ROM
i/o port i/o port i/o port
-
7/27/2019 Light Snsor31
30/50
Fig.1-7 A Block Diagram of a Microcontroller
CODING
#include #include#include
sbit scl=P0^1;sbit sda=P0^0;sbit a7=ACC^7; //define acc in bitssbit a6=ACC^6;sbit a5=ACC^5;sbit a4=ACC^4;sbit a3=ACC^3;sbit a2=ACC^2;sbit a1=ACC^1;sbit a0=ACC^0;
sbit l_en= P1^0;sbit ldc1= P1^1;
sbit ldc2= P1^2;sbit rdc1= P1^3;sbit rdc2= P1^4;sbit r_en= P1^5;/*
-
7/27/2019 Light Snsor31
31/50
sbit l_en= P1^0;sbit ldc1= P1^1;sbit ldc2= P1^2;
sbit rdc1= P1^3;sbit rdc2= P1^4;sbit r_en= P1^5; */
bit c=0,i;bit b;bit flag;/* i2c protocal routine*/void start();void stop();void shout();unsigned char shin();void nak();
void ack();void read_ch0();void read_ch1();void wait_1sec();void init_uart();void init_timer1();void display_acc();void tx();
unsigned char temp,temp1,temp2,cnt,value1,value2;
-
7/27/2019 Light Snsor31
32/50
code unsigned charascii[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
/*--------------------------------*/void main(void)
{l_en=r_en=1;
init_timer1();init_uart();printf("test\n");
// while(1);up: read_ch0();
read_ch1();
if(value1 > value2){
ldc1=1;ldc2=0;rdc1=0;rdc2=0;
}
if(value2 > value1){
ldc1=0;ldc2=0;rdc1=0;rdc2=1;
-
7/27/2019 Light Snsor31
33/50
}// P0=ACC;// display_acc();
// printf("%xvalue1=\n",value1);// printf("%xvalue2=\n",value2);
wait_1sec();// wait_1sec();
goto up;
}//end main/*-----------------------------------*/void init_uart(){
SCON=0x52;}
//-----------------------------------void init_timer1(){
TMOD|=0X20;TH1=0Xfd;TR1=1;
}//--------------------------void tx(){
while(!TI){
-
7/27/2019 Light Snsor31
34/50
}SBUF=ACC;TI=0;
}//---------------------------------------void display_acc(){
temp2=ACC;ACC=ACC
-
7/27/2019 Light Snsor31
35/50
{unsigned int x,z;
for(x=0;x
-
7/27/2019 Light Snsor31
36/50
ACC=0x90; //save copy of deviceaddress(90)
shout(); //send device address
if(c){goto x300; //abort if no acknowledge}ACC=0x00; //select channel 0 (addr 00)shout();if(c){goto x300; //abort if no acknowledge}
start(); //restartif(c)
{goto x300; //abort if no acknowledge}
ACC=0x91; //save copy of device address(91)shout(); // send device addressif(c){goto x300; //abort if no acknowledge}shin(); //dummy readack(); //acknowledge byte
-
7/27/2019 Light Snsor31
37/50
value1= shin(); // read bytenak(); //no acknowledge bytec=0; //clear error flag
//x310:stop();
x300:i=0;
}//--------------------------------------------------------------------------------
void read_ch1(){
start();if(c)
{goto x301; // abort if bus not available}ACC=0x90; //save copy of device
address(90)shout(); //send device addressif(c){goto x301; //abort if no acknowledge}ACC=0x01; //select channel 0 (addr 00)shout();
-
7/27/2019 Light Snsor31
38/50
if(c){goto x301; //abort if no acknowledge
}
start(); //restartif(c){goto x301; //abort if no acknowledge}
ACC=0x91; //save copy of device address(91)shout(); // send device addressif(c){goto x301; //abort if no acknowledge
}shin(); //dummy readack(); //acknowledge byte
value2= shin(); // read bytenak(); //no acknowledge bytec=0; //clear error flag
//x310:stop();
x301:i=0;
}
-
7/27/2019 Light Snsor31
39/50
/*------------------------------------*/
void start(){
sda=1;scl=1;
if(!sda)goto x40;
if(!scl)goto x40;
_nop_();sda=0;
_nop_(); _nop_();
_nop_(); _nop_(); _nop_(); _nop_();
scl=0;c=0;
goto x41;
x40:c=1;
x41:
-
7/27/2019 Light Snsor31
40/50
b=0;
}
/*----------------------------------*/void stop(){
sda=0; _nop_(); _nop_();
scl=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_();
sda=1;
}//end stop/*----------------------------------*/void shout(){
sda=a7; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_();
-
7/27/2019 Light Snsor31
41/50
_nop_();scl=0;
sda=a6; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
sda=a5; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
sda=a4; _nop_();scl=1;
_nop_(); _nop_();
-
7/27/2019 Light Snsor31
42/50
_nop_(); _nop_(); _nop_();
scl=0;
sda=a3; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
sda=a2;
_nop_();scl=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
sda=a1; _nop_();scl=1;
-
7/27/2019 Light Snsor31
43/50
_nop_(); _nop_(); _nop_();
_nop_(); _nop_();scl=0;
sda=a0; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
/*----------------------------------*/
/* acknowlodgement */
sda=1; _nop_(); _nop_();scl=1;
_nop_(); _nop_(); _nop_();
-
7/27/2019 Light Snsor31
44/50
_nop_(); _nop_();c=sda;
scl=0;
}//end shout/*----------------------------------*/unsigned char shin(){
sda=1; _nop_(); _nop_();
scl=1; _nop_(); _nop_();
a7=sda; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
a6=sda;
-
7/27/2019 Light Snsor31
45/50
_nop_();scl=1;
_nop_();
_nop_(); _nop_(); _nop_(); _nop_();scl=0;
a5=sda; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_();
_nop_();scl=0;
a4=sda; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
-
7/27/2019 Light Snsor31
46/50
a3=sda; _nop_();
scl=1; _nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;
a2=sda; _nop_();scl=1;
_nop_(); _nop_();
_nop_(); _nop_(); _nop_();scl=0;
a1=sda; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_();
-
7/27/2019 Light Snsor31
47/50
_nop_();scl=0;
a0=sda; _nop_();scl=1;
_nop_(); _nop_(); _nop_(); _nop_(); _nop_();scl=0;return(ACC);
}//end shin/*-----------------------------------------*/// Clock out an acknowledge bit (low).
//SCL expected low on entry. Return with SCL, SDAlow.
void ack(){
sda=0; // ACK bit _nop_(); // enforce SCL low and
data setup _nop_();scl=1; // raise clock
-
7/27/2019 Light Snsor31
48/50
_nop_(); // enforce SCL high _nop_(); _nop_();
_nop_();scl=0; // drop clock _nop_();
}
//----------------------------------------------------------------------//Clock out a negative acknowledge bit (high).//SCL expected low on entry. Return with SCL low,SDA high.void nak(){
sda=1; // NAK bit
_nop_(); // enforce SCL low anddata setup _nop_();scl=1; // raise clock
_nop_(); // enforce SCL high _nop_(); _nop_(); _nop_(); _nop_();scl=0; // drop clock
_nop_();}
-
7/27/2019 Light Snsor31
49/50
//-------------------------------------
CONCLUSIONThe project was successfully completed after a lot of efforts and work hours. This
project underwent compiling, debugging, removing errors, make it bug free,adding more facilities & interactivity, make it more reliable and user friendly.
-
7/27/2019 Light Snsor31
50/50
Guidance was taken from faculty; help from the friend were accepted at the various project development phases. Many books related to controlling of microcontroller were referred to get the desired results.