April 15, 2004

ATmega162 Serial and PWM are Working

Hey! Enki has moved his blog to Armyofevilrobots.com. Check it out after you are done here. This page is going nowhere though...

avrmegaproto_thumb.jpgNot exactly for robots, but it applies. I have gotten serial and PWM up on an ATmega162 uController. I love the GNU toolchain that is available for this chip. I have included some code below in case you are having trouble getting your serial connection up on this chip....

#include 
#include 
#include 
#include 
#ifndef _AVR_SFR_DEFS_H_
#include 
#endif

#if defined(__AVR_ATmega162__)
#  define OC1 PD5
#  define DDROC DDRD
#  define OCR OCR1A
#else
#  error "Don't know what kind of MCU you are compiling for"
#endif


void ioinit(){
	DDRC=0xFF;
	DDRB=0xFF;
	
			// bit 0 & bit 1 = 8 bits pwm
			// bit 2 + 3 = force output // + toggle the output
	TCCR0= ((_BV(WGM00))|
		(_BV(WGM01))|
		(_BV(COM01))|
		(_BV(COM00))|
		(_BV(CS02)));
		
		
	TCCR2= ((_BV(WGM20))|
		(_BV(COM21))|
		(_BV(COM20))|
		(_BV(CS20))|
		(_BV(CS21))|
		(_BV(CS22))
		);	
			//Set phase correct PWM, 	
	OCR2=128;
	OCR0=128;			
	sei();
	
}

void ser_init(){
	DDRD =2;	//Just to ensure the port can send/receive.
	
	UBRR0H=	0;
	UBRR0L=	29&255;
	UCSR0B=	_BV(RXEN0)|
		_BV(TXEN0);
	UCSR0C=	(1<

Posted by Enki at April 15, 2004 03:55 PM
| TrackBack


Comments

Online Cialis information site.

Posted by: Cialis at October 9, 2004 07:54 AM

Levaquin online information.

Posted by: Levaquin at October 13, 2004 07:20 AM

Seasonale online site.

Posted by: Seasonale at October 14, 2004 06:29 PM

Generic Fioricet online site.

Posted by: buy Generic Fioricet at October 16, 2004 07:31 AM

Online Fioricet information site.

Posted by: Fioricet at October 17, 2004 07:29 PM

Remeron online site.

Posted by: Remeron at October 22, 2004 03:34 PM

For Effexor information.

Posted by: Effexor at October 23, 2004 06:18 PM

Check Celexa info.

Posted by: Buy Celexa at October 25, 2004 09:22 AM

Elidel information.

Posted by: Elidel online at November 3, 2004 01:09 PM

Cheap Wellbutrin online.

Posted by: Wellbutrin at November 5, 2004 12:34 PM
Post a comment









Remember personal info?