/*****************************************************
This program was produced by the
CodeWizardAVR V1.24.8c Professional
Automatic Program Generator
?Copyright 1998-2006 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : 简易直流电压源
Version :
Date : 2007-5-18
Author : F4CG
Company : F4CG
Comments:
Chip type : ATmega16L
Program type : Application
Clock frequency : 8.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
#include <mega16.h>
#include <delay.h>
#include "1602a.h"
#define ADC_VREF_TYPE 0xc7//内部基准电源,单通道输入PA7
unsigned int adc_v;
int key_stime_ok,key_stime_counter;
void adc_to_disbuffer(unsigned int adc)
{
// #asm("cli")
// LcdPos(6,0); //确定光标位置
// LcdWd(adc%10+0x30);
adc="adc/10";
LcdPos(5,0); //确定光标位置
LcdWd(adc%10+0x30);
adc/=10;
LcdPos(4,0); //确定光标位置
LcdWd(adc%10+0x30);
adc/=10;
LcdPos(3,0); //确定光标位置
LcdWd('.');
LcdPos(2,0); //确定光标位置
LcdWd(adc%10+0x30);
adc/=10;
//#asm("sei")
}
interrupt [TIM0_COMP] void timer0_comp_isr(void)
{
// Place your code here
if (++key_stime_counter >=1)
{
key_stime_ok = 1;
}
}
// ADC interrupt service routine
interrupt [ADC_INT] void adc_isr(void)
{
unsigned int adc_data;
// Read the AD conversion result
adc_data=ADCW;
// Place your code here
adc_v=(unsigned long)adc_data*2560/1024; //换算成电压值
adc_to_disbuffer(adc_v);
}
// Declare your global variables here
void main(void)
{
// Declare your local variables here
//char j="88";
// Input/Output Ports initialization
// Port A 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
PORTA=0x00;
DDRA=0x00;
// 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=0xff;//液晶接口
DDRB=0xff;
// Port C 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
PORTC=0x00;
DDRC=0xff;
// Port D 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
PORTD=0xff;
DDRD=0xff;
// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: Timer 0 Stopped
// Mode: Normal top="FFh"
// OC0 output: Disconnected
TCCR0=0x0C;//采用比较模式,256分频 8M/256=31.25K
//TCCR0=0X0D;//1024 7.81k
TCNT0=0x00;
OCR0=0x40;// (61+1)/31.25 =2ms
// OCR0=0XFF;
// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer 1 Stopped
// Mode: Normal top="FFFFh"
// OC1A output: Discon.
// OC1B output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer 1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer 2 Stopped
// Mode: Normal top="FFh"
// OC2 output: Disconnected
ASSR=0x00;
TCCR2=0x00;
TCNT2=0x00;
OCR2=0x00;
// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
MCUCR=0x00;
MCUCSR=0x00;
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x02;
// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00;
// ADC initialization
// ADC Clock frequency: 125.000 kHz
// ADC Voltage Reference: Int., cap. on AREF
// ADC Auto Trigger Source: Timer0 Compare Match
ADMUX=ADC_VREF_TYPE;
ADCSRA=0xAE;
SFIOR&=0x1F;
SFIOR|=0x60;
// Global enable interrupts
RstLcd();//液晶初始化
RstLcd();//液晶初始化
RstLcd();//液晶初始化
/*
LcdPos(0,0);//x,y
LcdWd(j%10+0x30);
LcdPos(1,0);//x,y
j=j/10;
LcdWd(j%10+0x30);
//j=j/10 ;
LcdPos(2,0);//x,y
LcdWd('=');
LcdPos(3,0);
//Write_String(str);
lcd_putsf("JIANGLONGJIAN");
//LcdWd('b');*/
LcdPos(0,0); //确定光标位置
LcdWd('v');
LcdPos(1,0); //确定光标位置
LcdWd('=');
#asm("sei")
while (1)
{
// Place your code here
// if (key_stime_ok==1)
// { key_stime_ok=0;
// adc_to_disbuffer(adc_v);
// }
};
}
文章评论(0条评论)
登录后参与讨论