📄 encode.i
字号:
// CodeVisionAVR C Compiler
// (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega8
#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 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;
sfrw ICR1=0x26; // 16 bit access
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 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 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=0x80
.EQU __sm_mask=0x70
.EQU __sm_powerdown=0x20
.EQU __sm_powersave=0x30
.EQU __sm_standby=0x60
.EQU __sm_ext_standby=0x70
.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-
// Declare your global variables here
void main(void)
{
// Declare your local variables here
unsigned char count,counttime;
unsigned char codebuf[12];
// Port C initialization
// Func0=In Func1=In Func2=In Func3=In Func4=In Func5=In Func6=In Func7=In
// State0=T State1=T State2=T State3=T State4=T State5=T State6=T State7=T
PORTC=0x30;//00100000B,PORTC.5输出初始值为1
DDRC=0x30;//00100000B,PORTC.5输出,其他的输入
codebuf[0]=1; //地址码 有需要的话在这里改动
codebuf[1]=1;
codebuf[2]=1;
codebuf[3]=1;
codebuf[4]=0;
codebuf[5]=0;
codebuf[6]=0;
codebuf[7]=0;
codebuf[8]=1; //信息码
codebuf[9]=1;
codebuf[10]=1;
codebuf[11]=1;
while (1)
{
//Place your code here
/*temp=PINC&(0B00001000);//D3
codebuf[8]=temp>>3;//信息码
temp=PINC&(0B00000100);//D2
codebuf[9]=temp>>2;
temp=PINC&(0B00000010);
codebuf[10]=temp>>1;//D1
codebuf[11]=PINC&(0B00000001);//D0*/
/*codebuf[8]=PINC.3;
codebuf[9]=PINC.2;
codebuf[10]=PINC.1;
codebuf[11]=PINC.0;*/
for(counttime=0;counttime<4;counttime++) //发射脚为PA0
{for(count=0;count<12;count++) //发射
{if(codebuf[count]==1) //发射"1"
{PORTC.5 = 1;
#asm("cli")
delay_us(490); //发射频率22KHZ,发射头之前,即a=100US
PORTC.5 = 0;
delay_us(165);
PORTC.5 = 1;
delay_us(490);
PORTC.5 = 0;
delay_us(165);
#asm("sei")
}
if(codebuf[count]==0) //发射"0"
{PORTC.5 = 1;
#asm("cli")
delay_us(165); //发射频率10KHZ,发射头之前,即a=100US
PORTC.5 = 0;
delay_us(490);
PORTC.5 = 1;
delay_us(165);
PORTC.5 = 0;
delay_us(490);
#asm("sei")
}
if(codebuf[count]=='f') //发射"f"
{PORTC.5 = 1;
#asm("cli")
delay_us(165); //发射频率10KHZ,发射头之前,即a=100US
PORTC.5 = 0;
delay_us(490);
PORTC.5 = 1;
delay_us(490);
PORTC.5 = 0;
delay_us(165);
#asm("sei")
}
}
PORTC.5 = 1; //发射同步头
#asm("cli")
delay_us(165);
PORTC.5 = 0;
delay_us(5300);
#asm("sei")
}
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -