Simple LED Blink Program
Here I'm explained my first register level coding, It is awesome and it's make me much more understand about how the microcontroller is working, I'm still learning, so here I'm sharing what I understood. Are you ready for this then let's go Arduino language Blink program
This is simple Blink program without using any functions!. Take a look at the code the same code is converting to register level
unsigned long counter = 0;// initializing counter variable and set to 0 void setup() { pinMode(LED_BUILTIN, OUTPUT);// set 13th pin LED as output Serial.begin(9600);// initializing Serial communications } void loop() { counter++;//increment the counter Serial.println(counter);// print the counter value on Serial monitor if (counter > 250) { digitalWrite(LED_BUILTIN, HIGH);// if counter value greater than 250 then LED turn ON } if (counter > 500) { digitalWrite(LED_BUILTIN, LOW);// if counter value greater than 500 then LED turn OFF counter = 0;// resetting the counter to 0 } }
Before going to Register level programming we have to understand some basics.
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 is ATMEAG328 (Arduino Nano/UNO) have three ports
What is Ports?
For example ATMEGA328 (in Arduino Nano) have 32 pins and it has 3 Ports totally PORT B, PORT C and PORT D,
- B (digital pin 8 to 13)
- C (analog input pins)
- D (digital pins 0 to 7)
PORT D
PORT B
PORT C
Each port is controlled by three registers, which are also defined variables in the Arduino language.
I can show simply in the table how the Arduino coding is different from Register coding.
I will explain that what is DDR, PORT & PIN.
DDR - data direction register – DDRx
The port input pins I/O location is read only, It means default all the ports are inputs, so if we want to manipulate a pin to output we have to use Data Direction Register.
Comments
Post a Comment