Skip to main content

LED BLINKING WITH ATMEGA328P USING ATMEL STUDIO

AVR is a popular microcontroller been used on arduino board but do you know using arduino syntax can delay your work and reduce efficiency so we rather use avr syntax and register directly on arduino microcontroller but for a project that time is not of paramount important arduino syntax can be used directly for the sake of the led blinking tutorial we shall be using atmel studio code directly which will also work on arduino ide by just changing the int main() to void setup() and then do { }while() loop to void loop();






//**
 * \file
 *programmer:AKINGUNSOLA CALEB
 COMPILIER:ATMEL STUDIO 6.0 FOR AVR 
 * \brief Empty user application template
 *
 */

/*
 * Include header files for all drivers that have been imported from
 * Atmel Software Framework (ASF).
 */
#include <asf.h>
#define F_CPU 16000000UL    //16mhz crystal
#include <avr/io.h> //allow input output function
#include <avr/interrupt.h> //allow interrupt even though not used in code
#include <util/delay.h> //allow delay 



int main (void)
{
board_init();
DDRB|=(1<<PB5);//set all portd direction to output;
PORTB&=~(1<<PB5);//set pin low
do 
{
PORTB|=(1<<PB5); //set PB5 to high 
_delay_ms(1000);  //wait 1sec
PORTB&=~(1<<PB5); //set PB5 to low
_delay_ms(1000); //wait 1 sec
} while (1);

// Insert application code here, after the board has been initialized.
}

the above code is faster than the one below because we are making use of bit manipulation.,arduino code will still take a-lot of time converting back to the general avr code that time of conversion account for the great difference.

from the above diagram PB5 on the pinout of atmega328p is on digitalpin13 on arduino the code above is like the below code on arduino


void setup()

{
pinMode(13,OUTPUT); //set as output
digitalWrite(13,LOW);//set pin low

}

void loop()
{

digitalWrite(13,HIGH);//set pin high
delay(1000);//wait 1 seconds
digitalWrite(13,LOW);//set pin low
delay(1000);//wait 1 seconds
}



Comments

Popular posts from this blog

Interfacing L298N Motor Driver with Arduino Uno

1 May Interfacing L298N Motor Driver with Arduino Uno In this tutorial we will learn how to interface  L298N  motror driver with  Arduino Uno . You might be thinking why we need L298N for controlling a motor. The answer is very simple,  Arduino  board or a  microcontroller  IO pins don’t have enough current/voltage driving capability to drive a motor. For driving the motor in both directions (clockwise and anti-clockwise) we need to use an  H-Bridge . Please read our article  H-Bridge – DC Motor Driving  for more information. L298N is an integrated monolithic circuit with dual H-Bridge. It can be used to rotate the motor in both directions and to control the speed of the motor using  PWM  technique. Components Required Arduino Uno L298N Motor Driver 12V battery 2x DC Motors Jumper wires L298N Motor Driver Module L298N Motor Driver Connections Explained Specifications Output A, Output B – To connect two motors. Driver Power Inpu...

Using the TLP250 Isolated MOSFET Driver

Using the TLP250 Isolated MOSFET Driver - Explanation and Example Circuits I’ve already shown how to drive an N-channel MOSFET (or even an IGBT) in both high-side and low-side configurations in a multitude of ways. I’ve also explained the principles of driving the MOSFETs in these configurations. The dedicated drivers I’ve shown so far are the TC427 and IR2110. Some people have requested me to write up on MOSFET drive using the very popular TLP250. And I’ll explain that here. The TLP250, like any driver, has an input stage, an output stage and a power supply connection. What’s special about the TLP250 is that the TLP250 is an optically isolated driver, meaning that the input and output are “optically isolated”. The isolation is optical – the input stage is an LED and the receiving output stage is light sensitive (think “photodetector”). Before delving any further, let’s look at the pin configuration and the truth table. Fig. 1 - TLP250 Pin Configuration Fig....

SMPS DESIGN USING UC384X SERIES

 SMPS design is always a difficult task for most beginners even to many intermediate engineers based on the fact that the principle and the rules looks tedious. Flyback approach is always a very good concept when you needed a current not above KW but you can still use flyback approach to achieve a higher power rating if you can interconnect them together or follow some set rules. While I was getting my hands dirty, experimenting smps flyback approach I burnt a lot of IC and power transistors and other components before i was able to understand the principle revolving around it. SMPS design both buck converter, boost converter, buck-boost converter, push-pull, half-bridge and full bridge are not a difficult task but they need a very huge attention else nothing will work and debt may set in. Will be pointing out some rudiment behind SMPS design. Namely on buck converter using flyback approach: * TRANSFORMER SELECTION: Flyback uses a gapped ferrite core or gapped core, the core ca...