SlideShare ist ein Scribd-Unternehmen logo
1 von 31
I/O PORTS AND TIMERS
IN 8051 MICRO CONTROLLER

                             Dr. C. Saritha
                    Lecturer in Electronics
              SSBN Degree & PG College
             Anantapur - 515001
Input/Output Ports (I/O Ports)
 All8051 microcontrollers have 4 I/O ports
  each comprising 8 bits which can be
  configured as inputs or outputs.

 Allthe ports upon reset are configured as
  output, ready to use it as output port.

 To  use any of these ports as an input port,
  it must be programmed.
Port 0
Port0   occupies a total of 8 pins (pins
 32-39).
It can be used for input or output.
To use the pins of port o as both input
 and output ports, each pin must be
 connected externally to 10k-ohm pull up
 resistor.
This is due to fact that p0 is an open
 drain with external pull up resistors
 connected upon the reset.
Port0 with pull up resistor
Continue…

 Port0   is configured as o/p port:-
           BACK MOV A,#55H
                   MOV PO,A
                   ACALL DELAY
                   CPL A
                   SJMP BACK
Continue…
 To make the port o as i/p port, the port
 must be programmed by writing 1 to all the
 bits.
              MOV A,#FFH
               MOV PO,A
       BACK MOV A,PO
              SJMP BACK
Dual role of port 0
 Port0  is also designated as ADO-
 AD7,allowing it to be used for both address
 and data .

 When connecting 8051 to      an external
 memory, port0 provides both   address and
 data

 The 8051 multiplexes address and data
 through port0 to save pins.
Continue…
     When ALE=0, it provides data D0-D7 but
     when ALE=1 it has address A0-A7.

.
     ALE is used for multiplexing address and
     data with help of 74LS73.
Port1
 Port
     1 occupies a total of 8 pins, it can be
 used as input or output.

 This  port does not need any pull-up
 resistors since it already has pull-up
 resistor internally.

 Upon   reset ,port1 is configured as an o/p
 port.
Continue…
   Port1 is configured as o/p port:-
      BACK MOV A,#55H
               MOV P1,A
               ACALL DELAY
               CPL A
               SJMP BACK
Continue…
 To make port1 an i/p port, it must be
 programmed as such writing 1 to all its bits
            MOV A,#FFH
            MOV P1,A
      BACK MOV A,P1
            SJMP BACK
PORT 2
 Port2occupies a total of 8 pins, it can be
 used as i/p or o/p.

 Justlike p1,port2 does not need any pull-
 up resistor since it has pull-up resistor
 internally.

 Upon    reset, port2 configured as an o/p.
Continue…
   Port2 is configured as o/p port:-
      BACK MOV A,#55H
               MOV P2,A
               ACALL DELAY
               CPL A
               SJMP BACK
Continue…
 To make port2 an i/p port, it must be
 programmed as such writing 1 to all its bits
            MOV A,#FFH
            MOV P2,A
      BACK MOV A,P2
            SJMP BACK
Dual role of port2

 Port2  must be used along with p0 to
 provide the 16 bit address for the external
 memory.

 Port2  is designated as A8-A15,indicating
 its dual function
PORT 3
  port3 occupies a total of 8 pins. It can be
  used as i/p or o/p .
 P3 does not need any pull up resistor same
  as p1 and p2 did not.
 Port3 is configured as o/p port upon reset .
 Port3 has the additional function of providing
  some extremely important signals such as
  interrupts
Alternate Pin-functions
Timers/counters

          Timers/Counters




Timer0/Counter0     Timer1/Counter1
Continue…
They can be used as:
1 Timer:
 Timers are used as time delay generator.
    The clock source is the internal crystal
  frequency of the 8051.
2 counter:
   Which counts number of events.
      External input from input pin to count the
  number of events on register
Registers used in Timer/counter
   Register pairs (TH0,TH1),(TL0,TL1) form
    16-bit Timer/Counter registers.

 These   are instructions for reading and
  writing and they are bit wise
 One 8 bit mode register-TMOD.


 One   8 bit control register-TCON.
TMOD Register
      Both timer 0 and timer 1 use the same
    register called TMOD.

    It is an 8-bit register in which the lower 4
    bits are set aside for timer 0 and the upper 4
    bits are set aside for timer 1

    The lower 2 bits are used to set the timer
    and the upper 2 bits to specify the
Timer Mode (TMOD)



GATE C/T   M1    M0   GATE C/T   M1   M0


       Timer 1              Timer 0
 GATE       :-
               Gating control when set, the
 timer/counter is enabled only while the INTX
 Pin is high and the TRX control pin is set.

 C/T   :-
        This bit in the TMOD register is used
 to decide whether the timer is used as a
 delay generation or an event counter.
              If C/T=0,it is used as a delay
 generator.
Continue…
 M1:Mode bit 1
 M0: Mode bit 0
  M0 and M1 select the timer mode, there
 are three modes i.e., mode 0,mode 1,
 mode 2.
Modes of timers/counters
 Mode 0 : 5 bit prescaler(13 bit )
 Mode 1 : 16 bit timer
 Mode 2 : 8 bit Auto reload
 Mode 3 : TL 0 and TH0 are independent

           but TH0 controlled by TR1
           and TF1.
TCON Register
   This is an 8 bit register.

    The upper 4 bits of the register is used to
    store the TF and TR bits of both timer 0
    and timer 1.

     The lower 4 bits are set aside for
    controlling the interrupt bit.
Timer Control Register (TCON)



TF1   TR1 TF0   TR0 IE1   IT1   IE0   IT0
     TF1 [Timer1 over flow flag] :- Set by
    hardware when timer 1 counters over
    flows, cleared    by hardware as the
    processor vectors to the service routine.

 TR1    [Timer1 run control bit] :- Set/cleared
    by software to turn timer1 counter1 on/off.

 TF0     [Timer0 over flow flag] :- Set by
    hardware when timer /counters over flows,
    cleared by hardware as the processor
    vectors to the service routine.
 TR0    [Timer0 run control bit] :- Set/cleared by
    software to turn timer/counter on/off.

 IE1    [External interrupt1 edge flag] :- Set by
    CPU when the external interrupt edge is
    detected, cleared by the CPU when the
    interrupt is processed.

     IT1 [Interrupt 1 type control bit] :-
    Set/cleared by software to specify falling
    edge/low level triggered external interrupt.
 IE0 [External interrupt0 edge flag] :- Set by
 CPU when the external interrupt edge is
 detected, cleared by the CPU when the
 interrupt is processed.

 IT0  [Interrupt 0 type control bit] :-
 Set/cleared by software to specify falling
 edge/low level triggered external interrupt.
THANK YOU

Weitere ähnliche Inhalte

Was ist angesagt?

register file structure of PIC controller
register file structure of PIC controllerregister file structure of PIC controller
register file structure of PIC controllerNirbhay Singh
 
Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 completeShubham Singh
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontrollerthokalpv
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086asrithak
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller pptRahul Kumar
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxDr.YNM
 
Internal architecture-of-8086
Internal architecture-of-8086Internal architecture-of-8086
Internal architecture-of-8086Estiak Khan
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086saurav kumar
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Memory Segmentation of 8086
Memory Segmentation of 8086Memory Segmentation of 8086
Memory Segmentation of 8086Nikhil Kumar
 
MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration AKHIL MADANKAR
 
8086 modes
8086 modes8086 modes
8086 modesPDFSHARE
 
8086 pin details
8086 pin details8086 pin details
8086 pin detailsAJAL A J
 

Was ist angesagt? (20)

register file structure of PIC controller
register file structure of PIC controllerregister file structure of PIC controller
register file structure of PIC controller
 
Microprocessor 8085 complete
Microprocessor 8085 completeMicroprocessor 8085 complete
Microprocessor 8085 complete
 
8086 micro processor
8086 micro processor8086 micro processor
8086 micro processor
 
8051 memory
8051 memory8051 memory
8051 memory
 
Adc interfacing
Adc interfacingAdc interfacing
Adc interfacing
 
8051 Microcontroller
8051 Microcontroller8051 Microcontroller
8051 Microcontroller
 
flag register of 8086
flag register of 8086flag register of 8086
flag register of 8086
 
8051 Microcontroller ppt
8051 Microcontroller ppt8051 Microcontroller ppt
8051 Microcontroller ppt
 
8251 USART
8251 USART8251 USART
8251 USART
 
Introducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptxIntroducion to MSP430 Microcontroller.pptx
Introducion to MSP430 Microcontroller.pptx
 
Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
 
Internal architecture-of-8086
Internal architecture-of-8086Internal architecture-of-8086
Internal architecture-of-8086
 
ADC & DAC
ADC & DACADC & DAC
ADC & DAC
 
Addressing modes of 8086
Addressing modes of 8086Addressing modes of 8086
Addressing modes of 8086
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Memory Segmentation of 8086
Memory Segmentation of 8086Memory Segmentation of 8086
Memory Segmentation of 8086
 
MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration MICROCONTROLLER 8051- Architecture & Pin Configuration
MICROCONTROLLER 8051- Architecture & Pin Configuration
 
LCD Interacing with 8051
LCD Interacing with 8051LCD Interacing with 8051
LCD Interacing with 8051
 
8086 modes
8086 modes8086 modes
8086 modes
 
8086 pin details
8086 pin details8086 pin details
8086 pin details
 

Andere mochten auch

8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O portsanishgoel
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller NotesDr.YNM
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counterankit3991
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and CountersShreyans Pathak
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Ganesh Ram
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
Introduction to microprocessors notes
Introduction to microprocessors notesIntroduction to microprocessors notes
Introduction to microprocessors notesSARITHA REDDY
 
Embedded systems ppt iii
Embedded systems ppt iiiEmbedded systems ppt iii
Embedded systems ppt iiianishgoel
 
Unit iv microcontrollers final
Unit iv microcontrollers finalUnit iv microcontrollers final
Unit iv microcontrollers finalSARITHA REDDY
 

Andere mochten auch (20)

I o ports.ppt
I o ports.pptI o ports.ppt
I o ports.ppt
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
8051 Microcontroller I/O ports
8051 Microcontroller I/O ports8051 Microcontroller I/O ports
8051 Microcontroller I/O ports
 
8051 Microcontroller Notes
8051 Microcontroller Notes8051 Microcontroller Notes
8051 Microcontroller Notes
 
8051 i/o port circuit
8051 i/o port circuit8051 i/o port circuit
8051 i/o port circuit
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))Architecture of 8051 microcontroller))
Architecture of 8051 microcontroller))
 
Rfid technologies
Rfid technologiesRfid technologies
Rfid technologies
 
8051 MICROCONTROLLER
8051 MICROCONTROLLER 8051 MICROCONTROLLER
8051 MICROCONTROLLER
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
Introduction to microprocessors notes
Introduction to microprocessors notesIntroduction to microprocessors notes
Introduction to microprocessors notes
 
Embedded system - Introduction to micro-controller 8051
Embedded system - Introduction to  micro-controller 8051Embedded system - Introduction to  micro-controller 8051
Embedded system - Introduction to micro-controller 8051
 
8051 microprocessor
8051 microprocessor8051 microprocessor
8051 microprocessor
 
Ch09
Ch09Ch09
Ch09
 
Intel 8051
Intel 8051Intel 8051
Intel 8051
 
Embedded systems ppt iii
Embedded systems ppt iiiEmbedded systems ppt iii
Embedded systems ppt iii
 
8051 timers--2
   8051 timers--2   8051 timers--2
8051 timers--2
 
Unit iv microcontrollers final
Unit iv microcontrollers finalUnit iv microcontrollers final
Unit iv microcontrollers final
 

Ähnlich wie I o ports and timers of 8051

MICROCONTROLLER .pptx
MICROCONTROLLER .pptxMICROCONTROLLER .pptx
MICROCONTROLLER .pptxArulMozhie1
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051ssuser3a47cb
 
8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptxveeramaniks
 
Embedded systems io programming
Embedded systems   io programmingEmbedded systems   io programming
Embedded systems io programmingimtiazalijoono
 
Microprocessor 8051
Microprocessor 8051Microprocessor 8051
Microprocessor 8051Anil Maurya
 
8051 architecture
8051 architecture8051 architecture
8051 architecturesb108ec
 
SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051KanchanPatil34
 
EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3PRADEEP
 
Advanced Microprocessor 6.pptx
Advanced Microprocessor 6.pptxAdvanced Microprocessor 6.pptx
Advanced Microprocessor 6.pptxShanDimantha1
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051Rashmi
 
Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesSrikrishna Thota
 
janakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiramang6
 
janakiraman egsp collage I msc 4 unit
janakiraman egsp collage  I msc 4 unitjanakiraman egsp collage  I msc 4 unit
janakiraman egsp collage I msc 4 unitjanakiramang6
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcdabhishek upadhyay
 
Microcontroller (1).pptx
Microcontroller (1).pptxMicrocontroller (1).pptx
Microcontroller (1).pptxITPradiptaRoy
 
Embedded System Microcontroller 8051
Embedded System Microcontroller 8051Embedded System Microcontroller 8051
Embedded System Microcontroller 8051ShawnIslam20150022
 

Ähnlich wie I o ports and timers of 8051 (20)

MICROCONTROLLER .pptx
MICROCONTROLLER .pptxMICROCONTROLLER .pptx
MICROCONTROLLER .pptx
 
I/O port programming in 8051
I/O port programming in 8051I/O port programming in 8051
I/O port programming in 8051
 
8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx8051 Microcontroller -1.pptx
8051 Microcontroller -1.pptx
 
Embedded systems io programming
Embedded systems   io programmingEmbedded systems   io programming
Embedded systems io programming
 
Microprocessor 8051
Microprocessor 8051Microprocessor 8051
Microprocessor 8051
 
8051 architecture
8051 architecture8051 architecture
8051 architecture
 
SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051SE PAI Unit 5_IO programming in 8051
SE PAI Unit 5_IO programming in 8051
 
EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3EMBEDDED SYSTEMS 2&3
EMBEDDED SYSTEMS 2&3
 
Advanced Microprocessor 6.pptx
Advanced Microprocessor 6.pptxAdvanced Microprocessor 6.pptx
Advanced Microprocessor 6.pptx
 
Microcontroller 8051
Microcontroller 8051Microcontroller 8051
Microcontroller 8051
 
Microprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 FeaturesMicroprocessor Interfacing and 8155 Features
Microprocessor Interfacing and 8155 Features
 
8051 book
8051 book8051 book
8051 book
 
janakiraman I msc 4 unit
janakiraman I msc 4 unitjanakiraman I msc 4 unit
janakiraman I msc 4 unit
 
janakiraman egsp collage I msc 4 unit
janakiraman egsp collage  I msc 4 unitjanakiraman egsp collage  I msc 4 unit
janakiraman egsp collage I msc 4 unit
 
8155 GPPI
8155 GPPI8155 GPPI
8155 GPPI
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcd
 
At89 s8252
At89 s8252At89 s8252
At89 s8252
 
Microcontroller (1).pptx
Microcontroller (1).pptxMicrocontroller (1).pptx
Microcontroller (1).pptx
 
Embedded System Microcontroller 8051
Embedded System Microcontroller 8051Embedded System Microcontroller 8051
Embedded System Microcontroller 8051
 
At89s52
At89s52At89s52
At89s52
 

Mehr von SARITHA REDDY

8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directivesSARITHA REDDY
 
Unit ii microcontrollers final
Unit ii microcontrollers finalUnit ii microcontrollers final
Unit ii microcontrollers finalSARITHA REDDY
 
Introduction to microprocessor notes
Introduction to microprocessor notesIntroduction to microprocessor notes
Introduction to microprocessor notesSARITHA REDDY
 
8051 data type and directives
8051 data type and directives8051 data type and directives
8051 data type and directivesSARITHA REDDY
 
Decimation in time and frequency
Decimation in time and frequencyDecimation in time and frequency
Decimation in time and frequencySARITHA REDDY
 
Mos and cmos technology
Mos and cmos technologyMos and cmos technology
Mos and cmos technologySARITHA REDDY
 
Clampers and clippers
Clampers and clippersClampers and clippers
Clampers and clippersSARITHA REDDY
 
Electro Magnetic Wave Propagation
Electro Magnetic Wave PropagationElectro Magnetic Wave Propagation
Electro Magnetic Wave PropagationSARITHA REDDY
 
Satellite communications
Satellite communicationsSatellite communications
Satellite communicationsSARITHA REDDY
 
Electronics in daily life
Electronics in daily lifeElectronics in daily life
Electronics in daily lifeSARITHA REDDY
 
BSc I year practicals
BSc I year practicalsBSc I year practicals
BSc I year practicalsSARITHA REDDY
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuitsSARITHA REDDY
 
Applications of op amps
Applications of op ampsApplications of op amps
Applications of op ampsSARITHA REDDY
 
Digital logic gates and Boolean algebra
Digital logic gates and Boolean algebraDigital logic gates and Boolean algebra
Digital logic gates and Boolean algebraSARITHA REDDY
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c languageSARITHA REDDY
 

Mehr von SARITHA REDDY (20)

8051 data types and directives
8051 data types and directives8051 data types and directives
8051 data types and directives
 
Unit ii microcontrollers final
Unit ii microcontrollers finalUnit ii microcontrollers final
Unit ii microcontrollers final
 
Introduction to microprocessor notes
Introduction to microprocessor notesIntroduction to microprocessor notes
Introduction to microprocessor notes
 
8051 data type and directives
8051 data type and directives8051 data type and directives
8051 data type and directives
 
Decimation in time and frequency
Decimation in time and frequencyDecimation in time and frequency
Decimation in time and frequency
 
RT linux
RT linuxRT linux
RT linux
 
Mos and cmos technology
Mos and cmos technologyMos and cmos technology
Mos and cmos technology
 
Logic families
Logic familiesLogic families
Logic families
 
Clampers and clippers
Clampers and clippersClampers and clippers
Clampers and clippers
 
Linked lists
Linked listsLinked lists
Linked lists
 
Arrays
ArraysArrays
Arrays
 
Electro Magnetic Wave Propagation
Electro Magnetic Wave PropagationElectro Magnetic Wave Propagation
Electro Magnetic Wave Propagation
 
Satellite communications
Satellite communicationsSatellite communications
Satellite communications
 
Electronics in daily life
Electronics in daily lifeElectronics in daily life
Electronics in daily life
 
BSc I year practicals
BSc I year practicalsBSc I year practicals
BSc I year practicals
 
Combinational circuits
Combinational circuitsCombinational circuits
Combinational circuits
 
Applications of op amps
Applications of op ampsApplications of op amps
Applications of op amps
 
Digital logic gates and Boolean algebra
Digital logic gates and Boolean algebraDigital logic gates and Boolean algebra
Digital logic gates and Boolean algebra
 
Graphs in c language
Graphs in c languageGraphs in c language
Graphs in c language
 
Question bank
Question bankQuestion bank
Question bank
 

I o ports and timers of 8051

  • 1. I/O PORTS AND TIMERS IN 8051 MICRO CONTROLLER Dr. C. Saritha Lecturer in Electronics SSBN Degree & PG College Anantapur - 515001
  • 2. Input/Output Ports (I/O Ports)  All8051 microcontrollers have 4 I/O ports each comprising 8 bits which can be configured as inputs or outputs.  Allthe ports upon reset are configured as output, ready to use it as output port.  To use any of these ports as an input port, it must be programmed.
  • 3. Port 0 Port0 occupies a total of 8 pins (pins 32-39). It can be used for input or output. To use the pins of port o as both input and output ports, each pin must be connected externally to 10k-ohm pull up resistor. This is due to fact that p0 is an open drain with external pull up resistors connected upon the reset.
  • 4. Port0 with pull up resistor
  • 5. Continue…  Port0 is configured as o/p port:- BACK MOV A,#55H MOV PO,A ACALL DELAY CPL A SJMP BACK
  • 6. Continue…  To make the port o as i/p port, the port must be programmed by writing 1 to all the bits. MOV A,#FFH MOV PO,A BACK MOV A,PO SJMP BACK
  • 7. Dual role of port 0  Port0 is also designated as ADO- AD7,allowing it to be used for both address and data .  When connecting 8051 to an external memory, port0 provides both address and data  The 8051 multiplexes address and data through port0 to save pins.
  • 8. Continue…  When ALE=0, it provides data D0-D7 but when ALE=1 it has address A0-A7. .  ALE is used for multiplexing address and data with help of 74LS73.
  • 9. Port1  Port 1 occupies a total of 8 pins, it can be used as input or output.  This port does not need any pull-up resistors since it already has pull-up resistor internally.  Upon reset ,port1 is configured as an o/p port.
  • 10. Continue…  Port1 is configured as o/p port:- BACK MOV A,#55H MOV P1,A ACALL DELAY CPL A SJMP BACK
  • 11. Continue…  To make port1 an i/p port, it must be programmed as such writing 1 to all its bits MOV A,#FFH MOV P1,A BACK MOV A,P1 SJMP BACK
  • 12. PORT 2  Port2occupies a total of 8 pins, it can be used as i/p or o/p.  Justlike p1,port2 does not need any pull- up resistor since it has pull-up resistor internally.  Upon reset, port2 configured as an o/p.
  • 13. Continue…  Port2 is configured as o/p port:- BACK MOV A,#55H MOV P2,A ACALL DELAY CPL A SJMP BACK
  • 14. Continue…  To make port2 an i/p port, it must be programmed as such writing 1 to all its bits MOV A,#FFH MOV P2,A BACK MOV A,P2 SJMP BACK
  • 15. Dual role of port2  Port2 must be used along with p0 to provide the 16 bit address for the external memory.  Port2 is designated as A8-A15,indicating its dual function
  • 16. PORT 3  port3 occupies a total of 8 pins. It can be used as i/p or o/p .  P3 does not need any pull up resistor same as p1 and p2 did not.  Port3 is configured as o/p port upon reset .  Port3 has the additional function of providing some extremely important signals such as interrupts
  • 18. Timers/counters Timers/Counters Timer0/Counter0 Timer1/Counter1
  • 19. Continue… They can be used as: 1 Timer:  Timers are used as time delay generator.  The clock source is the internal crystal frequency of the 8051. 2 counter:  Which counts number of events.  External input from input pin to count the number of events on register
  • 20. Registers used in Timer/counter  Register pairs (TH0,TH1),(TL0,TL1) form 16-bit Timer/Counter registers.  These are instructions for reading and writing and they are bit wise  One 8 bit mode register-TMOD.  One 8 bit control register-TCON.
  • 21. TMOD Register  Both timer 0 and timer 1 use the same register called TMOD.  It is an 8-bit register in which the lower 4 bits are set aside for timer 0 and the upper 4 bits are set aside for timer 1  The lower 2 bits are used to set the timer and the upper 2 bits to specify the
  • 22. Timer Mode (TMOD) GATE C/T M1 M0 GATE C/T M1 M0 Timer 1 Timer 0
  • 23.  GATE :- Gating control when set, the timer/counter is enabled only while the INTX Pin is high and the TRX control pin is set.  C/T :- This bit in the TMOD register is used to decide whether the timer is used as a delay generation or an event counter. If C/T=0,it is used as a delay generator.
  • 24. Continue…  M1:Mode bit 1 M0: Mode bit 0 M0 and M1 select the timer mode, there are three modes i.e., mode 0,mode 1, mode 2.
  • 25. Modes of timers/counters  Mode 0 : 5 bit prescaler(13 bit )  Mode 1 : 16 bit timer  Mode 2 : 8 bit Auto reload  Mode 3 : TL 0 and TH0 are independent but TH0 controlled by TR1 and TF1.
  • 26. TCON Register  This is an 8 bit register.  The upper 4 bits of the register is used to store the TF and TR bits of both timer 0 and timer 1.  The lower 4 bits are set aside for controlling the interrupt bit.
  • 27. Timer Control Register (TCON) TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
  • 28. TF1 [Timer1 over flow flag] :- Set by hardware when timer 1 counters over flows, cleared by hardware as the processor vectors to the service routine.  TR1 [Timer1 run control bit] :- Set/cleared by software to turn timer1 counter1 on/off.  TF0 [Timer0 over flow flag] :- Set by hardware when timer /counters over flows, cleared by hardware as the processor vectors to the service routine.
  • 29.  TR0 [Timer0 run control bit] :- Set/cleared by software to turn timer/counter on/off.  IE1 [External interrupt1 edge flag] :- Set by CPU when the external interrupt edge is detected, cleared by the CPU when the interrupt is processed.  IT1 [Interrupt 1 type control bit] :- Set/cleared by software to specify falling edge/low level triggered external interrupt.
  • 30.  IE0 [External interrupt0 edge flag] :- Set by CPU when the external interrupt edge is detected, cleared by the CPU when the interrupt is processed.  IT0 [Interrupt 0 type control bit] :- Set/cleared by software to specify falling edge/low level triggered external interrupt.