Fast PWM using atmega2560 .

#define F_CPU 16000000
#include <avr/io.h>
#include <util/delay.h>
#define PIN_OCOB PG5

void initPWM();

int main(void)
{
	
     initPWM();	
		
    while (1) 
    {
	//set the duty cycle
	OCR0B = 128;//50% duty cycle
		
	_delay_ms(10);
    }
}

void initPWM()
{
	
	//        FAST PWM                | CLEAR OCOA ON COMPARE
	TCCR0A |= (1<<WGM01) | (1<<WGM00) | (1<<COM0B1) | (0<<COM0B0);
	
	//CS = NO PRESCALE  
	TCCR0B |= (1<<CS00) ;
	
	//Enable OCOA PWM pin	
	DDRG |= 1<<PIN_OCOB;
	
}

Running a stepper motor with arduino on RAMPS with drv8825 driver

#include <Stepper.h>

int enablePin = 24;
int dirPin = 28;
int stepPin = 26;

void setup() {
  pinMode(enablePin, OUTPUT);
  digitalWrite(enablePin, LOW);
  pinMode(dirPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
}

void step(boolean dir, int steps)
{
  digitalWrite(dirPin, dir);
  delay(50);

  for( int i=0;i<steps;i++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(800);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(800);

  }
}

void loop() {
  step(true, 1000);
  delay(50);
  step(false, 1000);
  delay(50);
}

RGB LED blinking in Induino R5

/*
 * main.c
 */

#include <avr/io.h>
#include <util/delay.h>
//#define PIN 0
int main(void)
{
    DDRB|= 1<<PB4;
    DDRB|= 1<<PB5;
    DDRD|= 1<<PD3;//Green
    DDRD|= 1<<PD5;//Blue
    DDRD|= 1<<PD6;//Red

    while(1)
    {
        PORTB|=1<<PB4;
        _delay_ms(100);
        if( PORTB & (1<<PB4) ) // if PB4 set
            PORTB&=~1<<PB4; //unset it

        PORTB|=1<<PB5;
        _delay_ms(100);
        if( PORTB & (1<<PB5) )
            PORTB&=~1<<PB5;

        PORTD|=1<<PD5;
        //PORTD|=1<<PD5;
        //PORTD|=1<<PD6;

        _delay_ms(40);

        PORTD&=~1<<PD5;
        //PORTD&=~1<<PD5;
        //PORTD&=~1<<PD6;
    }
}

//PORTB&=~( (1<<3)|(1<<4)|(1<<5) );//Bitwise NOT (set the OUTPUT as LOW)

A simple LED blink using Pure C in Arduino

Worked with ATmega8 using Eclipse.

Command used: avrdude    -pm8 -carduino -P/dev/ttyUSB0 -b19200 -v
            -Uflash:w:TestBlink1.hex:a

/*
* main.c
*
*      Author: praveenmax
*/

#include <avr/io.h>
#include <util/delay.h>

#define BLINK_DELAY_MS 100

int main(void)
{

DDRB |=_BV(DDB5);

while(1)
{

 PORTB |= _BV(PORTB5);
_delay_ms(BLINK_DELAY_MS);

 PORTB &= ~ _BV(PORTB5);
_delay_ms(BLINK_DELAY_MS);
}

}