please dont rip this site

main.c

/**********************************************************************
    main.c

    This file is part of the <MyPackage> package

    Copyright (c) 2003 dinux - dinux@mail.bg

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

**********************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>

#include "main.h"
#include "motors.h"


//Stores boolean flags 
volatile struct _bitfield bits_store1;

//Send message to USART
void send_msg( PGM_P msg)
{
	while( *msg ) {
		while(!(UCSR0A & (1<<UDRE0)))  /* Wait until transmit is complete */
			;
		UDR0 = *msg++;
	}
}


int main (void)
{
	uint8_t c;

	
	//Initialize the UART.  - 8N1
	UCSR0B = ( (1<<RXEN0)|(1<<TXEN0) );
#if CPU_CLOCK==11059200
//        UBRR0L = 71; UBRR0H=0;		/* For 11.059 MHz CPU and 9600 RS232 link. */
        UBRR0L = 5; UBRR0H=0;		/* For 11.059 MHz CPU and 115200 RS232 link. */
#endif
#if CPU_CLOCK==16000000
//        UBRR0L = 103; UBRR0H=0;         /* For 16 MHz CPU and 9600 RS232 link. */
        UBRR0L = 25; UBRR0H=0;		/* For 16 MHz CPU and 38.4 RS232 link. */
#endif
#if CPU_CLOCK==18432000
//        UBRR0L = 119; UBRR0H=0;         /* For 18.4320 MHz CPU and 9600 RS232 links */
        UBRR0L = 9; UBRR0H=0;		/* For 18.4320 MHz CPU and 115200 RS232 link. */
//	UBRR0L = 4; UBRR0H=0;		/* For 18.4320 MHz CPU and 230400 RS232 link. */
#endif
	UCSR0C = (1<<UCSZ00)|(1<<UCSZ01);       //8 bit


	//Enter the main loop.
	for(;;) {
		while(!(UCSR0A & (1<<RXC0))) {	//Wait for a byte
		}
		c = UDR0;
		//Parse the input
		switch(c) {
			case ' ':
				send_msg(PSTR("Both motors stopped\r\n"));
				set_left_motor(0);
				set_right_motor(0);
				break;
			case 'q':
			case 'Q':
				send_msg(PSTR("Left motor forward\r\n"));
				set_left_motor(1);
				break;
			case 'a':
			case 'A':
				send_msg(PSTR("Left motor stopped\r\n"));
				set_left_motor(0);
				break;
			case 'z':
			case 'Z':
				send_msg(PSTR("Left motor backward\r\n"));
				set_left_motor(2);
				break;
			case 'w':
			case 'W':
				send_msg(PSTR("Right motor forward\r\n"));
				set_right_motor(1);
				break;
			case 's':
			case 'S':
				send_msg(PSTR("Right motor stopped\r\n"));
				set_right_motor(0);
				break;
			case 'x':
			case 'X':
				send_msg(PSTR("Right motor backward\r\n"));
				set_right_motor(2);
				break;
			default:
				send_msg(PSTR("? Unkown keystroke\r\n"));
		}	
	}

	return 0;
}

See also:


file: /Techref/atmel/avr/avrbot-main.c, 3KB, , updated: 2004/2/14 21:37, local time: 2018/11/16 02:33, owner: JMN-EFP-786,
TOP NEW HELP FIND: 
54.144.100.123:LOG IN

 ©2018 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE! / 

<A HREF="http://www.piclist.com/techref/atmel/avr/avrbot-main.c"> main.c</A>

Did you find what you needed?

  PICList 2018 contributors:
o List host: MIT, Site host massmind.org, Top posters @20181116 RussellMc, Van Horn, David, Sean Breheny, David C Brown, Isaac M. Bavaresco, Bob Blick, Neil, John Gardner, AB Pearce - UKRI STFC, Harold Hallikainen,
* Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.
 

Welcome to www.piclist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .