Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)
Paste
Pasted as C by a ( 14 years ago )
/**
* \file
*
* \brief Empty user application template
*
*/
/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
#include <asf.h>
#define MYBSEL 12
volatile uint16_t receivedData;
unsigned char USART_Receive(void)
{
/* Receive one char. */
/* Wait until data received or a timeout.*/
while ( !( USARTC0.STATUS & USART_RXCIF_bm) );
receivedData = USARTC0.DATA;
}
void USART_Transmit(unsigned char data)
{
/* Wait for empty transmit buffer */
//while ( !( UCSR0A & (1<<UDRE0)) )
while ( !( USARTC0.STATUS & USART_DREIF_bm) )
;
/* Put data into buffer, sends the data */
USARTC0.DATA = data;
//UDR0 = data;
}
void USART_Init(unsigned int bsel) {
int bscale = 0;
/* Set baud rate */
USARTC0.BAUDCTRLA = (unsigned char)(bsel & 0xFF);
USARTC0.BAUDCTRLB = ((unsigned char)(bscale & 0x0F)<< 4) | ((unsigned char)(bsel >> 8) & 0x0F);
//UBRR0H = (unsigned char)(ubrr>>8);
//UBRR0L = (unsigned char)ubrr;
/* Set frame format: 8data, 1 stop bit */
USARTC0.CTRLC = (USARTC0.CTRLC & ~USART_CHSIZE_gm) | USART_CHSIZE_8BIT_gc;
//UCSR0C = (3<<UCSZ00);
/* Enable receiver and transmitter */
USARTC0.CTRLB = (USART_RXEN_bm | USART_TXEN_bm);
//UCSR0B = (1<<RXEN0)|(1<<TXEN0);
}
ISR(TCC0_OVF_vect)
{
USART_Transmit('b');
}
ISR(BADISR_vect){}
int main(void)
{
board_init();
PORTE.DIR==0xff;
PORTE.OUT==0xff;
TCC0.PER=0x03D0; //g�rna granica licznika: 976
TCC0.CTRLA=0x07; //w��cz licznik z preskalerem na 1024
TCC0.INTCTRLA=0x03; //najwi�kszy priorytet przerwania
PMIC.CTRL=0x04; // w��cznie przerwa� o najwy�szym priorytecie
sei(); //globalne w��czenie przerwa�
USART_Init(MYBSEL);
PORTC.DIRSET = PIN3_bm; // PC3 (TXD0) as output.
PORTC.DIRCLR = PIN2_bm; // PC2 (RXD0) as input.
while(1)
{
USART_Receive();
PORTE.OUTTGL=0xff;
USART_Transmit('x');
}
return 0;
}
Nowy dokument tekstowy (3).txt
#include <avr/io.h>
#include <avr/interrupt.h>
#include <asf.h>
#define false 0
#define true 1
/* Task 1
*
* This code will output a triangle waveform on a DAC channel. A blocking while
* loop is used to ensure that the data register is empty before a new value is written.
* If changing the TRIANGLE_ABRUPTNESS, the frequency of the signal will change.
*/
// A value of 100 will output a triangle with frequency around 380 Hz
// (this was read from the scope)
volatile int TRIANGLE_ABRUPTNESS=500;
volatile int max=0x1000;
ISR(PORTF_INT0_vect)
{
if((PORTF.IN & 0x01) == 0x00)
{
TRIANGLE_ABRUPTNESS=500;
//max=0x2000;
PORTE.OUTTGL=0x01;
}
else{
if((PORTF.IN & 0x02) == 0x00){
TRIANGLE_ABRUPTNESS=100;
//max=0x1000;
PORTE.OUTTGL=0x02;}
}
}
ISR(BADISR_vect){}
int main( void )
{
board_init();
PMIC.CTRL=0x04; // w��cznie przerwa� o najwy�szym priorytecie
sei(); //globalne w��czenie przerwa�
PORTE.DIR=0xff; //portE wyj�ciowy
PORTE.OUT=0xff;
PORTF.DIR=0x00;
PORTF.INTCTRL = ( PORTF.INTCTRL & ~PORT_INT0LVL_gm )|3;
PORTF.INT0MASK = 0xff;
// First we have to enable the audio amplifier by setting PQ3 high.
PORTQ.PIN3CTRL = (PORTQ.PIN3CTRL & ~PORT_OPC_gm) | PORT_OPC_PULLUP_gc;
uint16_t angle;
// Use AVCC as Voltage Reference
DACB.CTRLC = ( DACB.CTRLC & ~DAC_REFSEL_gm) | DAC_REFSEL_AVCC_gc;
// Use Single Conversion Mode
DACB.CTRLB = ( DACB.CTRLB & ~DAC_CHSEL_gm ) | DAC_CHSEL_SINGLE_gc;
// Enable Channel 0 and Enable the (entire) DACB module
DACB.CTRLA = DAC_CH0EN_bm | DAC_ENABLE_bm;
while (1) {
for ( angle = 0; angle < max; angle += TRIANGLE_ABRUPTNESS )
{
// Wait for Data register Empty
while ( (DACB.STATUS & DAC_CH0DRE_bm) == false );
// Write the part of the triangle pointing upwards
DACB.CH0DATA = angle;
}
for ( angle = 0; angle < max; angle += TRIANGLE_ABRUPTNESS )
{
// Wait for Data register Empty
while ( (DACB.STATUS & DAC_CH0DRE_bm) == false );
// Write the part of the triangle pointing downwards
DACB.CH0DATA = 0xFFF- angle;
}
}
}
Nowy dokument tekstowy.txt
/**
* \file
*
* \brief Empty user application template
*
*/
/*
* Include header files for all drivers that have been imported from
* Atmel Software Framework (ASF).
*/
#include <asf.h>
int a=0;
//void PORT_ConfigureInterrupt0(
//PORT_INT0LVL_t intLevel)
//{
//PORTF.INTCTRL = ( PORTF.INTCTRL & ~PORT_INT0LVL_gm ) | intLevel;
//PORTF.INT0MASK = 0xff;
//}
ISR(TCC0_OVF_vect)
{
if(a == 1)
{
if((PORTE.OUT & 0x01) == 0x00)
{
PORTE.OUT=0xff;
PORTE.OUTSET=0x7f;
}
else
{
PORTE.OUT=PORTE.OUT>>1;
}
}
else
{
if((PORTE.OUT & 0x80) == 0x00)
{
PORTE.OUT=0xff;
PORTE.OUTSET=0xfe;
}
else
{
PORTE.OUT=PORTE.OUT<<1;
}
}
}
ISR(PORTF_INT0_vect)
{
if((PORTF.IN & 0x01) == 0x00)
{
a=1;
}
else{
if((PORTF.IN & 0x02) == 0x00)
a=0;}
}
ISR(BADISR_vect){}
int main(void)
{
board_init();
TCC0.PER=0x03D0; //g�rna granica licznika: 976
TCC0.CTRLA=0x07; //w��cz licznik z preskalerem na 1024
TCC0.INTCTRLA=0x03; //najwi�kszy priorytet przerwania
PMIC.CTRL=0x04; // w��cznie przerwa� o najwy�szym priorytecie
sei(); //globalne w��czenie przerwa�
PORTE.DIR=0xff; //portB wyj�ciowy
PORTE.OUT=0xfe; //dla migania LED
PORTF.DIR=0x00;
// PORTF.OUT=0xff;
//PORTF.PIN0CTRL=0x18;
// PORTF.PIN1CTRL=0x18;
//unsigned long zmienna;
PORTF.INTCTRL = ( PORTF.INTCTRL & ~PORT_INT0LVL_gm )|3;
PORTF.INT0MASK = 0x03;
while(1)
{
//PORTE.OUT&=PORTF.IN;
//if((PORTF.IN & 0x01) == 0x00)
//{
//a=1;
//}
//else
//a=0;
//if((PORTF.IN & 0x03) == 0x01)
//{
// a=0;
//}
// zmienna=0xb9ca8; //oczekiwanie oko�o 1sek. dla cpu 32MHz
// while(zmienna>0) zmienna--;
// PORTB_OUT=~PORTB_OUT;
}
return 0;
}
Revise this Paste