📄 lamp.lst
字号:
__text_start:
__start:
002A E5CF LDI R28,0x5F
002B E0D4 LDI R29,4
002C BFCD OUT 0x3D,R28
002D BFDE OUT 0x3E,R29
002E 51C0 SUBI R28,0x10
002F 40D0 SBCI R29,0
0030 EA0A LDI R16,0xAA
0031 8308 STD Y+0,R16
0032 2400 CLR R0
0033 E6E0 LDI R30,0x60
0034 E0F0 LDI R31,0
0035 E010 LDI R17,0
0036 36E0 CPI R30,0x60
0037 07F1 CPC R31,R17
0038 F011 BEQ 0x003B
0039 9201 ST R0,Z+
003A CFFB RJMP 0x0036
003B 8300 STD Z+0,R16
003C E5E4 LDI R30,0x54
003D E0F0 LDI R31,0
003E E6A0 LDI R26,0x60
003F E0B0 LDI R27,0
0040 E010 LDI R17,0
0041 35E4 CPI R30,0x54
0042 07F1 CPC R31,R17
0043 F021 BEQ 0x0048
0044 95C8 LPM
0045 9631 ADIW R30,1
0046 920D ST R0,X+
0047 CFF9 RJMP 0x0041
0048 940E0097 CALL _main
_exit:
004A CFFF RJMP _exit
FILE: F:\AVR资料\台灯\LED.c
(0001) //ICC-AVR application builder // Target : M16
(0002) // Crystal: 4.0000Mhz
(0003) #include <iom16v.h>
(0004) #include <macros.h>
(0005) #define uchar unsigned char
(0006) #define uint unsigned int
(0007) void port_init(void);
(0008) void timer0_init(void);
(0009) void init_devices(void);
(0010) void delay_short(uint t);
(0011) uchar scan_key(void);
(0012) void port_init(void)
(0013) {
(0014) PORTA = 0x00;
_port_init:
004B 2422 CLR R2
004C BA2B OUT 0x1B,R2
(0015) DDRA = 0x00;
004D BA2A OUT 0x1A,R2
(0016) PORTB = BIT(PB3);
004E E088 LDI R24,0x8
004F BB88 OUT 0x18,R24
(0017) DDRB = BIT(PB3);
0050 BB87 OUT 0x17,R24
(0018) PORTC = 0x00; //m103 output only
0051 BA25 OUT 0x15,R2
(0019) DDRC = 0x00;
0052 BA24 OUT 0x14,R2
(0020) PORTD = 0x07;
0053 E087 LDI R24,7
0054 BB82 OUT 0x12,R24
(0021) DDRD = 0x00;
0055 BA21 OUT 0x11,R2
0056 9508 RET
(0022) }
(0023) // WGM: PWM Phase correct
(0024) // desired value: 1KHz
(0025) // actual value: 0.980KHz (-2.0%)
(0026) void timer0_init(void)
(0027) {
(0028) TCCR0 = 0x00; //stop
_timer0_init:
0057 2422 CLR R2
0058 BE23 OUT 0x33,R2
(0029) TCNT0 = 0x01; //set count
0059 E081 LDI R24,1
005A BF82 OUT 0x32,R24
(0030) OCR0 = 0xFF; //set compare
005B EF8F LDI R24,0xFF
005C BF8C OUT 0x3C,R24
(0031) TCCR0 = 0x62; //start timer ; 相位修正, 8分頻
005D E682 LDI R24,0x62
005E BF83 OUT 0x33,R24
005F 9508 RET
(0032) }
(0033) //call this routine to initialize all peripherals
(0034) void init_devices(void)
(0035) {
(0036) //stop errant interrupts until set up
(0037) CLI(); //disable all interrupts
_init_devices:
0060 94F8 BCLR 7
(0038) port_init();
0061 DFE9 RCALL _port_init
(0039) timer0_init();
0062 DFF4 RCALL _timer0_init
(0040) MCUCR = 0x00;
0063 2422 CLR R2
0064 BE25 OUT 0x35,R2
(0041) GICR = 0x00;
0065 BE2B OUT 0x3B,R2
(0042) TIMSK = 0x00; //timer interrupt sources
0066 BE29 OUT 0x39,R2
(0043) SEI(); //re-enable interrupts
0067 9478 BSET 7
0068 9508 RET
_delay_short:
i --> R20
t --> R16
0069 940E00B5 CALL push_gset1
(0044) //all peripherals are now initialized
(0045) }
(0046) void delay_short(uint t) // 短延時
(0047) {
(0048) uint i;
(0049) for (i=0;i<t;i++);
006B 2744 CLR R20
006C 2755 CLR R21
006D C002 RJMP 0x0070
006E 5F4F SUBI R20,0xFF
006F 4F5F SBCI R21,0xFF
0070 1740 CP R20,R16
0071 0751 CPC R21,R17
0072 F3D8 BCS 0x006E
0073 940E00B8 CALL pop_gset1
0075 9508 RET
_scan_key:
v --> R20
0076 940E00B5 CALL push_gset1
(0050) }
(0051) uchar scan_key(void) // 按鍵掃瞄
(0052) {
(0053) uchar v;
(0054)
(0055) v = 0;
0078 2744 CLR R20
(0056)
(0057) if ((PIND & 0x07) != 0x07)
0079 B380 IN R24,0x10
007A 7087 ANDI R24,7
007B 3087 CPI R24,7
007C F091 BEQ 0x008F
(0058) {
(0059)
(0060) if ((PIND & 0x01) == 0)
007D 9980 SBIC 0x10,0
007E C004 RJMP 0x0083
(0061) {
(0062) v = 1;
007F E041 LDI R20,1
(0063) delay_short(1000);
0080 EE08 LDI R16,0xE8
0081 E013 LDI R17,3
0082 DFE6 RCALL _delay_short
(0064) }
(0065)
(0066) if ((PIND & 0x2) == 0)
0083 9981 SBIC 0x10,1
0084 C004 RJMP 0x0089
(0067) {
(0068) v = 2;
0085 E042 LDI R20,2
(0069) delay_short(1000);
0086 EE08 LDI R16,0xE8
0087 E013 LDI R17,3
0088 DFE0 RCALL _delay_short
(0070) }
(0071)
(0072) if ((PIND & 0x4) == 0)
0089 9982 SBIC 0x10,2
008A C004 RJMP 0x008F
(0073) {
(0074) v = 3;
008B E043 LDI R20,3
(0075) delay_short(1000);
008C EE08 LDI R16,0xE8
008D E013 LDI R17,3
008E DFDA RCALL _delay_short
(0076) }
(0077) };
(0078) while((PIND & 0x07) != 0x07); // 判斷按鍵是不是放開
008F B380 IN R24,0x10
0090 7087 ANDI R24,7
0091 3087 CPI R24,7
0092 F7E1 BNE 0x008F
(0079) return v;
0093 2F04 MOV R16,R20
0094 940E00B8 CALL pop_gset1
0096 9508 RET
(0080) }
(0081) void main(void)
(0082) {
(0083) uchar key, OCR0_V;
(0084)
(0085) init_devices();
_main:
OCR0_V --> R20
key --> R22
0097 DFC8 RCALL _init_devices
(0086) OCR0_V = 0xff;
0098 EF4F LDI R20,0xFF
0099 C011 RJMP 0x00AB
(0087)
(0088) while(1)
(0089) {
(0090) key = scan_key();
009A DFDB RCALL _scan_key
009B 2F60 MOV R22,R16
(0091)
(0092) if (key > 0)
009C 2422 CLR R2
009D 1620 CP R2,R16
009E F460 BCC 0x00AB
(0093) {
(0094) if (key==1) // 減少佔空比
009F 3001 CPI R16,1
00A0 F411 BNE 0x00A3
(0095) {
(0096) OCR0_V -= 10;
00A1 504A SUBI R20,0xA
(0097) OCR0 = OCR0_V;
00A2 BF4C OUT 0x3C,R20
(0098) };
(0099)
(0100) if (key==2) // 增加佔空比
00A3 3062 CPI R22,2
00A4 F411 BNE 0x00A7
(0101) {
(0102) OCR0_V += 10;
00A5 5F46 SUBI R20,0xF6
(0103) OCR0 = OCR0_V;
00A6 BF4C OUT 0x3C,R20
(0104) };
(0105)
(0106) if (key==3) // 全黑,佔空比為100%
00A7 3063 CPI R22,3
00A8 F411 BNE 0x00AB
(0107) {
(0108) OCR0_V = 0xff;
00A9 EF4F LDI R20,0xFF
(0109) OCR0 = OCR0_V;
00AA BF4C OUT 0x3C,R20
00AB CFEE RJMP 0x009A
(0110) };
(0111) }
(0112) };
FILE: <library>
00AC 9508 RET
push_gset5:
00AD 92FA ST R15,-Y
00AE 92EA ST R14,-Y
push_gset4:
00AF 92DA ST R13,-Y
00B0 92CA ST R12,-Y
push_gset3:
00B1 92BA ST R11,-Y
00B2 92AA ST R10,-Y
push_gset2:
00B3 937A ST R23,-Y
00B4 936A ST R22,-Y
push_gset1:
00B5 935A ST R21,-Y
00B6 934A ST R20,-Y
00B7 9508 RET
pop_gset1:
00B8 E0E1 LDI R30,1
pop:
00B9 9149 LD R20,Y+
00BA 9159 LD R21,Y+
00BB FDE0 SBRC R30,0
00BC 9508 RET
00BD 9169 LD R22,Y+
00BE 9179 LD R23,Y+
00BF FDE1 SBRC R30,1
00C0 9508 RET
00C1 90A9 LD R10,Y+
00C2 90B9 LD R11,Y+
00C3 FDE2 SBRC R30,2
00C4 9508 RET
00C5 90C9 LD R12,Y+
00C6 90D9 LD R13,Y+
00C7 FDE3 SBRC R30,3
00C8 9508 RET
00C9 90E9 LD R14,Y+
00CA 90F9 LD R15,Y+
00CB 9508 RET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -