📄 12864.i
字号:
// CodeVisionAVR C Compiler
// (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega48(V)
#pragma used+
sfrb PINB=3;
sfrb DDRB=4;
sfrb PORTB=5;
sfrb PINC=6;
sfrb DDRC=7;
sfrb PORTC=8;
sfrb PIND=9;
sfrb DDRD=0xa;
sfrb PORTD=0xb;
sfrb TIFR0=0x15;
sfrb TIFR1=0x16;
sfrb TIFR2=0x17;
sfrb PCIFR=0x1b;
sfrb EIFR=0x1c;
sfrb EIMSK=0x1d;
sfrb GPIOR0=0x1e;
sfrb EECR=0x1f;
sfrb EEDR=0x20;
sfrb EEARL=0x21;
sfrb EEARH=0x22;
sfrw EEAR=0x21; // 16 bit access
sfrb GTCCR=0x23;
sfrb TCCR0A=0x24;
sfrb TCCR0B=0x25;
sfrb TCNT0=0x26;
sfrb OCR0A=0x27;
sfrb OCR0B=0x28;
sfrb GPIOR1=0x2a;
sfrb GPIOR2=0x2b;
sfrb SPCR=0x2c;
sfrb SPSR=0x2d;
sfrb SPDR=0x2e;
sfrb ACSR=0x30;
sfrb MONDR=0x31;
sfrb SMCR=0x33;
sfrb MCUSR=0x34;
sfrb MCUCR=0x35;
sfrb SPMCSR=0x37;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-
// Interrupt vectors definitions
// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
#pragma used+
void delay_us(unsigned int n);
void delay_ms(unsigned int n);
#pragma used-
/************************************************************************************/
void chushihua(void)
{
PORTB=0Xff;DDRB=0XFF;
PORTD=0X00;DDRD=0XFF;
(*(unsigned char *) 0x60) =0x18;//
(*(unsigned char *) 0x60) =0x1f;//
(*(unsigned char *) 0x7e)=0x00;
(*(unsigned char *) 0x7c)=0xc0 & 0xff;
(*(unsigned char *) 0x7a)=0x81;
}
unsigned long read_adc(unsigned char adc_input)
{
unsigned long a=0,b=0;
(*(unsigned char *) 0x7c)=adc_input | (0xC0 & 0xff);
(*(unsigned char *) 0x7a)|=0x40;
while (((*(unsigned char *) 0x7a) & 0x10)==0);
(*(unsigned char *) 0x7a)|=0x10;
a=(*(unsigned int *) 0x78) ;
a=a*119;
a=a%1000000;
a=a/100;
b=a*3077%10000/1000;
a=a*3077/10000;
if(b>=5){a=a+1;}
return a;
}
void main(void)
{
char i=0;
unsigned long temp;
chushihua();
PORTD.3 =0;
PORTB.6 =0;
PORTB.3 =0;
PORTB.1 =0;
PORTB.2 =0;
while(1)//65535
{
delay_ms(500);
temp=read_adc(5);
if(temp>135)//大于13.5V 断开充电
{
PORTD.3 =0;
PORTB.6 =1;
PORTB.3 =0;
PORTB.1 =1;
PORTB.2 =1;
i=0;
}
if((temp<=135)&&(temp>=115))//大于11.5 小于13.5 正常模式
{
PORTD.3 =1;
PORTB.6 =1;
PORTB.3 =1;
PORTB.2 =1;
i=1;
}
if(temp<115) //小于11.5断开负载 保持充电
{
PORTD.3 =1;
PORTB.6 =0;
PORTB.3 =1;
PORTB.1 =1;
PORTB.2 =0;
i=0;
}
if(i==1){PORTB.1 =0;delay_ms(500);PORTB.1 =1; delay_ms(500);}
else
{
delay_ms(500);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -