电路原理图如下:
- #include <iom16v.h>
- #include <macros.h>
- #define uchar unsigned char
- #define uchar unsigned int
- const uchar SEG_CODE[] =
- {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0xFF};
- uchar display[] = {0,0,0,10,0,0,0,10};
- void delay(uint mS);
- void main()
- {
-
- uchar i;
-
- DDRA = 0xfc;
-
- DDRC = 0xff; PORTC = 0x00;
-
- DDRD = 0xff; PORTD = 0x00;
-
- ADCSRA = 0xE6;
-
- delay(300);
-
-
- while(1)
-
- {
-
- ADC_num(0); ADC_num(1);
-
- for(i = 0; i < 8; i++)
- {
- PORTC = 0xff;
-
- PORTD = BIT(i);
-
- PORTC = SEG_CODE[display[i]];
-
- if(i == 0)PORTC &= 0x7F ;
- else if(i == 4)PORTC &= 0x7F ;
-
- delay(4);
-
- }
- }
-
- }
- void delay(uint mS)
- {
- uchar x,y;
- for(x=0;x<mS;x++)
- for(y=0;y<10;y++);
- }
复制代码
完整代码附件中
avr_精练的两路ADC.rar
(20.61 KB, 下载次数: 47)
|