Thursday 17 November 2016

LED blink Program using interrupts

 The classic LED blink program uses delay.
 
This version uses interrupts
 
Still flashes LED 13
 
 

Here is the code

/*
 * This is a interrupt version of the classic blink LED sketch
 */

// pins
const int led_pin = PB5; // PB5 is the same as pin 13


void setup() {
 
  // set LED pin to be a output
  DDRB |=(1<< led_pin);// using port B
 
}

void loop() {
 PORTB ^= (1<< led_pin);
 delay(200); // turns LED on/off
 

}
 
//7777777777777777777777777777777777777777

DDRB - The Port B Data Direction Register
 

Port registers allow for lower-level and faster manipulation of the i/o pins of the microcontroller on an Arduino board. The chips used on the Arduino board (the ATmega8 and ATmega168) have three ports:

  • B (digital pin 8 to 13)
  • C (analog input pins)
  • D (digital pins 0 to 7) 
 Port B pins can be either in or output.


Each port is controlled by three registers, which are also defined variables in the arduino language. 
The DDR register, determines whether the pin is an INPUT or OUTPUT. 
The PORT register controls whether the pin is HIGH or LOW.
The PIN register reads the state of INPUT pins set to input with pinMode(). 
 
 
 
Links
 
 
 
 
 

No comments:

Post a Comment