程序如下,本来网上有大把的,但我是学习,我想搞清楚我这个程序究竟哪里错了,这样才能达到学习的目的。谢谢先!!!
#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] = {0x10,0x20,0x40,0x80};
uchar displaybuffer[4] = {0xff,0xff,0xff,0xff};
void delay_ms(uint delaytime)
{
uint i;
for(;delaytime>0;delaytime--)
{
for(i=0;i<125;i++)
{;}
}
}
void port_init(void)
{
PORTA = 0X00;
DDRA = 0X00;
PORTC = 0x00;
DDRC = 0xFF;
PORTD = 0xF0;
DDRD = 0x00;
}
void convert(uint data)
{
uchar i;
for(i=0;i<=3;i++)
{
displaybuffer[3-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(5);
}
}
#pragma interrupt_handler adc_isr:iv_ADC
void adc_isr(void)
{
uint ADC_value;
uint ADC_data;
ADC_data=ADCL;
ADC_data|=(int)ADCH << 8;
ADC_value = (unsigned long)ADC_data*5000/1024;
convert( ADC_value);
ADCSRA|=0x50;
}
void main()
{
uint k;
port_init();
SEI();
ADMUX = 0x41;
ADCSRA = 0Xc9;
delay_ms(10);
while(1)
{
display();
}
} |