Microcontrollers !!

Blinking an LED , the hard way

Created by Akshai M / @m_akshai

MicroHOPE

Microcontrollers for Hobby Projects and Education

microhope

A bit of history , usual say

expeyes

Why MicroHOPE

Yet another controller board ?

Into the board

outlay

Controller

  • 32 I/O Pins (8 x 4)
  • 32 kB Flash , 512bytes EEPROM , 2kB SRAM
  • 3 x Timers , 8 Channel ADC (10 bit)
  • SPI , USART
atmega32

MCP2200

USB - UART

mcp2200

3 Keys

  • DDRX - Data Direction Register
  • PORTX - Output Pin Addressing
  • PINX - Input Pin Addressing

Code Code !! Code to copy


#include 

int main (void)
  {
  DDRA = 0;		// Data Direction Register
  PORTA = 1;		// Enable pullup on PORTA, bit 0
  DDRB = 1;
  
  for(;;)
    PORTB = PINA;
}				

Macros for bit Manipulation

  • BITVAL(bit position)
  • SETBIT(variable, bit position)
  • CLRBIT(variable, bit position)
  • GETBIT(variable, bit position)

Macros in code


#include "mh-digital.c"

int main (void)
  {
  uint8_t  val;
  DDRA = 0;		// PORTA as Input
  PORTA = 1;		// Enable pullup PA0
  DDRB = 1;		// configure PB0 as output

  for(;;)
     {
     val = GETBIT(PINA, 0);
     if (val != 0)
	    PORTB = 1; //SETBIT(PORTB, 0);
     else
	    PORTB = 0; //CLRBIT(PORTB, 0);
     }
}

Explore mh-digital.c from Library

Alternatives


#include   // Include file for I/O operations

int main (void)
{
DDRA = 0;             // Port A as Input
PORTA = 1;          // Enable pullup on PA0
DDRB = 1;             // Configure PB0 as output  

for(;;)
   if(PINA & 1)        // If PA0 is set
       PORTB |= 1;     // Set PB0, by ORing with 00000001b
   else                // otherwise clear PB0
       PORTB &= ~1;    // by ANDing with 11111110b (~00000001b)
}

its in code

??

?

PC - MicroHOPE

Code >> Compile >> Upload

AVR GCC & AVR DUDE



$ avr-gcc -Wall -O2 -mmcu=atmega32 -o code code.c
$ avr-objcopy -j .text -j .data -O ihex code code.hex
$ avrdude -b 19200 -P /dev/ttyACM0 -pm32 -c stk500v1 -U flash:w:code.hex

Schematics

schematic

UART

schematic

schematic

Time to blink

Blink :)



#include "mh-utils.c"


int main (void)
  {
  DDRB = 255;		// Data Direction Register for port B

  for(;;)
    {
    PORTB = 1;	
    delay_ms(50);
    PORTB = 0;
    delay_ms(50);
  }
return 0;
}

Thats It !!

Akshai M
Email : akshai.m@ieee.org