📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
.dbfunc e Delay _Delay fV
; i -> R16,R17
.even
_Delay::
.dbline -1
.dbline 43
; /*****************************************************************************
; *
; * Copyright (C) 1996-1998 Atmel Corporation
; *
; * File : main.c
; * Compiler : IAR 1.51B
; * Output size : 505 bytes (size optimized)
; * Created : 16-jun-99
; * Modified : 5-jan-2000
; * Last modified : 16-may-2001 by jll
; *
; * Support mail : avr@atmel.com
; *
; * Description : This Program allows an AVR with bootloader capabilities to
; * Read/write its own Flash/EEprom. To enter Programming mode
; * PD2 is checked, it this pin is pulled low, programming mode
; * is entered. If not, normal execution is done from $0000
; * "reset" vector in Application area.
; * The PD2 pin should be pulled HIGH by an external Pull-up
; * resistor.
; *
; * Other info : Code must be modified to use this specific code with devices
; * other than ATmega161. Following change should be made:
; * -Specify device in define list (e.g. _ATMEGA163)
; *
; * When using this code with (future) parts other than ATmega32,
; * ATmega161 and ATmega163, it will be necessary to change more
; * than the device name. The changes that should be made is:
; * -Device name
; * -Device signature and memory settings (defines.h)
; * -Device code
; * -Linker file
; *
; * In general the linker file should always be verifyed to match
; * the used part's boot address and size. Note that memory size
; * is specified in bytes in the linker file.
; ****************************************************************************/
; #include "defines.h"
; #include "serial.h"
; #include "assembly.h"
;
; void Delay(unsigned int i)
; {
L2:
.dbline 44
L3:
.dbline 44
; while(i--) ;
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L2
tst R3
brne L2
X0:
.dbline -2
.dbline 45
; }
L1:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e Display_IAP _Display_IAP fV
.even
_Display_IAP::
.dbline -1
.dbline 48
;
; void Display_IAP(void)
; {
.dbline 49
; PORTD = 0xEF;
ldi R24,239
out 0x12,R24
.dbline 50
; PORTB = 0xF9;
ldi R24,249
out 0x18,R24
.dbline 51
; Delay(6000);
ldi R16,6000
ldi R17,23
rcall _Delay
.dbline 52
; PORTD = 0xB7;
ldi R24,183
out 0x12,R24
.dbline 53
; PORTB = 0x08;
ldi R24,8
out 0x18,R24
.dbline 54
; Delay(6000);
ldi R16,6000
ldi R17,23
rcall _Delay
.dbline 55
; PORTD = 0xBB;
ldi R24,187
out 0x12,R24
.dbline 56
; PORTB = 0xCC;
ldi R24,204
out 0x18,R24
.dbline -2
.dbline 57
; }
L5:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 18
rjmp _timer0_ovf_isr
.area text(rom, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
.dbfunc e timer0_ovf_isr _timer0_ovf_isr fV
.even
_timer0_ovf_isr::
rcall push_lset
.dbline -1
.dbline 61
;
; #pragma interrupt_handler timer0_ovf_isr:10
; void timer0_ovf_isr(void)
; {
.dbline 62
; TCNT0 = 0x8D; //reload counter value
ldi R24,141
out 0x32,R24
.dbline 63
; Display_IAP();
rcall _Display_IAP
.dbline -2
.dbline 64
; }
L6:
rcall pop_lset
.dbline 0 ; func end
reti
.dbend
.dbfunc e main _main fV
; intval -> <dead>
; val -> R20
; address -> R22,R23
; data -> R14,R15
; page_size -> R10
; page_address -> R12,R13
.even
_main::
.dbline -1
.dbline 66
; void main(void)
; {
.dbline 69
; unsigned int intval,address,data,page_address;
; unsigned char val, page_size;
; Delay(10000);
ldi R16,10000
ldi R17,39
rcall _Delay
.dbline 70
; SerialInit();
rcall _SerialInit
.dbline 71
; Delay(50000);
ldi R16,50000
ldi R17,195
rcall _Delay
.dbline 72
; sendstr("富友勤IAP V1.0 ");
ldi R16,<L8
ldi R17,>L8
rcall _sendstr
.dbline 73
; PORTB = 0xFF;
ldi R24,255
out 0x18,R24
.dbline 74
; DDRB = 0xFF;
out 0x17,R24
.dbline 75
; PORTC = 0x7F; //m103 output only
ldi R24,127
out 0x15,R24
.dbline 76
; DDRC = 0x79;
ldi R24,121
out 0x14,R24
.dbline 77
; PORTD = 0xFF;
ldi R24,255
out 0x12,R24
.dbline 78
; DDRD = 0xFC;
ldi R24,252
out 0x11,R24
.dbline 79
; val=UDR;
in R20,0xc
.dbline 80
; val=reccharcommand2();
rcall _reccharcommand2
mov R20,R16
.dbline 81
; if(val=='I') //Chip erase
cpi R16,73
brne L9
.dbline 82
; goto Binger;
rjmp L11
L9:
.dbline 87
;
; //UCSRB = 0x00; //disable while setting baud rate
; //UCSRA = 0x00;
;
; PROGPORT |= PROGCTRL; //enable pull-up on PROGCTRL line on PROGPORT
sbi 0x12,2
.dbline 88
; if (PROGMODE)
sbic 0x10,2
rjmp L12
.dbline 89
; {
L11:
.dbline 92
; Binger:
;
; sendstr("富友勤 ATMEGA8 DEMO");
ldi R16,<L14
ldi R17,>L14
rcall _sendstr
.dbline 93
; sendstr("Start IAP");
ldi R16,<L15
ldi R17,>L15
rcall _sendstr
.dbline 94
; for(;;)
L16:
.dbline 95
; {
.dbline 96
; Display_IAP();
rcall _Display_IAP
.dbline 97
; val=reccharcommand();
rcall _reccharcommand
mov R20,R16
.dbline 98
; if(val=='W') //Chip erase
cpi R16,87
breq X5
rjmp L20
X5:
.dbline 99
; {
.dbline 100
; sendstr("Start Write ");
ldi R16,<L22
ldi R17,>L22
rcall _sendstr
.dbline 101
; page_address=recchar();
rcall _recchar
mov R12,R16
clr R13
.dbline 102
; page_address|=recchar()<<8;
rcall _recchar
mov R2,R16
clr R3
mov R3,R2
clr R2
or R12,R2
or R13,R3
.dbline 103
; for(address=0;address < APP_END;address += PAGESIZE) //Application section = 60 pages
clr R22
clr R23
rjmp L26
L23:
.dbline 104
; {
.dbline 105
; for(page_size=0;page_size < PAGESIZE;page_size += 2) //Application section = 60 pages
clr R10
rjmp L30
L27:
.dbline 106
; {
.dbline 107
; if(page_address!=0)
tst R12
brne X1
tst R13
breq L31
X1:
.dbline 108
; data=recchar();
rcall _recchar
mov R14,R16
clr R15
rjmp L32
L31:
.dbline 110
; else
; data=0xFF;
ldi R24,255
ldi R25,0
movw R14,R24
L32:
.dbline 111
; if(page_address)
tst R12
brne X2
tst R13
breq L33
X2:
.dbline 112
; page_address--;
movw R24,R12
sbiw R24,1
movw R12,R24
L33:
.dbline 113
; if(page_address!=0)
tst R12
brne X3
tst R13
breq L35
X3:
.dbline 114
; data|=recchar()<<8;
rcall _recchar
mov R2,R16
clr R3
mov R3,R2
clr R2
or R14,R2
or R15,R3
rjmp L36
L35:
.dbline 116
; else
; data|=0xFF<<8;
movw R24,R14
ori R25,255
movw R14,R24
L36:
.dbline 117
; if(page_address)
tst R12
brne X4
tst R13
breq L37
X4:
.dbline 118
; page_address--;
movw R24,R12
sbiw R24,1
movw R12,R24
L37:
.dbline 119
mov R18,R10
clr R19
movw R16,R14
rcall _fill_temp_buffer
.dbline 120
L28:
.dbline 105
mov R24,R10
subi R24,254 ; addi 2
mov R10,R24
L30:
.dbline 105
mov R24,R10
cpi R24,64
brsh X6
rjmp L27
X6:
.dbline 121
ldi R18,5
movw R16,R22
rcall _write_page
.dbline 122
L24:
.dbline 103
subi R22,192 ; offset = 64
sbci R23,255
L26:
.dbline 103
cpi R22,0
ldi R30,28
cpc R23,R30
brsh X7
rjmp L23
X7:
.dbline 123
; fill_temp_buffer(data,(page_size)); //call asm routine.
; }
; write_page((address),0x05);
; }
; sendstr("End Write ");
ldi R16,<L39
ldi R17,>L39
rcall _sendstr
.dbline 124
; }
rjmp L16
L20:
.dbline 126
;
; else if(val=='e') //Chip erase
cpi R20,101
breq X8
rjmp L16
X8:
.dbline 127
; {
.dbline 128
; sendstr("Start Erase ");
ldi R16,<L42
ldi R17,>L42
rcall _sendstr
.dbline 130
;
; for(address=0;address < APP_END;address += PAGESIZE) //Application section = 60 pages
clr R22
clr R23
rjmp L46
L43:
.dbline 131
.dbline 131
ldi R16,20000
ldi R17,78
rcall _Delay
.dbline 132
ldi R18,3
movw R16,R22
rcall _write_page
.dbline 133
L44:
.dbline 130
subi R22,192 ; offset = 64
sbci R23,255
L46:
.dbline 130
cpi R22,0
ldi R30,28
cpc R23,R30
brlo L43
.dbline 134
; {Delay(20000);
; write_page(address,0x03); //Perform page erase
; }
; sendstr("End Erase ");
ldi R16,<L47
ldi R17,>L47
rcall _sendstr
.dbline 135
; }
.dbline 138
;
;
; }
.dbline 94
.dbline 94
rjmp L16
L12:
.dbline 141
; }
; else
; { asm("JMP 0x0000") ;
.dbline 141
JMP 0x0000
.dbline 142
; UCSRB = 0x00;
clr R2
out 0xa,R2
.dbline 143
; }
.dbline -2
.dbline 145
;
; }
L7:
.dbline 0 ; func end
ret
.dbsym l intval 1 i
.dbsym r val 20 c
.dbsym r address 22 i
.dbsym r data 14 i
.dbsym r page_size 10 c
.dbsym r page_address 12 i
.dbend
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
L47:
.blkb 12
.area idata
.byte 'E,'n,'d,32,32,'E,'r,'a,'s,'e,32,0
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
L42:
.blkb 13
.area idata
.byte 'S,'t,'a,'r,'t,32,'E,'r,'a,'s,'e,32,0
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
L39:
.blkb 11
.area idata
.byte 'E,'n,'d,32,'W,'r,'i,'t,'e,32,0
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
L22:
.blkb 13
.area idata
.byte 'S,'t,'a,'r,'t,32,'W,'r,'i,'t,'e,32,0
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
L15:
.blkb 10
.area idata
.byte 'S,'t,'a,'r,'t,32,'I,'A,'P,0
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
L14:
.blkb 20
.area idata
.byte 184,187,211,209,199,218,32,'A,'T,'M,'E,'G,'A,56,32,'D
.byte 'E,'M,'O,0
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
L8:
.blkb 16
.area idata
.byte 184,187,211,209,199,218,'I,'A,'P,32,'V,49,46,48,32,0
.area data(ram, con, rel)
.dbfile D:\AVR_Demo\M8IAP\Source\main.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -