📄 amp.i
字号:
// CodeVisionAVR C Compiler
// (C) 1998-2001 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega16
#pragma used+
#pragma used+
sfrb TWBR=0;
sfrb TWSR=1;
sfrb TWAR=2;
sfrb TWDR=3;
sfrb ADCL=4;
sfrb ADCH=5;
sfrw ADCW=4; // 16 bit access
sfrb ADCSRA=6;
sfrb ADMUX=7;
sfrb ACSR=8;
sfrb UBRRL=9;
sfrb UCSRB=0xa;
sfrb UCSRA=0xb;
sfrb UDR=0xc;
sfrb SPCR=0xd;
sfrb SPSR=0xe;
sfrb SPDR=0xf;
sfrb PIND=0x10;
sfrb DDRD=0x11;
sfrb PORTD=0x12;
sfrb PINC=0x13;
sfrb DDRC=0x14;
sfrb PORTC=0x15;
sfrb PINB=0x16;
sfrb DDRB=0x17;
sfrb PORTB=0x18;
sfrb PINA=0x19;
sfrb DDRA=0x1a;
sfrb PORTA=0x1b;
sfrb EECR=0x1c;
sfrb EEDR=0x1d;
sfrb EEARL=0x1e;
sfrb EEARH=0x1f;
sfrw EEAR=0x1e; // 16 bit access
sfrb UBRRH=0x20;
sfrb UCSRC=0X20;
sfrb WDTCR=0x21;
sfrb ASSR=0x22;
sfrb OCR2=0x23;
sfrb TCNT2=0x24;
sfrb TCCR2=0x25;
sfrb ICR1L=0x26;
sfrb ICR1H=0x27;
sfrb OCR1BL=0x28;
sfrb OCR1BH=0x29;
sfrw OCR1B=0x28; // 16 bit access
sfrb OCR1AL=0x2a;
sfrb OCR1AH=0x2b;
sfrw OCR1A=0x2a; // 16 bit access
sfrb TCNT1L=0x2c;
sfrb TCNT1H=0x2d;
sfrw TCNT1=0x2c; // 16 bit access
sfrb TCCR1B=0x2e;
sfrb TCCR1A=0x2f;
sfrb SFIOR=0x30;
sfrb OSCCAL=0x31;
sfrb OCDR=0x31;
sfrb TCNT0=0x32;
sfrb TCCR0=0x33;
sfrb MCUCSR=0x34;
sfrb MCUCR=0x35;
sfrb TWCR=0x36;
sfrb SPMCR=0x37;
sfrb TIFR=0x38;
sfrb TIMSK=0x39;
sfrb GIFR=0x3a;
sfrb GICR=0x3b;
sfrb OCR0=0X3c;
sfrb SPL=0x3d;
sfrb SPH=0x3e;
sfrb SREG=0x3f;
#pragma used-
// Interrupt vectors definitions
// Needed by the power management functions (sleep.h)
#asm
#ifndef __SLEEP_DEFINED__
#define __SLEEP_DEFINED__
.EQU __se_bit=0x40
.EQU __sm_mask=0xB0
.EQU __sm_powerdown=0x20
.EQU __sm_powersave=0x30
.EQU __sm_standby=0xA0
.EQU __sm_ext_standby=0xB0
.EQU __sm_adc_noise_red=0x10
.SET power_ctrl_reg=mcucr
#endif
#endasm
// CodeVisionAVR C Compiler
// (C) 1998-2000 Pavel Haiduc, HP InfoTech S.R.L.
#pragma used+
#pragma used+
void delay_us(unsigned int n);
void delay_ms(unsigned int n);
#pragma used-
/*
#define SECTION1 (((PORTC|=0x0d)&(PORTC&=0xfd))&((PORTD|=0x80)&(PORTD&=0xdf)))
#define SECTION2 (((PORTC|=0x0b)&(PORTC&=0xfb))&((PORTD|=0x20)&(PORTD&=0x7f)))
#define SECTION3 (((PORTC|=0x0e)&(PORTC&=0xfe))&(PORTD&=0x5f))
#define SECTION4 (((PORTC|=0x07)&(PORTC&=0xf7))&(PORTD&=0x5f))
#define SECTION5 (((PORTC|=0x02)&(PORTC&=0xf2))&((PORTD|=0x20)&(PORTD&=0x7f)))
#define SECTION6 (((PORTC|=0x05)&(PORTC&=0xf5))&(PORTD|=0xa0))
#define SECTION7 (((PORTC|=0x08)&(PORTC&=0xf8))&(PORTD|=0xa0))
#define SECTION8 ((PORTC&=0xf0)&((PORTD|=0x80)&(PORTD&=0xdf)))
*/
static unsigned char step=0;
/*数控电阻选择子程序
jmp_step在0到32之间选择
*/
void x9511(unsigned char jmp_step)
{
unsigned char i;
unsigned char j;j=step;
if(j>jmp_step)
{
for(i=0;i<j-jmp_step;i++)
{
(PORTB&=0xfd);
delay_ms(50);
(PORTB|=0x02);
delay_ms(5);
step--;
}
}
else
{
for(i=0;i<jmp_step-j;i++)
{
(PORTB&=0xfb);
delay_ms(50);
(PORTB|=0x04);
delay_ms(5);
step++;
}
}
}
void clr_x9511(void)
{
unsigned char i;
for(i=0;i<31;i++)
{
(PORTB&=0xfd);
delay_ms(50);
(PORTB|=0x02);
delay_ms(5);
}
}
/*调幅总程序
参数channel为通道选择,1为SIN正弦波,2为SQUART方波,3为TRIGLE三角波
参数amp_data为幅度选择,范围0~32
*/
void amp(unsigned char channel,unsigned char amp_data)
{
switch(channel)
{
case 0:
(((PORTB|=0x80)&(PORTB&=0x8f))&((PORTD|=0x20)&(PORTD&=0xbf)));
break;
case 1:
(((PORTB|=0x10)&(PORTB&=0x1f))&((PORTD|=0x40)&(PORTD&=0xdf)));
break;
case 2:
(((PORTB|=0x20)&(PORTB&=0x2f))&((PORTD|=0x20)&(PORTD&=0xbf)));
break;
default:
break;
}
x9511(amp_data);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -