📄 irremote.lst
字号:
__text_start:
__start:
0033 E5CF LDI R28,0x5F
0034 E0D4 LDI R29,4
0035 BFCD OUT 0x3D,R28
0036 BFDE OUT 0x3E,R29
0037 51C0 SUBI R28,0x10
0038 40D0 SBCI R29,0
0039 EA0A LDI R16,0xAA
003A 8308 STD Y+0,R16
003B 2400 CLR R0
003C E6E0 LDI R30,0x60
003D E0F0 LDI R31,0
003E E010 LDI R17,0
003F 36E2 CPI R30,0x62
0040 07F1 CPC R31,R17
0041 F011 BEQ 0x0044
0042 9201 ST R0,Z+
0043 CFFB RJMP 0x003F
0044 8300 STD Z+0,R16
0045 E6E5 LDI R30,0x65
0046 E0F0 LDI R31,0
0047 E6A0 LDI R26,0x60
0048 E0B0 LDI R27,0
0049 E010 LDI R17,0
004A 36E5 CPI R30,0x65
004B 07F1 CPC R31,R17
004C F021 BEQ 0x0051
004D 95C8 LPM
004E 9631 ADIW R30,1
004F 920D ST R0,X+
0050 CFF9 RJMP 0x004A
0051 940E00D7 CALL _main
_exit:
0053 CFFF RJMP _exit
FILE: D:\M16开发板实验教程\icc-avr\irremote\delay.h
(0001) #include<iom16v.h>
(0002) #include <macros.h>
(0003)
(0004) /*-----------------------------------------------------------*/
(0005) /*-----------------------------------------------------------------------
(0006) 延时函数
(0007) 系统时钟:8M
(0008) -----------------------------------------------------------------------*/
(0009) void delay_1us(void) //1us延时函数
(0010) {
(0011) asm("nop");
_delay_1us:
0054 0000 NOP
0055 9508 RET
_delay_nus:
i --> R20
n --> R22
0056 940E01A3 CALL push_gset2
0058 01B8 MOVW R22,R16
(0012) }
(0013)
(0014) void delay_nus(unsigned int n) //N us延时函数
(0015) {
(0016) unsigned int i=0;
0059 2744 CLR R20
005A 2755 CLR R21
(0017) for (i=0;i<n;i++)
005B C003 RJMP 0x005F
(0018) delay_1us();
005C DFF7 RCALL _delay_1us
005D 5F4F SUBI R20,0xFF
005E 4F5F SBCI R21,0xFF
005F 1746 CP R20,R22
0060 0757 CPC R21,R23
0061 F3D0 BCS 0x005C
0062 940E0197 CALL pop_gset2
0064 9508 RET
(0019) }
(0020)
(0021) void delay_1ms(void) //1ms延时函数
(0022) {
(0023) unsigned int i;
(0024) for (i=0;i<1140;i++);
_delay_1ms:
i --> R16
0065 2700 CLR R16
0066 2711 CLR R17
0067 C002 RJMP 0x006A
0068 5F0F SUBI R16,0xFF
0069 4F1F SBCI R17,0xFF
006A 3704 CPI R16,0x74
006B E0E4 LDI R30,4
006C 071E CPC R17,R30
006D F3D0 BCS 0x0068
006E 9508 RET
_delay_nms:
i --> R20
n --> R22
006F 940E01A3 CALL push_gset2
0071 01B8 MOVW R22,R16
(0025) }
(0026)
(0027) void delay_nms(unsigned int n) //N ms延时函数
(0028) {
(0029) unsigned int i=0;
0072 2744 CLR R20
0073 2755 CLR R21
(0030) for (i=0;i<n;i++)
0074 C003 RJMP 0x0078
(0031) delay_1ms();
0075 DFEF RCALL _delay_1ms
0076 5F4F SUBI R20,0xFF
0077 4F5F SBCI R21,0xFF
0078 1746 CP R20,R22
0079 0757 CPC R21,R23
007A F3D0 BCS 0x0075
007B 940E0197 CALL pop_gset2
007D 9508 RET
_display:
num --> R20
007E 940E01A5 CALL push_gset1
0080 2F40 MOV R20,R16
FILE: D:\M16开发板实验教程\icc-avr\irremote\shumaguan.h
(0001) /*
(0002) this file is the head file
(0003) */
(0004)
(0005)
(0006) #include<iom16v.h>
(0007) #include<macros.h>
(0008) #include"delay.h"
(0009) //macros.h 中有BIT(x) (1 << (x))定义, 比如 BIT(5)相当于将第5位置1
(0010)
(0011) const unsigned char discode[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,
(0012) 0x82,0xf8,0x80,0x90,0x88,0x83,
(0013) 0xc6,0xa1,0x86,0x8e,0xbf}; //共阳数码管
(0014)
(0015) /*------------------------------------------------------------------
(0016) fuction: display in hex formart
(0017) para : hi--the high two bits to be displayed
(0018) low--the low two bits to be displayed
(0019) -------------------------------------------------------------------*/
(0020) void display(unsigned char num)
(0021) {
(0022) PORTB &=~BIT(PORTB0); //light the first bit of the shumaguan
0081 98C0 CBI 0x18,0
(0023) //PORTB0 was defined in iom16v.h
(0024) PORTA=discode[num>>4]; //display the thousand bit
0082 E584 LDI R24,0x54
0083 E090 LDI R25,0
0084 2FE4 MOV R30,R20
0085 27FF CLR R31
0086 95F5 ASR R31
0087 95E7 ROR R30
0088 95F5 ASR R31
0089 95E7 ROR R30
008A 95F5 ASR R31
008B 95E7 ROR R30
008C 95F5 ASR R31
008D 95E7 ROR R30
008E 0FE8 ADD R30,R24
008F 1FF9 ADC R31,R25
0090 91E4 LPM R30,0(Z)
0091 BBEB OUT 0x1B,R30
(0025) delay_nms(5);
0092 E005 LDI R16,5
0093 E010 LDI R17,0
0094 DFDA RCALL _delay_nms
(0026) PORTB |=BIT(PORTB0); //turn off the first bit of the shumaguan
0095 9AC0 SBI 0x18,0
(0027)
(0028) PORTB &=~BIT(PORTB1);
0096 98C1 CBI 0x18,1
(0029) PORTA=discode[num%16];
0097 E120 LDI R18,0x10
0098 E030 LDI R19,0
0099 2F04 MOV R16,R20
009A 2711 CLR R17
009B 940E015D CALL mod16s
009D 01F8 MOVW R30,R16
009E E584 LDI R24,0x54
009F E090 LDI R25,0
00A0 0FE8 ADD R30,R24
00A1 1FF9 ADC R31,R25
00A2 91E4 LPM R30,0(Z)
00A3 BBEB OUT 0x1B,R30
(0030) delay_nms(5);
00A4 E005 LDI R16,5
00A5 E010 LDI R17,0
00A6 DFC8 RCALL _delay_nms
(0031) PORTB |=BIT(PORTB1);
00A7 9AC1 SBI 0x18,1
00A8 940E01A8 CALL pop_gset1
00AA 9508 RET
(0032)
(0033) }
(0034) /*---------------------------------------------------------------------
(0035) fuction: display error,this will display "- - - -" on the four bits leds
(0036) ----------------------------------------------------------------------*/
(0037) void displayerror(void)
(0038) {
(0039) PORTB &=~1; //light the first bit of the shumaguan
_displayerror:
00AB 98C0 CBI 0x18,0
(0040) //PORTB0 was defined in iom16v.h
(0041) PORTA=discode[16]; //display the thousand bit
00AC E6E4 LDI R30,0x64
00AD E0F0 LDI R31,0
00AE 91E4 LPM R30,0(Z)
00AF BBEB OUT 0x1B,R30
(0042) delay_nms(5);
00B0 E005 LDI R16,5
00B1 E010 LDI R17,0
00B2 DFBC RCALL _delay_nms
(0043) PORTB |=1; //turn off the first bit of the shumaguan
00B3 9AC0 SBI 0x18,0
(0044)
(0045) PORTB &=~2;
00B4 98C1 CBI 0x18,1
(0046) PORTA=discode[16];
00B5 E6E4 LDI R30,0x64
00B6 E0F0 LDI R31,0
00B7 91E4 LPM R30,0(Z)
00B8 BBEB OUT 0x1B,R30
(0047) delay_nms(5);
00B9 E005 LDI R16,5
00BA E010 LDI R17,0
00BB DFB3 RCALL _delay_nms
(0048) PORTB |=2;
00BC 9AC1 SBI 0x18,1
00BD 9508 RET
FILE: D:\M16开发板实验教程\icc-avr\irremote\irremote.c
(0001) /*
(0002) Title: icc-avr irremote
(0003) Author: dushibiao
(0004) Date: 2007 10 19
(0005) Purpose: control your pc use a ir remoter
(0006) Frequency: internal 8M
(0007) needed
(0008) Software: icc-avr to compile
(0009) needed
(0010) Hardware: AVR mega16 BOARD
(0011) Connect: dushibiao@126.com
(0012) */
(0013) #include <iom16v.h>
(0014) #include <macros.h>
(0015) #include "shumaguan.h"
(0016)
(0017) #define IR 2 //PB2,irfrade receive line
(0018) #define PIN_RXD 0 //PD0 RXD
(0019) #define PIN_TXD 1 //PD1 TXD
(0020) #define BAUDRATE 9600 //baudrate
(0021) #define F_CPU 8000000 //the frequency of the global clock
(0022)
(0023)
(0024) volatile unsigned char flag,code;
(0025)
(0026)
(0027) void delay0_9ms(void)
(0028) {
(0029) delay_nus(510);
_delay0_9ms:
00BE EF0E LDI R16,0xFE
00BF E011 LDI R17,1
00C0 DF95 RCALL _delay_nus
00C1 9508 RET
(0030) }
(0031)
(0032) //4.5ms
(0033) void delay4_5ms(void)
(0034) {
(0035) delay_nms(4);
_delay4_5ms:
00C2 E004 LDI R16,4
00C3 E010 LDI R17,0
00C4 DFAA RCALL _delay_nms
(0036) delay_nus(320);
00C5 E400 LDI R16,0x40
00C6 E011 LDI R17,1
00C7 DF8E RCALL _delay_nus
00C8 9508 RET
(0037) }
(0038) /*---------------------------------------------------------------------------
(0039) function send an unsigned char to the uart
(0040) ----------------------------------------------------------------------------*/
(0041) void put_c(unsigned char c) //发送采用查询方式
(0042) {
(0043) while( !(UCSRA & (1<<UDRE)) ); //wait until the uart is empty
_put_c:
c --> R16
00C9 9B5D SBIS 0x0B,5
00CA CFFE RJMP _put_c
(0044) UDR=c; //write data to uart
00CB B90C OUT 0x0C,R16
00CC 9508 RET
(0045) }
(0046) /*---------------------------------------------------------------------------
(0047) fuction initialize the uart unit
(0048) ----------------------------------------------------------------------------*/
(0049) void init_USART(void)//USART 初始化
(0050) {
(0051)
(0052) //USART 9600 8, n,1 PC上位机软件(超级终端等)也要设成同样的设置才能通讯
(0053) UCSRC = (1<<URSEL) | 0x06;
_init_USART:
00CD E886 LDI R24,0x86
00CE BD80 OUT 0x20,R24
(0054) //异步,8位数据,无奇偶校验,一个停止位,无倍速
(0055) /*
(0056) UBRRH与UCSRC共用I/O 地址。因此访问该地址时需注意以下问题。
(0057) 写访问
(0058) 当在该地址执行写访问时, USART 寄存器选择位(URSEL)控制被写入的寄存器。
(0059) 若URSEL为0,对UBRRH值更新;若URSEL为1,对UCSRC设置更新
(0060)
(0061) 读访问
(0062) 对UBRRH 或UCSRC 寄存器的读访问则较为复杂。但在大多数应用中,基本不需要读这些寄存器
(0063)
(0064)
(0065) 没有UBRR这个16位寄存器,因为UBRRL(0x09)/UBRRH(0x20)的地址不连续,而且UBRRH跟UCSRC共用地址
(0066) */
(0067)
(0068) //U2X=0时的公式计算
(0069) UBRRL= (F_CPU/BAUDRATE/16-1)%256;
00CF E383 LDI R24,0x33
00D0 B989 OUT 0x09,R24
(0070) UBRRH= (F_CPU/BAUDRATE/16-1)/256;
00D1 2422 CLR R2
00D2 BC20 OUT 0x20,R2
(0071) //U2X=1时的公式计算
(0072) //UBRRL= (F_CPU/BAUDRATE/8-1)%256;
(0073) //UBRRH= (F_CPU/BAUDRATE/8-1)/256;
(0074) //也可根据数据手册的[波特率设置的例子]查得
(0075) //UBRRL = 0x2F; //set baud rate lo
(0076) //UBRRH = 0x00; //set baud rate hi
(0077) UCSRA = 0x00; //无倍速
00D3 B82B OUT 0x0B,R2
(0078) UCSRB = (1<<RXEN)|(1<<TXEN);
00D4 E188 LDI R24,0x18
00D5 B98A OUT 0x0A,R24
00D6 9508 RET
(0079) //使能接收,使能发送
(0080) }
(0081)
(0082) void main(void)
(0083) {
(0084) PORTA=0XFF;
_main:
00D7 EF8F LDI R24,0xFF
00D8 BB8B OUT 0x1B,R24
(0085) DDRA=0XFF; //OUT
00D9 BB8A OUT 0x1A,R24
(0086) PORTB=0XFF;
00DA BB88 OUT 0x18,R24
(0087) DDRB=0X03; //PB0,PB1 OUT
00DB E083 LDI R24,3
00DC BB87 OUT 0x17,R24
(0088) PORTC=0XFF;
00DD EF8F LDI R24,0xFF
00DE BB85 OUT 0x15,R24
(0089) DDRD =(1<<PIN_TXD); //TXD为输出
00DF E082 LDI R24,2
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -