我有一个使用AtMega 328 / L 40pin的机器人,直到最近我还需要更多资源,所以我搬到了Atmega 644p。
寄存器和位名称在两者之间是不同的,说实话,我不能让新的工作正常。我确信我已经按照数据表中的说明进行了更改,但我觉得我缺乏了解其中的知识。
以下是328功能:
{
portInit(); // Setup port directions and initial values.
// This is the most important step!
cli(); // Disable global interrupts.
// UART:
UBRRH = UBRR_BAUD_LOW >> 8; // Setup UART: Baud is Low Speed
UBRRL = (uint8_t) UBRR_BAUD_LOW;
UCSRA = 0x00;
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0);
UCSRB = (1 << TXEN) | (1 << RXEN) | (1 << RXCIE);
// Initialize ADC:
ADMUX = 0; //external reference
ADCSRA = (0<<ADIE) | (0<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADIF);
SFIOR = 0;
// Initialize External interrupts - all disabled:
MCUCR = (1 << ISC11) | (1 << ISC10) | (1 << ISC01) | (1 << ISC00);
GICR = (0 << INT2) | (0 << INT1) | (0 << INT0);
MCUCSR = (0 << ISC2);
// 10kHz Timer 0:
TCCR0 = (0 << WGM00)
| (1 << WGM01)
| (0 << COM00)
| (0 << COM01)
| (0 << CS02)
| (1 << CS01)
| (0 << CS00);
OCR0 = 199;
//Timer 1 is free for your application!
// Timer 2 - used for beeper:
TCCR2 = 0;
OCR2 = 0xFF;
// Enable timer interrupts:
TIMSK = (1 << OCIE0);
sei(); // Enable Global Interrupts
}
以下是我正在尝试的代码:
{
portInit(); // Setup port directions and initial values.
// This is the most important step!
cli(); // Disable global interrupts.
// UART:
//UBRRH = UBRR_BAUD_LOW >> 8; // Setup UART: Baud is Low Speed
//UBRR0L = (uint8_t) UBRR_BAUD_LOW;
//UCSR0A = 0x00;
//UCSR0C = ((1<<UCSZ00));
//UCSR0B = (1 << TXEN0) | (1 << RXEN0) | (1 << RXCIE0);
// Initialize ADC:
ADMUX = 0; //external reference
ADCSRA = (0<<ADIE) | (0<<ADEN) | (1<<ADPS2) | (1<<ADPS1) | (1<<ADIF);
ADCSRB = 0;
// Initialize External interrupts - all disabled:
//MCUCR
SMCR = (1 << ISC11) | (1 << ISC10) | (1 << ISC01) | (1 << ISC00);
EIMSK = (0 << INT2) | (0 << INT1) | (0 << INT0);
MCUSR = (0 << ISC20);
// 10kHz Timer 0:
TCCR0A = (0 << WGM00)
| (1 << WGM01)
| (0 << COM0A0)
| (0 << COM0A1);
TCCR0B = (0 << CS02)
| (1 << CS01)
| (0 << CS00);
OCR0A = 199;
/*
Timer 1 is free for your application!
*/
// Timer 2 - used for beeper:
TCCR2A = 0;
OCR2A = 0xFF;
// Enable timer interrupts:
TIMSK0 = (1 << OCIE0A);
sei(); // Enable Global Interrupts
}
我以前从未使用过这些,所以我正在努力。
有什么明显的我在这里做错了吗?
亲切的问候 利