Docsity

Configuring the Pin in Microprocessor & Computer Architecture Lab, Slides of Microprocessor and Assembly Language Programming

Partial preview of the text

Download Configuring the Pin in Microprocessor & Computer Architecture Lab and more Slides Microprocessor and Assembly Language Programming in PDF only on Docsity!

Microprocessor & Computer Architecture Lab (EE3321) Lab 02

Configuring the Pin

  • (^) Each port pin consists of three register bits: DDxn, PORTxn, and PINxn.

Data Register (PORTxn)

  • (^) If PORTxn is written logic one when the pin is configured as an output pin, the port pin is driven high (one).
  • (^) If PORTxn is written logic zero when the pin is configured as an output pin, the port pin is driven low (zero).

Input Pin (PINxn)

  • (^) Port Pin can be read through the PINxn Register bit.

Port B (PB7..PB0)

  • (^) Port B is an 8-bit bi-directional I/O port.

Port C (PC7..PC0)

  • (^) Port C is an 8-bit bi-directional I/O port.

Examples (DDRx)

  • (^) DDRB = 0xFF; // set PORTB as output
  • (^) DDRA = (1<<DDRA5); // set PINA5 as output and other pins of PORTA as input
  • (^) DDRD=(1<<DDRD5)|(1<<DDRD3); //set PIND5 & PIND3 as output and PIND7, PIND6, PIND4, PIND2, PIND1, PIND0 as input
  • (^) DDRD = 0x00; // set PORTD as input
  • (^) DDRB = 0x04; // set PINB3 as output and other pins of PORTB as input
  • (^) DDRA = 0b11111111; // set PORTA as output
  • (^) DDRA = 0b10100000; // set PINA7 & PINA5 as output and other pins as input PORTC = 128

Examples (PORTx)

  • (^) PORTB = 0xFF; // set PORTB as Logic Level โ€˜1โ€™
  • (^) PORTA = (1<<PORTA5); // set PINA5 as Logic Level โ€˜1โ€™ and other pins of PORTA as Logic Level โ€˜0โ€™
  • (^) PORTD=(1<<PORTD5)|(1<<PORTD3); //set PIND5 & PIND3 as Logic Level โ€˜1โ€™ and PIND7, PIND6, PIND4, PIND2, PIND1, PIND0 as Logic Level โ€˜0โ€™
  • (^) PORTD = 0x00; // set PORTD as Logic Level โ€˜0โ€™
  • (^) PORTB = 0x04; // set PINB3 as Logic Level โ€˜1โ€™ and other pins of PORTB as Logic Level โ€˜0โ€™
  • (^) PORTA = 0b11111111; // set PORTA as Logic Level โ€˜1โ€™
  • (^) PORTA = 0b10100000; // set PINA7 & PINA5 as Logic Level โ€˜1โ€™ and other pins as Logic Level โ€˜0โ€™
  • (^) PORTD = 255