//ICC-AVR application builder : 2007-7-17 16:07:21 // Target : M8 // Crystal: 8.0000Mhz #include <iom8v.h> #include <macros.h> unsigned char valu; unsigned char led[6]={1,0,0,0,0,6}; unsigned int i;
void delay(unsigned int t) //延迟 {unsigned char w; w=t*1000; while(w>=0) {w--; } } void xs_zh(unsigned char b) //扫描显示 { PORTD = (PIND & 0x27) | (0xc0 & led<<4) | (0x18 & led<<3); } void port_init(void) { PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output only DDRC = 0x0E; PORTD = 0x00; DDRD = 0xD8; }
//TIMER0 initialize - prescale:64 // desired value: 2mSec // actual value: 2.000mSec (0.0%) void timer0_init(void) { TCCR0 = 0x00; //stop TCNT0 = 0x06; //set count TCCR0 = 0x01; //start timer }
#pragma interrupt_handler timer0_ovf_isr:10 //用中断来扫描显示 void timer0_ovf_isr(void) { TCNT0 = 0x06; //reload counter value PORTC |= 0x0E;//先关闭显示 xs_zh(i); //送显示数据 PORTC = (PINC & 0xf1) | (0x0e &i<<1); //开显示 i++; //准备显示下一位 if(i>=6)i=0; }
//call this routine to initialize all peripherals void init_devices(void) { //stop errant interrupts until set up CLI(); //disable all interrupts port_init(); timer0_init(); MCUCR = 0x00; GICR = 0x00; TIMSK = 0x01; //timer interrupt sources SEI(); //re-enable interrupts //all peripherals are now initialized } /*——————————————————————————————————————————————*/ void adc_cov(void) //AREF接AVCC(5V) {unsigned int temp1; unsigned int temp2; ADMUX=0X60; ADCSRA=0XC3; delay(1); while(!(ADCSRA&(1<<ADIF))); ADCSRA&=~(1<<ADIF); ADCSRA&=~(1<<ADEN); temp1=(unsigned int)ADCL; temp2=(unsigned int)ADCH; valu=(temp2<<8)+temp1; }
void pocess(void) { led[2]=valu/100; valu%=100; led[1]=valu/10; valu%=10; led[0]=valu; led[3]=0; led[4]=0; led[5]=0; }
void main(void) { init_devices(); while(1) { adc_cov(); pocess(); delay(10); } }
请问一下各位大哥,我这个程序从PC1,2,3输出到74LS138片选LED,从PD3,4,6,7输出BCD码到74LS47译码到LED段码。怎么现在显示出来的只是我初始化的数据,说明AD转换没有问题了,难道我的AD转换就没有出数据吗?急,请指教,谢谢了! |