8051projectreport.pdf

Embed Size (px)

Citation preview

  • 8/14/2019 8051projectreport.pdf

    1/9

    8051 Project:

    Automatic Lighting and Visitor Counter

    Andrew Herzog

    Richard Baker

    December 13, 2007

    CMPET 211

  • 8/14/2019 8051projectreport.pdf

    2/9

    Executive Summary

    The objective of the project was to create a circuit with an 8051 microcontroller that

    sensed when an object passed through an infrared receivers receive path to automatically turn on

    lights and count how many times the receive path was blocked.

    Discussion

    To complete the project several smaller circuits were needed to be designed and

    constructed. The project needed a circuit to pulse an infrared LED at 38 kHz, a circuit to receive

    the infrared signal, a seven segment LED display circuit, an auto-lighting circuit, and aprogramming circuit. The project also required code to be written to the 8051 microcontroller to

    combine all the smaller circuits into an operational system.

    The 38 kHz generator, Fig. 1-1, was major factor in getting the infrared receiver tooperate correctly. A 555 timing chip was used to output a squarewave at 38 kHz for an infrared

    LED. The generator needed to be completely isolated from the rest of the circuit because it wasfound that the infrared receivers output was similar to Fig. 1-2 at a frequency of 38 kHz. Thereceiver needed to output a high until an object blocked the infrared signal when it would output

    a low.

    Fig. 1-1, 38 kHz Generator

    Fig. 1-2, Infrared Receiver Output

  • 8/14/2019 8051projectreport.pdf

    3/9

    The infrared receiver, Fig 1-3, was a

    very basic component of the project. 5 V wasconnected to pin three, ground connected to

    pin two, and the output was on pin one which

    was connected to pin twelve of the 8051. The

    receiver output a high as long as nothing wasblocking the 38 kHz infrared signal. When an

    object blocked the signal, the receiver output alow, while being monitored by the 8051.

    Fig. 1-3, Infrared Receiver Connections

    Fig. 1-4, Infrared Transmitter and Receiver

  • 8/14/2019 8051projectreport.pdf

    4/9

    The seven segment LED display was very similar to the Interfacing the DS89C430 witha 7-Segment LED Display lab that was done in the past. A couple problems occurred involving

    brightness and segments dropping out, those problems will be explained further in Problems

    Encountered.

    Fig. 1-5, 7 Segment LED Display Connections

    The auto-lighting portion of the project, Fig. 1-6, required knowledge learned in EET210, the use of a transistor, LEDs, and a relay. The transistor had to be used as a switch, so using

    the rated values from the relay, coil pick-up voltage = 9 V and coil current = 30 mA, and the

    transistors hfeof 250, the base resistor of the circuit was found using EQ. 1 and EQ. 2, wherehard saturation equals 2 IB.

    EQ. 1, IB EQ. 2, RB

    A resistor value was also calculated to limit the current in the LEDs. Using the LEDscurrent rating, 20 mA, and voltage drop, 1.6 V, the resistance value was calculated to be around

    80 using Ohms Law.

    mAmA

    h

    II

    fe

    CB

    12.250

    30=== =

    =

    = k

    mA

    VV

    I

    VVR

    B

    BB 9.17

    24.*2

    7.5

    2

    7.

  • 8/14/2019 8051projectreport.pdf

    5/9

    Fig. 1-6, Auto-Lighting Connections

    The programming part of the circuit, Fig. 1-7, was the same circuit used all semester to

    program the 8051.

    Fig. 1-7, 8051 Programming

  • 8/14/2019 8051projectreport.pdf

    6/9

    Fig. 1-8, Whole Schematic

  • 8/14/2019 8051projectreport.pdf

    7/9

    Assembly code was written to the 8051 microcontroller so that all the circuits could be

    combined into one complete system. The code written for the 8051 can be seen in Fig. 1-9.

    Fig. 1-9, Project Code

    ORG 0

    TOP: CLR P1.1 AGAIN: JB P3.2, AGAINCLR P1.3 LJMP TOP

    ACALL DELAY

    AGAIN0: JB P3.2, AGAIN0

    MOV P1, #00001010B

    MOV P2, #01011111B DELAY:

    CLR P2.6 H1: MOV R4, #100

    SETB P2.6 H2: MOV R3, #100

    ACALL DELAY H3: DJNZ R3, H3

    AGAIN1: JB P3.2, AGAIN1 DJNZ R4, H2

    MOV P1, #00001010B DJNZ R5, H1

    MOV P2, #01010000B RET

    ACALL DELAY

    AGAIN2: JB P3.2, AGAIN2 END

    MOV P1, #00001010B

    MOV P2, #01101101BACALL DELAY

    AGAIN3: JB P3.2, AGAIN3

    MOV P1, #00001010B

    MOV P2, #01111001B

    ACALL DELAY

    AGAIN4: JB P3.2, AGAIN4

    MOV P1, #00001010B

    MOV P2, #01110010B

    CLR P2.6

    SETB P2.6

    ACALL DELAY

    AGAIN5: JB P3.2, AGAIN5

    MOV P1, #00001010B

    MOV P2, #01011111B

    ACALL DELAYAGAIN6: JB P3.2, AGAIN6

    MOV P1, #00001010B

    MOV P2, #00111111B

    ACALL DELAY

    AGAIN7: JB P3.2, AGAIN7

    MOV P1, #00001010B

    MOV P2, #01010001B

    CLR P2.4

    SETB P2.4

    ACALL DELAY

    AGAIN8: JB P3.2, AGAIN8

    MOV P1, #00001010B

    MOV P2, #01111111B

    CLR P2.2

    SETB P2.2ACALL DELAY

    AGAIN9: JB P3.2, AGAIN9

    MOV P1, #00001010B

    MOV P2, #01011111B

    CLR P2.4

    SETB P2.4

    ACALL DELAY

  • 8/14/2019 8051projectreport.pdf

    8/9

    First a loop was created to monitor pin twelve of the microcontroller, the output of the

    infrared receiver, for a low. Once a low was received by the 8051, highs were sent to pin twoand pin four to turn on the transistor and the LED display. The proper code for the number to be

    displayed on the LED display was output on port two; highs corresponded with which segments

    were to be lit. CLR P2.6 and SETB P2.6 fixed the problem of the B segment not coming on,

    Fig. 1-10, which will be discussed in detail in the Problems Encountered section. This actionwas also applied to segments C and E when they would not light.

    Fig. 1-10, Segment Fix AGAIN0: JB P3.2, AGAIN0

    MOV P1, #00001010B

    MOV P2, #01011111B

    CLR P2.6

    SETB P2.6

    Problems Encountered

    Several problems were encountered throughout the course of the project, mostly because

    the end project isnt the original project that was researched. The infrared sensors that werecalled for in the original project didnt have part numbers attached to them on the website.

    Dealing with that, a generic infrared receiver and LED were purchased from Radioshack. From

    the original project, those sensors along with 555 timer chips were used to detect direction so thecounter could increase or decrease. The final project cant do that with only one receiver. If the

    project were done over, another receiver couldve been purchased.

    Another problem ran into was that the original project called for the auto-lighting to belamps run by 230 V. To keep things simpler, using only one DC power supply, four LEDs were

    used.

    A problem arose when the code was run without a delay after each monitor section where

    the 8051 would continue down through the code when there was nothing blocking the infrared

    receiver. Using the oscilloscope, the waveform seen in Fig 1-11 was observed on the infraredreceivers output pin when an object moved through the infrared receive path. A delay was

    created so that the second low would not be seen by the 8051.

    Fig. 1-11, Infrared Receiver Output

    A couple of problems were run into with the seven segment LED display. The displaywas too dim when the same resistors were used from the Interfacing the DS89C430 with a 7-

    Segment LED Display were used in the project. 220 resistors instead of 470 resistors were

    used between the ULN2003A and the display. Also a pull-up resistor of 160 was used on pin14, VCC, of the display to help with the brightness.

    Another problem with the display was that when the code was implemented a segment

    would drop out for certain numbers. It was found that if the wire connecting the ULN2003A was

    disconnected and reconnected, the segment would light again. To solve the problem, two linesof code, Fig. 1-10, were implemented; clear and set bit commands were issued to the pin of the

    8051 associated with the segment.

  • 8/14/2019 8051projectreport.pdf

    9/9