📄 led.s
字号:
.module led.c
.area text(rom, con, rel)
.dbfile f:\MYDOCU~1\AVR\led\代码\led.c
.area data(ram, con, rel)
.dbfile f:\MYDOCU~1\AVR\led\代码\led.c
_tmrRollFlag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile f:\MYDOCU~1\AVR\led\代码\led.c
.dbsym e tmrRollFlag _tmrRollFlag c
.area vector(rom, abs)
.org 2
rjmp _ISR_int0_handler
.area data(ram, con, rel)
.dbfile f:\MYDOCU~1\AVR\led\代码\led.c
.area text(rom, con, rel)
.dbfile f:\MYDOCU~1\AVR\led\代码\led.c
.dbfunc e ISR_int0_handler _ISR_int0_handler fV
; b -> <dead>
; a -> <dead>
.even
_ISR_int0_handler::
st -y,R0
st -y,R1
st -y,R2
st -y,R3
st -y,R4
st -y,R5
st -y,R6
st -y,R7
st -y,R8
st -y,R9
st -y,R16
st -y,R17
st -y,R18
st -y,R19
st -y,R24
st -y,R25
st -y,R26
st -y,R27
st -y,R30
st -y,R31
in R0,0x3f
st -y,R0
.dbline -1
.dbline 38
; /*-----------------------------------------------------------------------------
; * File: LED01.C
; * Author: David Boydston - Solutions Consulting - http://www.serialio.com
; * Copyright (c) 1999 Solutions Consulting All Rights Reserved.
; *
; * Function: Test the light sequence on Atmel 8515 development board
; * Lights should blink one at a time 'up' from PB0 to PB7 then back 'down'
; * from PB7 to PB0. Then the lights will 'stack up' from PB0 to PB7 and
; * 'stack down' from PB7 to PB0. At any time when the PB2 button is
; * pressed the lights should display with an alternating pattern momentarily
; * then continue with the blinking pattern.
; *
; * See disclaimer at http://www.serialio.com/Legal/SoftDisclaimer.htm
; *---------------------------------------------------------------------------*/
;
; #include <io8515v.h>
; #include <macros.h>
;
; #define CLK_DIV_BY_0 0x01 //rolls at 8.19ms with 4Mhz Clock
; #define CLK_DIV_BY_8 0x02 //rolls at 65.5ms with 4Mhz Clock
; #define CLK_DIV_BY_64 0x03 //rolls at 524ms with 4Mhz Clock
; #define CLK_DIV_BY_256 0x04 //rolls at 2.1sec with 4Mhz Clock
; #define CLK_DIV_BY_1024 0x05 //rolls at 8.4sec with 4Mhz Clock
; #define TMR1_OVF_INT_ENA 0x80
; #define GLOBAL_INT_ENA 0x80
; #define INT0_ENA 0x40
; #define INT0_TRIG_FALL_EDGE 0x02
; #define INT1_ENA 0x80
;
; unsigned char tmrRollFlag = 0;
;
; void delay2(unsigned char);
; #pragma interrupt_handler ISR_int0_handler:2
; //Note: GIMSK I-bit cleared by MCU on INT and set by MCU on RETI
; //Thus there should be no danger of us being involked multiple
; //times by switch bounce (as long as delay is reasonable to see LED)
; void ISR_int0_handler()
; {
.dbline 40
; unsigned char a, b;
; PORTB = 0x55;
ldi R24,85
out 0x18,R24
.dbline 41
; delay2(5); //doing this in ISR causes heavy stack use.
ldi R16,5
rcall _delay2
.dbline -2
L1:
.dbline 0 ; func end
ld R0,y+
out 0x3f,R0
ld R31,y+
ld R30,y+
ld R27,y+
ld R26,y+
ld R25,y+
ld R24,y+
ld R19,y+
ld R18,y+
ld R17,y+
ld R16,y+
ld R9,y+
ld R8,y+
ld R7,y+
ld R6,y+
ld R5,y+
ld R4,y+
ld R3,y+
ld R2,y+
ld R1,y+
ld R0,y+
reti
.dbsym l b 1 c
.dbsym l a 1 c
.dbend
.area vector(rom, abs)
.org 12
rjmp _ISR_tmr1_ovf_handler
.area text(rom, con, rel)
.dbfile f:\MYDOCU~1\AVR\led\代码\led.c
.dbfunc e ISR_tmr1_ovf_handler _ISR_tmr1_ovf_handler fV
.even
_ISR_tmr1_ovf_handler::
st -y,R24
in R24,0x3f
st -y,R24
.dbline -1
.dbline 52
; /*
; //this way is easier on the stack
; for (a = 1; a; a++)
; for (b = 1; b; b++)
; ;
; */
; }
;
; #pragma interrupt_handler ISR_tmr1_ovf_handler:7
; void ISR_tmr1_ovf_handler()
; {
.dbline 54
; // PORTB = 0x0f; //sanity check
; tmrRollFlag = 1;
ldi R24,1
sts _tmrRollFlag,R24
.dbline -2
L2:
.dbline 0 ; func end
ld R24,y+
out 0x3f,R24
ld R24,y+
reti
.dbend
.dbfunc e delay _delay fV
; i -> R20,R21
; n -> R16
.even
_delay::
st -y,R20
st -y,R21
.dbline -1
.dbline 58
; }
;
; void delay(unsigned char n)
; {
.dbline 61
; int i;
;
; for (i = 0; i < n; i++) {
clr R20
clr R21
rjmp L7
L4:
.dbline 61
.dbline 62
; tmrRollFlag = 0;
clr R2
sts _tmrRollFlag,R2
L8:
.dbline 63
; while (!tmrRollFlag); //wait for IRQ
L9:
.dbline 63
lds R2,_tmrRollFlag
tst R2
breq L8
X0:
.dbline 64
; }
L5:
.dbline 61
subi R20,255 ; offset = 1
sbci R21,255
L7:
.dbline 61
mov R2,R16
clr R3
cp R20,R2
cpc R21,R3
brlt L4
X1:
.dbline -2
L3:
.dbline 0 ; func end
ld R21,y+
ld R20,y+
ret
.dbsym r i 20 I
.dbsym r n 16 c
.dbend
.dbfunc e delay2 _delay2 fV
; a -> R20
; b -> R22
; c -> R10
; n -> R16
.even
_delay2::
rcall push_xgsetF00C
.dbline -1
.dbline 77
;
; }
;
; #ifdef FIXED_DELAY
; void delay()
; {
; tmrRollFlag = 0;
; while (!tmrRollFlag); //wait for IRQ
; }
; #endif
;
; void delay2(unsigned char n)
; {
.dbline 80
; unsigned char a, b, c;
;
; for (a = 1; a; a++)
ldi R20,1
rjmp L15
L12:
.dbline 81
; for (b = 1; b; b++)
ldi R22,1
rjmp L19
L16:
.dbline 82
; for (c = 1; c<n; c++)
clr R10
inc R10
rjmp L23
L20:
.dbline 83
; ;
L21:
.dbline 82
inc R10
L23:
.dbline 82
cp R10,R16
brlo L20
X2:
L17:
.dbline 81
inc R22
L19:
.dbline 81
tst R22
brne L16
X3:
L13:
.dbline 80
inc R20
L15:
.dbline 80
tst R20
brne L12
X4:
.dbline -2
L11:
.dbline 0 ; func end
rjmp pop_xgsetF00C
.dbsym r a 20 c
.dbsym r b 22 c
.dbsym r c 10 c
.dbsym r n 16 c
.dbend
.dbfunc e LED_On _LED_On fV
; i -> R10,R11
.even
_LED_On::
st -y,R10
st -y,R11
mov R10,R16
mov R11,R17
.dbline -1
.dbline 87
; }
;
; void LED_On(int i)
; {
.dbline 88
; PORTB = ~BIT(i); /* low output to turn LED on */
ldi R16,1
ldi R17,0
mov R18,R10
mov R19,R11
rcall lsl16
mov R2,R16
mov R3,R17
com R2
com R3
out 0x18,R2
.dbline 90
; // delay2(0);
; delay(3);
ldi R16,3
rcall _delay
.dbline -2
L24:
.dbline 0 ; func end
ld R11,y+
ld R10,y+
ret
.dbsym r i 10 I
.dbend
.dbfunc e main _main fV
; v -> R22
; i -> R20
.even
_main::
.dbline -1
.dbline 94
; }
;
; void main()
; {
.dbline 97
; signed char i, v;
;
; DDRB = 0xFF; /* output */
ldi R24,255
out 0x17,R24
.dbline 98
; PORTB = 0x55; //sanity check
ldi R24,85
out 0x18,R24
.dbline 99
; delay2(5);
ldi R16,5
rcall _delay2
.dbline 101
;
; TCCR1A = 0;
clr R2
out 0x2f,R2
.dbline 102
; TCCR1B = CLK_DIV_BY_8;
ldi R24,2
out 0x2e,R24
.dbline 104
; // TCCR1B = CLK_DIV_BY_64;
; TIMSK = TMR1_OVF_INT_ENA;
ldi R24,128
out 0x39,R24
.dbline 106
;
; MCUCR = INT0_TRIG_FALL_EDGE;
ldi R24,2
out 0x35,R24
.dbline 107
; MCUCR = 0; //low level trig
out 0x35,R2
.dbline 108
; GIMSK = INT0_ENA;
ldi R24,64
out 0x3b,R24
.dbline 110
;
; SREG = GLOBAL_INT_ENA; //enable ints
ldi R24,128
out 0x3f,R24
rjmp L27
L26:
.dbline 113
;
; while (1)
; {
.dbline 115
; /* forward march */
; for (i = 0; i < 8; i++)
clr R20
rjmp L32
L29:
.dbline 116
; LED_On(i);
mov R16,R20
clr R17
sbrc R16,7
com R17
rcall _LED_On
L30:
.dbline 115
inc R20
L32:
.dbline 115
cpi R20,8
brlt L29
X5:
.dbline 118
; /* backward march, don't repeat bit 7 */
; for (i = 6; i >= 0; i--)
ldi R20,6
rjmp L36
L33:
.dbline 119
; LED_On(i);
mov R16,R20
clr R17
sbrc R16,7
com R17
rcall _LED_On
L34:
.dbline 118
dec R20
L36:
.dbline 118
cpi R20,0
brge L33
X6:
.dbline 123
; //PORTB = 0xF0; //sanity check
; //delay();
; /* stack, don't repeat bit 0 */
; for (i = 0, v = 3; i < 7; i++) {
clr R20
ldi R22,3
rjmp L40
L37:
.dbline 123
.dbline 124
; PORTB = ~v;
mov R2,R22
com R2
out 0x18,R2
.dbline 125
; v |= v << 1;
mov R2,R22
lsl R2
or R22,R2
.dbline 126
; delay(3);
ldi R16,3
rcall _delay
.dbline 127
; }
L38:
.dbline 123
inc R20
L40:
.dbline 123
cpi R20,7
brlt L37
X7:
.dbline 129
; /* unstack */
; for (i = 0, v = 0x7F; i < 8; i++) {
clr R20
ldi R22,127
rjmp L44
L41:
.dbline 129
.dbline 130
; PORTB = ~v;
mov R2,R22
com R2
out 0x18,R2
.dbline 131
; v &= v >> 1;
mov R2,R22
asr R2
and R22,R2
.dbline 132
; delay(3);
ldi R16,3
rcall _delay
.dbline 133
; }
L42:
.dbline 129
inc R20
L44:
.dbline 129
cpi R20,8
brlt L41
X8:
.dbline 134
; }
L27:
.dbline 112
rjmp L26
X9:
.dbline -2
L25:
.dbline 0 ; func end
ret
.dbsym r v 22 C
.dbsym r i 20 C
.dbend
; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -