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 / Replies / Hi,Avoid using statements

Hi,Avoid using statements

|

Microcontroller › PIC › confusion in using latch register and port register › Hi,Avoid using statements

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.

RSS Recent Posts

  • 12v battery, 18v magic May 23, 2025
  • parallel-to-serial problem May 23, 2025
  • STM32 checking self-written delay function May 23, 2025
  • Behringer MX 1602 mixer - reading block diagram May 23, 2025
  • Reclaiming missing motherboard header May 23, 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