Hallo Zusammen,

in diesem Thread werde ich einen kleinen Frevel begehen, nämlich ( zumindest in Ansätzen ) das RP6-Betriebssystem durch die ASURO-Lib zu ersetzen. Damit wird der RP6 sozusagen ein ASURO mit Ketten.
Meiner Meinung nach ist es die beste Möglichkeit, sich mit einem neuen System zu beschäftigen, in dem man die bisherigen Erfahrungen nutzen kann. Und da ich nun einmal relativ viel Erfahrungen mit dem ASURO habe, möchte ich einige Programme auf den RP6 übertragen. Dazu ist es notwendig, dass ein ASURO-kompatible Library existiert.

Für Anfänger, die schon einige Erfahrungen mit dem ASURO haben ist es mit der Verwendung einer solchen Library natürlich besonders einfach, Programme für den RP6 zu schreiben, da keine neuen Befehle gelernt werden müssen.

Hier also der Code für asuro.c und asuro.h:
Code:
//*********** ASURO Library modified for RP6 *****************************
//
// asuro.c
//
//************************************************************************
#include "asuro.h"
#include "string.h"

volatile unsigned char count36kHz;	
volatile unsigned long timebase;

SIGNAL (SIG_OVERFLOW2)
{
	TCNT2 += 0x25;
	count36kHz ++;
	if (!count36kHz) timebase ++;
}


/* Set motor speed */
inline void MotorSpeed(unsigned char left_speed, unsigned char right_speed)
{
	OCR1A = left_speed;
	OCR1B = right_speed;
}

/* Set motor direction */
inline void MotorDir(unsigned char left_dir, unsigned char right_dir)
{
	switch(left_dir)
	{
       	case FWD:
       	{
 			PORTC |= (LEFT_DIR) ;
		}
		break;
		case RWD :
       	{
 			PORTC &=~ (LEFT_DIR) ;
		}
		break;
		default:
		{ 
			OCR1A = 0;
 		}break;			
	}
	
	switch(right_dir)
	{
       	case FWD:
       	{
 			PORTC |= (RIGHT_DIR) ;
		}
		break;
		case RWD :
       	{
 			PORTC &=~ (RIGHT_DIR) ;
		}
		break;
		default:
		{ 
			OCR1B = 0;
 		}break;			

	}

}
/* StatusLED(GREEN); */
inline void StatusLED(unsigned char color)
{
	if (color == OFF)    {GREEN_LED_OFF; RED_LED_OFF;}
	if (color == GREEN)  {GREEN_LED_ON; RED_LED_OFF;} 
	if (color == YELLOW) {GREEN_LED_ON; RED_LED_ON;}
	if (color == RED)    {GREEN_LED_OFF; RED_LED_ON;}
}
void BackLED(unsigned char left, unsigned char right)
{
};

/* uses 36kHz timer => Sleep(x) = x/36kHz [sec] */
void Sleep(unsigned char time36kHz)
{   
	unsigned char ziel=(time36kHz+count36kHz) & 0x00FF;
	while (count36kHz != ziel);
}

void Msleep(int dauer)
{
	int z;
	for(z=0;z<dauer;z++) Sleep(36);
}

void Init (void)
{
	//-------- seriell interface programmed in boot routine and already running -------
	//  prepare 36kHz for IR - Communication
	//TCCR2 = (1 << WGM20) | (1 << WGM21) | (1 << COM20) | (1 << COM21) | (1 << CS20);
	TCCR2 = (1 << WGM20) | (1 << WGM21) | (1 << CS20);

	OCR2  = 0x91; // duty cycle for 36kHz
	TIMSK |= (1 << TOIE2); // 36kHz counter for sleep
		
	// I/O Ports
	DDRC = GREEN_LED | RED_LED; 

	// Motor Bits
	DDRC |= (1<<PC2) | (1<<PC3);
	DDRD=0;
	DDRD |= PWM;
	
	DDRB=0b01011000;
	PORTB=0b00000000;

	// for PWM (8-Bit PWM) on OC1A & OC1B
	TCCR1A = (1 << WGM10) | (1 << COM1A1) | (1 << COM1B1);
	// tmr1 running on MCU clock/8 
	TCCR1B = (1 << CS11);
	
	MotorDir(BREAK,BREAK);
	MotorSpeed(0,0);
	
	sei();
}
//*********** ASURO Library modified for RP6 *****************************
//
// asuro.h
//
//************************************************************************
#ifndef ASURO_H
#define ASURO_H

#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
#include <stdlib.h>

#define  FALSE	0
#define  TRUE	1

#define  OFF    0
#define  ON     1

#define GREEN	1
#define RED	2
#define YELLOW  3

/* neue Funktionen und Variablen*/
#define LEFT    0
#define RIGHT   1

void Msleep(int dauer);
inline void StatusLED(unsigned char color);
void Sleep(unsigned char time36kHz);
inline void MotorDir(unsigned char left_dir, unsigned char right_dir);
inline void MotorSpeed(unsigned char left_speed, unsigned char right_speed);
void BackLED(unsigned char left, unsigned char right);

// RP6 definitions
#define GREEN_LED   (1 << PC4)          	/*!< PB0 Port fuer Gruene Status LED */
#define RED_LED     (1 << PC5)			/*!< PD2 Port fuer Rote Status LED */
#define PWM 	  (1 << PD4) | (1 << PD5)	/*!< PB1, PB2 Ports fuer Pulsweitenmodulation der Motor Geschwindigkeit */
#define RIGHT_DIR (1 << PC3)	/*!Ports fuer Drehrichtung rechter Motor */
#define LEFT_DIR  (1 << PC2)  /*!Ports fuer Drehrichtung linker Motor */
#define BREAK	0x00				/*!< Motor bremsen */
#define FREE	0x00  	/*!< Motor freilaufend ==> gibts nicht beim RP6 */

// ASURO Ports, not uset in RP6
#define FWD	(1 << PB5) 			/*!< Motor vorwaerts */
#define RWD	(1 << PB4) 			/*!< Motor rueckwaerts */

#define GREEN_LED_ON  PORTC |=  GREEN_LED	/*!< Gruene Status LED an */
#define GREEN_LED_OFF PORTC &= ~GREEN_LED	/*!< Gruene Status LED aus */
#define RED_LED_ON    PORTC |=  RED_LED		/*!< Rote Status LED an */
#define RED_LED_OFF   PORTC &= ~RED_LED		/*!< Rote Status LED aus */

#endif /* ASURO_H */

//*********** ASURO Library modified for RP6 *****************************
//
// test.c
//
//************************************************************************
#include "asuro.h"

int main(void)
{
  	Init();
//	Encoder_Init();

		StatusLED(GREEN);
		Msleep(500);
		StatusLED(RED);
		Msleep(500);
		StatusLED(GREEN);
		Msleep(500);
		StatusLED(RED);
		
		Msleep(2000);

		MotorDir(FWD,FWD);
		MotorSpeed(100,100);
		Msleep(2000);
		MotorDir(RWD,RWD);
		Msleep(2000);
		
		MotorSpeed(0,0);



	while(1);
}


Copyrights:

/*!
 * \file asuro.c
 * \brief Die ASURO Bibliothek
 *
 * $Revision: 2.60 $
 * $Date: 27. September 2005 $
 * $Author: Jan Grewe, Robotrixer, Waste, Stochri, Andun, m.a.r.v.i.n $
 *
 */

/*******************************************************************************
*
* File Name:   asuro.c
* Project  :   ASURO
*
* Description: This file contains ASURO main features
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------
* 1.00	   14.08.2003   Jan Grewe        build
* 2.00     14.10.2003   Jan Grewe        LEFT_VEL, RIGHT_VEL -> MotorSpeed(unsigned char left_speed, unsigned char right_speed);
*                                        LeftRwd(),LeftFwd(),RightRwd(),
*                                        RigthFwd() -> MotorDir(unsigned char left_dir, unsigned char right_dir);
*                                        GREEN_ON,GREEN_OFF,RED_ON,RED_OFF -> StatusLED(unsigned char color);
*                                        LED_RED_ON, LED_RED_OFF -> FrontLED(unsigned char color);
*                                        Blink(unsigned char left, unsigned char right) -> BackLED(unsigned char left, unsigned char right);
*                                        Alles in Funktionen gefasst => leichter verst�dlich ?!?!
* 2.10     17.10.2003   Jan Grewe        new Timer funktion void Sleep(unsigned char time36kHz)  
*
* Copyright (c) 2003 DLR Robotics & Mechatronics
*****************************************************************************/
/****************************************************************************
*
* File Name:   asuro.c
* Project  :   asuro library "Robotrixer Buxtehude"
*
* Description: This file contains additional functions:
*
* signal (SIG_ADC)                 interrupt/signal routine for encoder-counter
* signal (SIG_INTERRUPT1)          signal for switches
* Encoder_Init()                   initializing encoder-counter
* Encoder_Start()                  start autoencoding
* Encoder_Stop()                   stop autoencoding
* Encoder_Set(int,int)             set encodervalue
* Msleep(int delay)                wait for delay in milliseconds
* Gettime()                        get systemtime in milliseconds
* PrintInt(int)
*
* modifications in Sleep, SIG_OUTPUT_COMPARE2, PollSwitch, LineData
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------
* beta1	   31.03.2005   Robotrixer	 asuro library
* -------  ----------   --------------   ------------------------------
* the encoder source is based on RechteckDemo.c ver 2.0 by Jan Grewe 22.10.2003 
* Copyright (c) 2003 DLR Robotics & Mechatronics

*****************************************************************************/
/****************************************************************************
*
* File Name:   asuro.c
* Project  :   asuro library modified for IR collision detector
*
* Description: modifications made in following functions:
*
* SIGNAL (SIG_OUTPUT_COMPARE2)	->	SIGNAL (SIG_OVERFLOW2)
* Gettime()				counts now 36kHz
* Init()				timer2 modified for adjustable duty cycle
* Batterie()				bug fixed
* Sleep()				counts now 36kHz
* Msleep()				counts now 36kHz
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------
* beta2	   11.06.2005   Waste   	 asuro library
* -------  ----------   --------------   ------------------------------
*****************************************************************************/
/****************************************************************************
*
* File Name:   asuro.c
* Project  :   asuro library 
*
* Description: This file contains additional functions:
*
* motor control functions 29.7.2005 stochri
* void Go(int distance)
* void Turn(int degree)
*
* unsigned char Wheelspeed[2]		measured Wheelspeed by interupt
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------------------
* sto1     29.07.2005   stochri		 asuro library with motor control functions
* -------  ----------   --------------   ------------------------------------------
*****************************************************************************/
/****************************************************************************
*
* File Name:   asuro.c
* Project  :   asuro library 
*
* Description: modifications made in following functions:
*
* void Go(int distance, int speed)
* void Turn(int degree, int speed)
*
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------------------
* And1     31.07.2005   Andun		 Added Speed and Odometrie
* -------  ----------   --------------   ------------------------------------------
*****************************************************************************/
/****************************************************************************
*
* File Name:   asuro.c
* Project  :   asuro library 
*
* Description: modifications made in following functions:
*
* void PrintInt(int wert)
*
*
* Ver.     Date         Author           Comments
* -------  ----------   --------------   ------------------------------------------
* 2.60     28.09.2005   m.a.r.v.i.n      doxygen comments 
* -------  ----------   --------------   ------------------------------------------
*****************************************************************************/
/***************************************************************************
*                                                                         *
*   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     *
*   any later version.                                                    *
***************************************************************************/
Bester Gruß,
stochri

Edit:
V0.1: Msleep und StatusLED erstellt
V0.2: MotorSpeed und MotorDir eingefügt