So even if you don’t connect anything to pin and if you try to read it, it will read as 1. In input mode, when pull-up is enabled, default state of pin becomes ‘1’. In order to activate pull-up resister, set bit in PORTx to 1, and to deactivate (i.e to make port pin tri stated) set it to 0. make port pins as inputs, then corresponding bits in PORTx register are used to activate/deactivate pull-up registers associated with that pin. It will be explained shortly.ĭDRC |= 0b00000001 //set only 0th pin of port c as outputĢ) To activate/deactivate pull up resistors – when port is configures as input Either you can use port pins as tri stated inputs or you can activate internal pull up. If port is made output, then reading PINx register will give you data that has been output on port pins. This is done by setting bits in DDRx to zero. In order to read the data from port pin, first you have to change port’s data direction to input. PINx (Port IN) used to read data from port pins. to make lower nibble of port B as output and higher nibble as input :.to make all pins of port A as output pins :.to make all pins of port A as input pins :.Writing 0 to a bit in DDRx makes corresponding port pin as input, while writing 1 to a bit in DDRx makes corresponding port pin as output. Means its setting determines whether port pins will be used for input or output. (x can be replaced by A,B,C,D as per the AVR you are using)ĭDRx (Data Direction Register) configures data direction of port pins. Bit0 of these registers is associated with Pin0 of the port, Bit1 of these registers is associated with Pin1 of the port, …. Every bit in those registers configure pins of particular port. Every port has 3 registers associated with it each one with 8 bits. Got that ? If not read this para again.Ītmel AVR is 8 bit microcontroller. To change setting for one single pin of the port, you have to change a particular bit in associated register. Thus in order to change setting for one port, you have to change setting for all port pins of that port. NOTE : I will frequently refer to ‘configuring pin’ or simply ‘pin’. To get quick background about AVR microcontrollers, refer to Intoduction to AVR Tutorial on this blog. It is slightly confusing for beginners, however once you understand it, you will certainly appreciate the way it is designed. We will learn how to use Atmel AVR’s GPIO ports and actually ‘code’ for writing/reading data to/from port pins in this AVR tutorial. Finally its all about : taking input, processing it and generating output ! Thus i/o registers and their correct settings is indispensable part while learning to program any uC. Provide 8-bit PWM output with the analogWrite() function.You cannot imagine to use microcontroller without using any of its i/o pins. See the attachInterrupt() function for details. These pins can be configured to trigger an interrupt on a low value, a rising or falling edge, or a change in value. Pins 0 and 1 are also connected to the corresponding pins of the ATmega16U2 USB-to-TTL Serial chip.Įxternal Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2). Used to receive (RX) and transmit (TX) TTL serial data. In addition, some pins have specialized functions: Each pin can provide or receive a maximum of 40 mA and has an internal pull-up resistor (disconnected by default) of 20-50 kOhms. Each of the 54 digital pins on the Arduino 2560 Mega can be used as an input or output, using pinMode(), digitalWrite(), and digitalRead() functions.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |