|
马老师:
你好,刚开始接触过AVR,以前全用汇编写的,也是做51和PIC的,现在刚开始接触AVR,写了个按键数码管显示加1的程序,不知道为什么老是不正确,望指教,程序如下:/ICC-AVR application builder : 2007-12-12 17:27:22
// Target : M16
// Crystal: 14.7456Mhz
#include <iom16v.h>
#include <macros.h>
const led_table[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
typedef unsigned char uint8;
uint8 i;
void port_init(void)
{
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0xFf;
DDRB = 0xFE;
PORTC = 0xFF; //m103 output only
DDRC = 0xFF;
PORTD = 0x00;
DDRD = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialized
}
void delay(void)
{unsigned int j;
for(j=0;j<1000;j++)
{;}
}
void main(void)
{int temp;
init_devices();
while(1){
if(PINB==0XFf)
{PORTA=led_table;
PORTB=0XFe;
PORTC=0X00;
}
else
{delay();
if(PINB==0XFE)
{do{i=i+1;
if(i==10)i=0;
PORTA=led_table;
PORTB=0XFe;
PORTC=0XFf;}while(PINB==0XFF);}
else
{PORTA=led_table;
PORTB=0XFe;
}
}
}} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|