📄 a.i
字号:
/*****************************************************
Project :
Version :
Date : 2007-5-31
Author : Cheung
Company : hhuc
Comments:
Chip type : ATmega16L
Program type : Application
Clock frequency : 1.000000 MHz
Memory model : Small
External SRAM size : 0
Data Stack size : 256
*****************************************************/
// CodeVisionAVR C Compiler
// (C) 1998-2001 Pavel Haiduc, HP InfoTech S.R.L.
// I/O registers definitions for the ATmega16
#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
/* CodeVisionAVR C Compiler
Prototypes for standard library functions
(C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.
*/
#pragma used+
int atoi(char *str);
long int atol(char *str);
float atof(char *str);
void itoa(int n,char *str);
void ltoa(long int n,char *str);
void ftoa(float n,unsigned char decimals,char *str);
void ftoe(float n,unsigned char decimals,char *str);
void srand(int seed);
int rand(void);
void *malloc(unsigned int size);
void *calloc(unsigned int num, unsigned int size);
void *realloc(void *ptr, unsigned int size);
void free(void *ptr);
#pragma used-
#pragma library stdlib.lib
// 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-
// Alphanumeric LCD Module functions
#asm
.equ __lcd_port=0x18 ;PORTB
#endasm
/* LCD driver routines
CodeVisionAVR C Compiler
(C) 1998-2003 Pavel Haiduc, HP InfoTech S.R.L.
BEFORE #include -ING THIS FILE YOU
MUST DECLARE THE I/O ADDRESS OF THE
DATA REGISTER OF THE PORT AT WHICH
THE LCD IS CONNECTED!
EXAMPLE FOR PORTB:
#asm
.equ __lcd_port=0x18
#endasm
#include <lcd.h>
*/
#pragma used+
void _lcd_ready(void);
void _lcd_write_data(unsigned char data);
// write a byte to the LCD character generator or display RAM
void lcd_write_byte(unsigned char addr, unsigned char data);
// read a byte from the LCD character generator or display RAM
unsigned char lcd_read_byte(unsigned char addr);
// set the LCD display position x=0..39 y=0..3
void lcd_gotoxy(unsigned char x, unsigned char y);
// clear the LCD
void lcd_clear(void);
void lcd_putchar(char c);
// write the string str located in SRAM to the LCD
void lcd_puts(char *str);
// write the string str located in FLASH to the LCD
void lcd_putsf(char flash *str);
// initialize the LCD controller
unsigned char lcd_init(unsigned char lcd_columns);
#pragma used-
#pragma library lcd.lib
unsigned int arr[16]; //捕捉中断之间的时间值;
unsigned char times; //捕捉中断次数;
unsigned char index; //数组索引;
unsigned char ir_code; //接受红外编码;
unsigned char ok_flag; //解码完毕标示;
unsigned char head; //引导码标志;
unsigned char hex[3]; //十六进制解码
void time1_initial() //定时器1初始化
{
TCCR1B=0x81; //输入噪声消除,下降沿捕捉,系统时钟1M;
TCNT1H=0x00;
TCNT1L=0x00;
TIMSK=0x20; //输入捕捉中断使能;
}
void port_init()
{
DDRD=0x00;
PORTD=0xff;
}
void dec_to_hex(unsigned char dec) //十进制转换十六进制显示
{
unsigned char temp[2],i;
temp[0]=dec/16;
temp[1]=dec%16;
for(i=0;i<2;i++){
switch(temp[i]){
case 0:temp[i]='0';break;
case 1:temp[i]='1';break;
case 2:temp[i]='2';break;
case 3:temp[i]='3';break;
case 4:temp[i]='4';break;
case 5:temp[i]='5';break;
case 6:temp[i]='6';break;
case 7:temp[i]='7';break;
case 8:temp[i]='8';break;
case 9:temp[i]='9';break;
case 10:temp[i]='A';break;
case 11:temp[i]='B';break;
case 12:temp[i]='C';break;
case 13:temp[i]='D';break;
case 14:temp[i]='E';break;
case 15:temp[i]='F';break;
}
hex[i]=temp[i];
}
}
// Timer 1 input capture interrupt service routine
interrupt [6] void timer1_capt_isr(void)
{
unsigned int value,temp;
value=ICR1L;
temp=ICR1H;
TCNT1H=0x00;
TCNT1L=0x00; //设置value值即为TCNT(new)-TCNT(old)
times++; //纪录一个中断
value|=temp<<8;
if(value>12500&&value<14500)
{
head=1; //识别引导码
times=2;
}
if(head&&(times>28)&&(times<45)) //从第29个下降沿开始保存
{
arr[index]=value;
index++;
}
else if(head&×>=45) //当下降沿大于46时,解码完毕
{
times=1;
index=0;
head=0;
ok_flag=1; //解码完毕标示
}
}
/*------------------------------解码程序----------------------------------------
结果:得到uchar型的键码ir_code,如果解码出错,则ir_code=0xff
-----------------------------------------------------------------------------*/
void get_code()
{
unsigned char i,data,_data; //data为键码,_data为键码反码
unsigned int temp=0; //键码(16位)
for(i=0;i<16;i++)
{
if(arr[i]<1225) //"0码"
temp<<=1;
if(arr[i]>2150) //"1码"
{
temp<<=1;
temp|=1;
}
}
_data=(unsigned char)(temp&0x00ff); //取temp低八位
data=(unsigned char)((temp>>8)&0x00ff); //取temp高八位
if((data&_data)==0x00) //校验接受键码
ir_code=data;
else{
TCNT1H=0x00;
TCNT1L=0x00;
//ir_code=0xff; //解码出错
return;
}
}
void main()
{
unsigned char code[5]; //用于液晶显示所用的存储数据数组应设置长点!
unsigned char showhex[]="The Code Is:0x";
unsigned char showdec[]="Dec Code:";
//WDTCR=0xF;
time1_initial();
port_init();
delay_ms(200);
lcd_init(16);
#asm("sei") // Global enable interrupts
while(1)
{
//#asm("wdr")
if(ok_flag)
{
get_code();
dec_to_hex(ir_code);
ok_flag=0;
lcd_clear();
itoa(ir_code,code);
}
lcd_gotoxy(0,0);
lcd_puts(showhex);
lcd_gotoxy(14,0);
lcd_puts(hex);
lcd_gotoxy(3,1);
lcd_puts(showdec);
lcd_gotoxy(13,1);
lcd_puts(code);
};
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -