c代码
/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.5a Evaluation
Automatic Program Generator
?Copyright 1998-2011 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project :
Version :
Date : 2012/1/9
Author : Freeware, for evaluation and
non-commercial use only
Company :
Comments:
Chip type : ATmega16
Program type : Application
AVR Core Clock frequency: 4.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
flash unsigned char led_7[10] = {0x3F,0x06,0x5B,0x4f,0x66,0x6D,0x7D,0x07,0x7F,0x6F} ;
flash unsigned char position[4] = {0xfe,0xfd,0xfb,0xf7};
unsigned char dis_buff[4]={0,0,0,},posit;
bit time_2ms_ok ;
void adc_to_disbuffer(unsigned int adc)
{
unsigned char i;
for (i=0;i<=3; i++)
{
dis_buff[i] = adc %10;
adc /= 10;
}
}
interrupt[TIM0_COMP] void timer0_comp_isr(void)
{
time_2ms_ok = 1;
}
interrupt[ADC_INT] void adc_isr(void)
{
unsigned int adc_data,adc_v;
adc_data = ADCW ;
adc_v = (unsigned long) adc_data * 5000/1024 ;
adc_to_disbuffer(adc_v);
}
void display(void)
{
PORTA |= 0x0f;
PORTC = led_7[dis_buff[posit]];
if(posit== 3) PORTC |= 0x80;
PORTA &= position[posit];
if(++posit >= 4) posit = 0;
}
void main(void)
{
DDRA = 0x0f;
PORTA = 0x0F;
DDRC = 0xff;
PORTC = 0x00;
TCCR0 = 0x0B;
TCNT0 = 0x00;
OCR0 = 0x7c;
TIMSK = 0x02;
ADMUX = 0x47;
SFIOR &= 0x1F;
SFIOR |=0x60;
ADCSRA = 0xAD;
#asm("sei")
while (1)
{
if(time_2ms_ok)
{
display();
time_2ms_ok = 0;
}
}
}