从 AtMega328 迁移到 AtMega644p
我有一个机器人,它使用 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
}
我以前从未使用过这些代码,所以我正在尽力而为。
我在这里做错了什么明显的事情吗?
亲切的问候 李
I have a robot which used a AtMega 328/L 40pin until recently when I needed more resources, so I moved to the Atmega 644p.
The registers and bit names are different between the two and to be honest I just cannot get the new one to work properly. I am certain I have followed the changes as stated in the datasheet, but feel that my lack of knowledge in standing in the way.
Here is the 328 function that did work:
{
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
}
And here is the code I am trying to get working:
{
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
}
I have never worked with these before so I am trying my best.
Is there anything obvious that I am doing wrong here?
Kind Regards
Lee
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论