Orangutan Sample code

I just bought 4 Orangutan controllers for a project I am working on. I powered up the first one and noticed that they come pre-flashed with sample code that, at the least, communicates with the LCD and reads the A/D. Is the source code for this pre-installed firmware available anywhere?

Thanks,
Robotguy

Hello,

We’ve just been using the hex file for a while, so this hasn’t been tested with recent versions of the development tools. I hope it will at least give you some starting point for using the LCD.

-Jan

#include <avr/io.h>
#include <avr/delay.h>

//#include "serial.h"

/*
** Programming
** Buzzer
** Reset
** Power Switch
** Power LED
   Trimmer Pot
** LED 
   I/O pins
** Motors
   Push buttons
** LCD
*/


/*
** Delays
*/

#define	Delay( x )	_delay_loop_2( x )

void	Big_Delay( void )
{
	Delay( 60000 );
	Delay( 60000 );
	Delay( 60000 );
	Delay( 60000 );
}

/*
**
*/

void Speaker( void )
{
	DDRB = 1;
	DDRD = 2;
	while ( 1 ) {

		PORTD = 0;
		if ( PINB & BV(3) ) {
			PORTD = 2;
			PORTB = PORTB ^ 1;
			Delay( 50 );
		}
/*		if ( PINB & BV(4) ) {
			PORTB = PORTB ^ 1;
			Delay( 100 );
		}*/
		if ( PINB & BV(5) ) {
			PORTB = PORTB ^ 1;
			Delay( 200 );
		}
	}
}

void Motors( void )
{
	DDRB = BV(1) | BV(2);
	DDRD = BV(5) | BV(6);
	
	while ( 1 ) {
		PORTB |= BV(1);
		PORTD &= ~BV(5);
		Big_Delay();
		PORTB |= BV(2);
		PORTD &= ~BV(6);
		Big_Delay();
		PORTB &= ~BV(1);
		PORTD |= BV(5);
		Big_Delay();
		PORTB &= ~BV(2);
		PORTD |= BV(6);
		Big_Delay();
	}
}

/*
** LCD
*/
#define LCD_COMMAND_CLEAR	0x01
#define LCD_COMMAND_LINE1	0x02
#define LCD_COMMAND_LINE2	0xC0

#define	LCDDelay	_delay_loop_2

void	LCDSendNibble( unsigned char data )
{
	data &= 0x0F;
	data <<= 3;
	PORTB &= ~0x38;
	PORTB |= (data & 0x38);
	data <<= 1;
	PORTD &= ~0x80;
	PORTD |= (data & 0x80);
	PORTD |= BV(4);		//	LCD_STROBE = 1;
	_delay_loop_1( 200 );
	PORTD &= ~BV(4);	//	LCD_STROBE = 0;
	_delay_loop_1( 200 );
}

void	LCDData( unsigned char data )
{
	PORTD |= BV(2);		// LCD_RS = 1;
	LCDSendNibble( data >> 4 );
	LCDSendNibble( data );
}

void	LCDString( const unsigned char *str )
{
    while (*str != 0)  {
		LCDData( *str++ );
    }
}

void	LCDCommand( unsigned char data )
{
	PORTD &= ~BV(2);		// LCD_RS = 0;
	LCDSendNibble( data >> 4 );
	LCDSendNibble( data );
	LCDDelay( 100 );
}

void	LCDHexNibble( unsigned char data )
{
	data &= 0x0F;
	if ( data > 9 ) {
		data += ('A' - '9' - 1);
	}
	LCDData( data + '0' );
}

void	LCDHex( unsigned char data )
{
	LCDHexNibble( data >> 4 );
	LCDHexNibble( data );
}

void	LCDInit( void )
{
	DDRB |= BV( 3 ) | BV( 4 ) | BV( 5 );
	DDRD |= BV( 7 ) | BV( 4 ) | BV( 3 ) | BV( 2 );
	PORTD &= ~BV(4);	//	LCD_STROBE = 0;
	PORTD &= ~BV(3);	//	r/w = 0
	LCDDelay( 200 );
	LCDCommand( 0x32 );
	LCDCommand( 0x20 );
	LCDCommand( 0x1C );
	LCDCommand( LCD_COMMAND_CLEAR );
	LCDCommand( 0x28 );
	LCDCommand( 0x06 );
	LCDCommand( 0x0C );
}


/*
**
*/
int main(void)
{
//	Serial_Init();

	LCDInit();
	LCDString( "Orangutan" );


	DDRB = 0;
	DDRD |= BV(1);
	PORTB = 0;
	//PORTB &= ~BV(5);
/*	while (1) {
		if (PINB & BV(5)){
		PORTD &= ~BV(1);	//	LCD_STROBE = 0;
		//Delay( 20000 );
		} else {
		PORTD |= BV(1);		//	LCD_STROBE = 1;
		//Delay( 20000 );
		}
	}
*/

	ADCSR |= (1 << ADPS2);
	ADCSR |= (1 << ADFR);
	ADMUX = 7;
	ADCSR |= (1 << ADEN);
	ADCSR |= (1 << ADSC);

	LCDInit();
	LCDString( "Orangutan" );

	while ( 1 ) {
		static int i = 0;
		LCDCommand( LCD_COMMAND_LINE2 );
		i++;
		LCDHex( ADC >>8 );		
		LCDHex( ADC );
		if (PINB & BV(5)){
		PORTD &= ~BV(1);	//	LCD_STROBE = 0;
		//Delay( 20000 );
		} else {
		PORTD |= BV(1);		//	LCD_STROBE = 1;
		//Delay( 20000 );
		}
	}

//	Motors();

	return 0;
}

Thanks! I have to use Codevision (the project is for my work) so I am going to have some conversion to do anyway, This will at least give me a leg up.

-Robotguy

Jan:

i’ve copied and pasted your code from above, and tried to compile it with WinAVR. i get the following error. can you give some insight? what is the BV(.) function doing?

“make.exe” all

-------- begin --------
avr-gcc (GCC) 3.4.6
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


Compiling: Sample02.c
avr-gcc -c -mmcu=atmega168 -I. -gstabs   -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=Sample02.lst  -std=gnu99 -Wp,-M,-MP,-MT,Sample02.o,-MF,.dep/Sample02.o.d Sample02.c -o Sample02.o 
Sample02.c: In function `Speaker':
Sample02.c:47: warning: implicit declaration of function `BV'
Sample02.c: In function `main':
Sample02.c:188: error: `ADCSR' undeclared (first use in this function)
Sample02.c:188: error: (Each undeclared identifier is reported only once
Sample02.c:188: error: for each function it appears in.)
Sample02.c:189: error: `ADFR' undeclared (first use in this function)
make.exe: *** [Sample02.o] Error 1

Process Exit Code: 2
Time Taken: 00:00

thanks,
it