EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / confusion in using latch register and port register

confusion in using latch register and port register

|

Microcontroller › PIC › confusion in using latch register and port register

  • This topic has 2 replies, 2 voices, and was last updated 10 years, 6 months ago by himanshu mittal.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • December 6, 2014 at 9:10 am #3338
    himanshu mittal
    Participant

    Sir,
    I am new to pic microcontroller and trying to learn from friends.
    I am doing led blink program on pic 16f877a.
    I am confused whether to use port register or latch register.
    When i used latch register in blinking led
    LATB=~LATB
    Delay();

    complier shows error like undefined LATB
    When i used port registr led start blinking
    PORTA=~PORTA
    Delay();

    Engineergarage is using latch register in their tutorial but some are using port register in led blinking.
    I am totally confused whether to use latch or port register.

    I am also unable to understand what is Read modify write operation.

    December 8, 2014 at 4:50 am #12406
    AJISH ALFRED
    Participant

    Hi,

    Avoid using statements like this in your ‘C’ code.

    LATB=~LATB 

    PORTA=~PORTA 

     

    Take a temperory variable, say ‘t’ and convert the above statements like,

     

    t = LATB;

    LATB = ~t;

     

    t = PORTA;

    PORTA = ~t;

     

    Port registers are connected to the port pin through Latch registers,

     

    PORT REGISTER >> LATCH REGISTER >> PORT PIN

     

    Even if you write a value to the port register, it will not appear at the port pin until you enable the latching using the lacth registers. 

    For a simple LED blinking, writing a ‘1’ or ‘0’ to port register (according to whether the anode or cathode of LED is connected to the pin) and then keep on enabling and disabling the latching will do the purpose.

    December 8, 2014 at 7:10 am #12407
    himanshu mittal
    Participant

    Thank u

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Saga 1400sv vinyl cutter motherboard issue June 20, 2025
  • PIC KIT 3 not able to program dsPIC June 20, 2025
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz June 20, 2025
  • using a RTC in SF basic June 20, 2025
  • Relay buzzing after transformer change? June 20, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise