Saturday, February 22, 2025

What is a port? (Computer/Microcontroller)

Ports are physical connectors that allow a computer/microcontroller to communicate with external devices.

Ex: In a simple ECG device, the sensor's output is transmit through the circuits to the port of microcontroller. The analog signal is further process in the microcontroller. 


Microcontroller

https://gbembedded.wordpress.com/2015/10/26/avr-io-ports/

As see in the above URL, the port of a microcontroller can be configure as below.

Example:

Interfacing one LED to PORTC and one button to PORTD and when the button is pressed, the LED will glow.

Steps for programming:

  1. Configure inputs and outputs by using DDRx register.
  2. Setting pins as low or high by using PORTx register.
  3. Read the Pin value by using PINx register and perform the operation.
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
DDRC=0x01;
DDRD=0x00;
PORTC=0x00;
PORTD=0x00;
while(1)
{
PORTC=0x01;
if (PIND & 0x01)
{
PORTC=0x00;
_delay_ms(100);

}

}
}

Figure 1: Coding taken from https://gbembedded.wordpress.com/2015/10/26/avr-io-ports/

Figure 2: Picture taken from https://www.flowcode.co.uk/courses/itm/index.php?n=PIC16F1937Architecture.PORTC







No comments:

Post a Comment