Step 5Moving from Arduino to AVR
The fuses are set to an 8Mhz internal RC timer since timing isn't critical. Once done with the code, go right ahead and solder the circuit together.
Below is the code I used for the AVR. If you aren't familiar with AVR programming, most of what you need can be found here:http://iamsuhasm.wordpress.com/tutsproj/avr-gcc-tutorial/ and the tutorials here: http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewforum&f=11&sid=f899212b86e2e0de2b660c0999f95fd7
#include <avr/io.h>
#include <util/delay.h>
#include <avr/sfr_defs.h>
#define lights PB0
#define magSense PB1
void initPorts();
int main(void)
{
volatile uint16_t val; // variable for reading the pin status
//volatile uint16_t lightMode = 0; // variable to keep the light's state
initPorts();
while(1){
val = bit_is_set(PINB, magSense); // read input value and store it in val
if (val) // make sure we got a 1
PORTB |= (1 << lights);
else
PORTB &= ~(1 << lights);
}
return 0;
}
void initPorts(){
PORTB = 0b000010; // enable pull up on sensor pin
DDRB = 0b000001; // set PB0 as output and rest as input
}
main.c729 bytes| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|












































