没有用到看门狗, 整个程序如下,帮我看看吧,我不想再受打击。
#include <iom16v.h>
#include <macros.h>
#define uchar unsigned char
#define uint unsigned int
uchar displaycode[10] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
uchar posistion[4] = {0x70,0xb0,0xc0,0xe0};
uchar displaybuffer[4] = {0,0,0,0};
void delay_ms(uint delaytime)
{
uint i;
for(;delaytime>0;delaytime--)
{
for(i=0;i<125;i++)
{;}
}
}
void port_init(void)
{
PORTC = 0x00;
DDRC = 0xFF;
PORTD = 0xF0;
DDRD = 0x00;
}
void convert(uint data)
{
uchar i;
for(i = 0;i<4;i++)
{
displaybuffer[4-i] = data%10;
data = data/10;
}
}
void display()
{
uchar i;
for(i=0;i<4;i++)
{
PORTD = posistion[i];
PORTC = displaycode[displaybuffer[i]];
delay_ms(300);
}
}
void main()
{
uint k;
port_init();
k = 1234;
convert(k);
while(1)
{
display();
}
} |