understanding 8051 with c

Upload: sandipnair06

Post on 08-Apr-2018

246 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/7/2019 Understanding 8051 with C

    1/20

    Understanding 8051

    By,

    Sandip Nair

    [email protected]

  • 8/7/2019 Understanding 8051 with C

    2/20

    Embedded microcontroller

    Microcontroller has inbuilt peripherals such as memory,

    UART, timers etc where as microprocessor has only theprocessing unit and the peripherals, has to be connected

    externally

    ,

    washing machine, digital watch, A/C, automobiles,

    microwave oven etc

  • 8/7/2019 Understanding 8051 with C

    3/20

    Embedded design philosophy

    An efficient microcontroller application involves

    designing with a minimum external hardware necessary toallow the software to keep up with all of its tasks

    An efficient software is easy-to-understand software that

  • 8/7/2019 Understanding 8051 with C

    4/20

    Understanding 8051

    arc tecture

  • 8/7/2019 Understanding 8051 with C

    5/20

    About 8051

    The first device was developed by intel

    The architecture had dominated for more than 20 years Other versions are developed keeping the architecture

    and instruction set same for low power, larger memory

    and with many peripherals added

    8051 can be programmed using C, BASIC, C++, forth

    and PL/M languages

  • 8/7/2019 Understanding 8051 with C

    6/20

    Atmel AT89S52

    It is a 8-bit microcontroller built on 80C51

    architecture

    4.0 V to 5.5V operating voltage

    It has 8K bytes of ISP flash memory

    Three level program memory lock 256 X 8bit internal RAM

    32 programmable I/O lines

    Three 16 bit timer/counter

    Eight interrupt sources Full duplex UART serial channel

  • 8/7/2019 Understanding 8051 with C

    7/20

    Cont.

    Low power idle and power down modes Interrupt recovery from power down

    Watch dog timer

    Power-off flag

    Fast programming time

    Flexible ISP programming

  • 8/7/2019 Understanding 8051 with C

    8/20

  • 8/7/2019 Understanding 8051 with C

    9/20

    Pin diagram

  • 8/7/2019 Understanding 8051 with C

    10/20

    Pin description

    Pin 40 =VCC = supply voltage 4.0V to 5.5 V

    Pin 20 = GND = ground Pin 9 = RST = reset input

    Pin 30 =ALE/ PROG = ALE for latching the low byte address

    Pin 29 = PSEN =

  • 8/7/2019 Understanding 8051 with C

    11/20

    Port 0

    P0.0 to P0.7 = Pin 39 to Pin 32

    Has internal pull up resistor for external program

    memory

    Low order address/data bus for external program

    memory Receives code bytes for flash programming

    Outputs code bytes for verification

    Requires external pull up register during program

    verification

  • 8/7/2019 Understanding 8051 with C

    12/20

    Port 1

    Pin 1 to 8 = P1.0 to 1.7

    Has an internal pull up resistor P1.0 = T2 = external count input to timer/counter 2

    P1.1 = T2EX = Timer/counter 2 capture/ reload trigger

    P1.5 = MOSI = used for in-s stem ro rammin

    P1.6 = MISO = used for in-system programming P1.7 = SCK = used for in-system programming

  • 8/7/2019 Understanding 8051 with C

    13/20

    Port 2

    Pin 21 to 28 = P2.0 to 2.7

    Has internal pull ups

    Used for higher order bus for external memory

    Also receives some control signal during flash

    programming

  • 8/7/2019 Understanding 8051 with C

    14/20

    Port 3

    Pin 10 to 17 = P3.0 to P3.7

    Receives control signals for flash programming andverification

    P3.0 = RXD = serial input port

    . = =

    P3.2 = INT0 = external interrupt 0 = inverted

    P3.3 = INT1 = external interrupt 1 = inverted

    P3.4 = T0 = timer 0 external input

    P3.5 = T1 = timer 1 external input P3.6 = WR = external memory data write strobe = inverted

    P3.7 = RD = external memory data read strobe = inverted

  • 8/7/2019 Understanding 8051 with C

    15/20

    C basics

  • 8/7/2019 Understanding 8051 with C

    16/20

  • 8/7/2019 Understanding 8051 with C

    17/20

    C variablesInteger:

    It is 16 bit variable type to store integer values

    It is default unsigned

    Float:

    Double is a 64 bit variable type

    The calculation with these variable types requires

    library function

  • 8/7/2019 Understanding 8051 with C

    18/20

    C variables

    Static and volatile

    Constants:

    Doesnt vary during the program cycle

    It is stored in ro ram memor

    #define

    used at the top of the program to create short cut to save

    typing

    Eg, #define uchar unsigned char#define buffersize 100

  • 8/7/2019 Understanding 8051 with C

    19/20

    Tips for variable

    Calculations to be done on signed variable requireslibrary function which adds extra code to the program,

    making it lengthy and slow. Thus where ever possible

    use unsi ned variable.

    Variable naming should be according to the purpose itis used for, such that it helps in understanding the code

    for others

  • 8/7/2019 Understanding 8051 with C

    20/20

    Reference

    AT89S52 datasheet

    C & the 8051 by Thomas Schultz