Microcontrollers for Hobby Projects and Education
Yet another controller board ?
USB - UART
#include
int main (void)
{
DDRA = 0; // Data Direction Register
PORTA = 1; // Enable pullup on PORTA, bit 0
DDRB = 1;
for(;;)
PORTB = PINA;
}
#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
#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
?
Code >> Compile >> Upload
$ 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
#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;
}