Friday 4 March 2016

microcontroller - Difference between reading PORT and PIN


What is the difference between reading PORTA and PINA? What is the relation between a port and its pins?I'm really confused!!! sample of reading PORT:(reading pin is not useful here)


Assembly f=1MHZ ATmega8 I need to complement PORTB every 1ms.(Dutycycle=50%)


    LDI R16,$FF

OUT DDRB,R16
MAIN: LDI R16,00
DELAY:CPI R16,200
BREQ LOOP
INC R16
RJMP DELAY
loop:IN R17,PORTB
COM R17
OUT PORTB,R17
OUT R17,PORTB

RJMP MAIN

Answer



PORT is the OUTPUT buffer, PIN is the INPUT buffer.


When you want to set the pin to a "high" or "low" voltage, write to the PORT register.


When you want to know what voltage is currently presented to a pin, read the PIN register.


The bits of these registers represent the corresponding pins of the general-purpose input/output port.


Here is a simplified schematic of the electronics inside the AVR connected to a single pin (go here for complete datasheets).


This circuit block is repeated for each pin. Eight of these form a port (port A, for example).


enter image description here


Starting at the left-most square (which represents the physical connection to the outside world), you can see three paths:




  1. The upper-most path is the software selectable pull-up resistor

  2. The middle path is used when the pin is configured as an output

  3. The lowest path is used when the pin is configured as an input


It should be noted that some or all of this circuitry can be bypassed when the pin is shared with an internal peripheral. For example, the Analog-to-Digital Converter (ADC).


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...