Robot_2010.c
/********************************************************************
* *
* Base firmware for Task robot (year 2010 version) *
* (SAMPLE CODE) *
* *
* MCU: ATmega324p *
* Clock: 16MHz XTAL *
* Compiler: WinAVR (avr-gcc) version 20071221 *
* *
* - Toni Harju 2010 *
* *
********************************************************************/
#define F_CPU
16000000
// clock frequency for delay.h
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#define XTAL
16000000
// Clock frequency for calculating USART
baudrate
#define BAUD
38400
// USART BAUDRATE, 9600bps
#include "USART1.c"
#include "LaserCard.c"
#define strobe 0
#define DIR_Y 1
// Y axis, direction
#define CLK_Y 2
// Y axis, clock
#define Y_END_R 2
// Boundary switch, "right" end
#define Y_END_L 3
// Boundary switch, "left" end
#define DIS 3
#define DIR_Z 5
// Z axis, direction
#define CLK_Z 6
// Z axis, clock
#define Z_END_F 1
// Boundary switch, "front"
#define Z_END_B 0
// Boundary switch, "back"
// movement directions (used in main() and Move())
#define MV_UP
1
#define MV_DOWN
2
#define MV_LEFT
3
#define MV_RIGHT
4
// function prototypes
void Move(unsigned char dir, unsigned char steps);
char StrCompare(const char *ref, unsigned char *data);
// global variables
// main program begins here...
//
// - TKH 2010
int main(void)
{
ACSR |= 1<<ACD;
// disable the comparator
DDRA = 0xFF;
// PORTA, all outputs
PORTA=0b01001101;
// portB directions
DDRB = 0b11000000;
// portB initial state
PORTB = 0b10000000;
// Initialize the LaserCard
_Init_LaserCard();
// initialize the USART
Sivu 1