|
附帶proteus設計圖 電路圖 大圖在附件里面
- /*****************************************************
- Project :
- Version :
- Date : 2015-10-29
- Author :tengzaiba
- Chip type : ATmega16
- AVR Core Clock frequency: 8.000000 MHz
- *****************************************************/
- #include <mega16.h>
- #include <delay.h>
- // Declare your global variables here
- char LCD_7[16] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
- char dis_buff[4];
- unsigned int votage=0;
- unsigned int vot1;
- // Timer 0 overflow interrupt service routine
- interrupt [TIM0_OVF] void timer0_ovf_isr(void)
- {
- // Place your code here
- // Read the 8 most significant bits
- // of the AD conversion result
- PORTC.7=~PORTC.7;
- delay_us(20);
- while ((ADCSRA & 0x10)==0);
- ADCSRA|=0x10;
- vot1=ADCW;
- votage=(unsigned long)vot1*5000/1024;
- }
- void display(unsigned int vot)
- {
- // move vot to dis_buff
- char i;
- char j;
- for (i=0;i<4;i++)
- {
- dis_buff[i]=vot % 10;
- vot/=10;
- }
- // dis_buff to LEDs
- for (j=0;j<=3;j++)
- {
- PORTC=LCD_7[dis_buff[j]];
- PORTA=~(1<<j);
- delay_ms(2);
- PORTA=0x0f;
- }
- }
- void main(void)
- {
- // Declare your local variables here
- // Input/Output Ports initialization
- // Port A initialization
- // Func7=In Func6=In Func5=In Func4=In Func3=Out Func2=Out Func1=Out Func0=Out
- // State7=T State6=T State5=T State4=T State3=0 State2=0 State1=0 State0=0
- PORTA=0x00;
- DDRA=0x0F;
- // Port B initialization
- // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In
- // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T
- PORTB=0x00;
- DDRB=0x00;
- // Port C initialization
- // Func7=In Func6=Out Func5=Out Func4=Out Func3=Out Func2=Out Func1=Out Func0=Out
- // State7=T State6=0 State5=0 State4=0 State3=0 State2=0 State1=0 State0=0
- PORTC=0x00;
- DDRC=0xFF;
- // Timer/Counter 0 initialization
- // Clock source: System Clock
- // Clock value: Timer 0 Stopped
- // Mode: Normal top=FFh
- // OC0 output: Disconnected
- TCCR0=0x03;
- TCNT0=0x00;
- OCR0=0x00;
- // External Interrupt(s) initialization
- // INT0: Off
- // INT1: Off
- // INT2: Off
- MCUCR=0x00;
- MCUCSR=0x00;
- // Timer(s)/Counter(s) Interrupt(s) initialization
- TIMSK=0x01;
- // Analog Comparator initialization
- // Analog Comparator: Off
- // Analog Comparator Input Capture by Timer/Counter 1: Off
- ACSR=0x80;
- SFIOR=0x00;
- // ADC initialization
- // ADC Clock frequency: 1000.000 kHz
- // ADC Voltage Reference: AREF pin
- // ADC Auto Trigger Source: Timer0 Overflow
- // Only the 8 most significant bits of
- // the AD conversion result are used
- ADMUX=0x47;
- ADCSRA=0xA3;
- SFIOR&=0x1F;
- SFIOR|=0x80;
- // Global enable interrupts
- #asm("sei")
- while (1)
- {
-
- display(votage);
- };
- }
復制代碼
|
-
-
AVR16電壓表制作.rar
2016-1-1 14:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
60.88 KB, 下載次數: 124, 下載積分: 黑幣 -5
電壓表制作
評分
-
查看全部評分
|