led00.s

来自「这是关于AVR单片机学习的初步开发」· S 代码 · 共 408 行

S
408
字号
	.module led00.c
	.area text(rom, con, rel)
	.dbfile C:\DOCUME~1\alf\MYDOCU~1\开发板\调试程序\led\led00.c
	.dbfunc e port_init _port_init fV
	.even
_port_init::
	.dbline -1
	.dbline 12
; //I/O演示程序
; //程序流程:全亮->全灭->PD隔一步进->全亮->全灭->PD隔二步进->全亮->全灭->PB全亮->pb0置位->pb0清零->PB0反转->全灭->(循环)
; 
; // Target : M8
; // Crystal: 11.059Mhz
; 
; #include <iom8v.h>
; #include <macros.h>
; 
; //起始全亮
; void port_init(void)
; {
	.dbline 13
;  PORTB = 0x00;
	clr R2
	out 0x18,R2
	.dbline 14
;  DDRB  = 0xFF;
	ldi R24,255
	out 0x17,R24
	.dbline 15
;  PORTC = 0x00; 
	out 0x15,R2
	.dbline 16
;  DDRC  = 0x7F;
	ldi R24,127
	out 0x14,R24
	.dbline 17
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 18
;  DDRD  = 0xFF;
	ldi R24,255
	out 0x11,R24
	.dbline -2
	.dbline 19
; }
L1:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e delay _delay fV
;              i -> R20,R21
;              j -> R22,R23
;            tim -> R16
	.even
_delay::
	rcall push_gset2
	.dbline -1
	.dbline 23
; 
; //延时函数,大约1ms;
; void delay(char tim)
; {
	.dbline 25
;  unsigned int i,j;
;  for(i=0;i<tim;i++)
	clr R20
	clr R21
	rjmp L6
L3:
	.dbline 26
	clr R22
	clr R23
	rjmp L10
L7:
	.dbline 26
L8:
	.dbline 26
	subi R22,255  ; offset = 1
	sbci R23,255
L10:
	.dbline 26
	cpi R22,16
	ldi R30,39
	cpc R23,R30
	brlo L7
L4:
	.dbline 25
	subi R20,255  ; offset = 1
	sbci R21,255
L6:
	.dbline 25
	mov R2,R16
	clr R3
	cp R20,R2
	cpc R21,R3
	brlo L3
	.dbline -2
	.dbline 27
;  	for(j=0;j<10000;j++);
; }
L2:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 20 i
	.dbsym r j 22 i
	.dbsym r tim 16 c
	.dbend
	.dbfunc e led_on _led_on fV
	.even
_led_on::
	.dbline -1
	.dbline 31
; 
; //led全亮
; void led_on(void)
; {
	.dbline 32
;  PORTB = 0x00;
	clr R2
	out 0x18,R2
	.dbline 33
;  PORTC = 0x00;
	out 0x15,R2
	.dbline 34
;  PORTD = 0x00;
	out 0x12,R2
	.dbline 36
;  
;  delay(5000);
	ldi R16,136
	.dbline -2
	.dbline 37
; }
L11:
	.dbline 0 ; func end
	rjmp _delay
	.dbend
	.dbfunc e led_off _led_off fV
	.even
_led_off::
	.dbline -1
	.dbline 40
; //led全灭
; void led_off(void)
; {
	.dbline 41
;  PORTB = 0xFF;
	ldi R24,255
	out 0x18,R24
	.dbline 42
;  PORTC = 0xFF;
	out 0x15,R24
	.dbline 43
;  PORTD = 0xFF;
	out 0x12,R24
	.dbline 45
;  
;  delay(5000);
	ldi R16,136
	.dbline -2
	.dbline 46
; }
L12:
	.dbline 0 ; func end
	rjmp _delay
	.dbend
	.dbfunc e pd_1 _pd_1 fV
;              i -> R20
	.even
_pd_1::
	rcall push_gset1
	.dbline -1
	.dbline 49
; //PB隔1步进
; void pd_1(void)
; {
	.dbline 51
;  char i;
;  for (i = 0; i < 8; i++)
	clr R20
	rjmp L17
L14:
	.dbline 52
	.dbline 53
	ldi R16,1
	mov R17,R20
	rcall lsl8
	mov R2,R16
	com R2
	out 0x18,R2
	.dbline 54
	ldi R16,136
	rcall _delay
	.dbline 55
L15:
	.dbline 51
	inc R20
L17:
	.dbline 51
	cpi R20,8
	brlo L14
	.dbline -2
	.dbline 56
;  {
;   	 PORTB = ~(1 << (i));//位操作结合移位操作
; 	 delay(5000);
;  }
; }
L13:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e pd_2 _pd_2 fV
;              i -> R20
	.even
_pd_2::
	rcall push_gset1
	.dbline -1
	.dbline 59
; //PB隔2步进
; void pd_2(void)
; {
	.dbline 61
;  char i;
;  for (i = 0; i < 8; i+=2)
	clr R20
	rjmp L22
L19:
	.dbline 62
	.dbline 63
	ldi R16,1
	mov R17,R20
	rcall lsl8
	mov R2,R16
	com R2
	out 0x18,R2
	.dbline 64
	ldi R16,136
	rcall _delay
	.dbline 65
L20:
	.dbline 61
	subi R20,254    ; addi 2
L22:
	.dbline 61
	cpi R20,8
	brlo L19
	.dbline -2
	.dbline 66
;  {
;   	 PORTB = ~(1 << (i));//位操作结合移位操作
; 	 delay(5000);
;  }
; }
L18:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r i 20 c
	.dbend
	.dbfunc e init_devices _init_devices fV
	.even
_init_devices::
	.dbline -1
	.dbline 70
; 
; //call this routine to initialise all peripherals
; void init_devices(void)
; {
	.dbline 72
;  //stop errant interrupts until set up
;  CLI(); //disable all interrupts
	cli
	.dbline 73
;  port_init();
	rcall _port_init
	.dbline 75
; 
;  MCUCR = 0x00;
	clr R2
	out 0x35,R2
	.dbline 76
;  GICR  = 0x00;
	out 0x3b,R2
	.dbline 77
;  TIMSK = 0x00; //timer interrupt sources
	out 0x39,R2
	.dbline 78
;  SEI(); //re-enable interrupts
	sei
	.dbline -2
	.dbline 80
;  //all peripherals are now initialised
; }
L23:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e main _main fV
	.even
_main::
	.dbline -1
	.dbline 84
; 
; //
; void main(void)
; {
	.dbline 85
;  init_devices();
	rcall _init_devices
	rjmp L26
L25:
	.dbline 88
	.dbline 89
	rcall _led_on
	.dbline 90
	rcall _led_off
	.dbline 92
	rcall _led_on
	.dbline 93
	rcall _led_off
	.dbline 96
	rcall _pd_1
	.dbline 98
	rcall _led_on
	.dbline 99
	rcall _led_off
	.dbline 102
	rcall _pd_2
	.dbline 104
	rcall _led_on
	.dbline 105
	rcall _led_off
	.dbline 109
	ldi R24,254
	out 0x18,R24
	.dbline 110
	ldi R16,136
	rcall _delay
	.dbline 112
	sbi 0x18,0
	.dbline 113
	ldi R16,136
	rcall _delay
	.dbline 115
	cbi 0x18,0
	.dbline 116
	ldi R16,136
	rcall _delay
	.dbline 118
	ldi R24,1
	in R2,0x18
	eor R2,R24
	out 0x18,R2
	.dbline 119
	ldi R16,136
	rcall _delay
	.dbline 120
L26:
	.dbline 87
	rjmp L25
X0:
	.dbline -2
	.dbline 121
;  
;  while(1)
;  {
;   led_on();
;   led_off();
;   
;   led_on();
;   led_off();
;   
;   
;   pd_1();
;   
;   led_on();
;   led_off();
;   
;   
;   pd_2();
;   
;   led_on();
;   led_off();
;   
;   
;   //赋值(会给所有的位以特定值),使pb0为0,led亮;
;   PORTB = 0xFE;
;   delay(5000);
;   //置位(不影响其他位),使pb0为1,led灭;
;   PORTB |= 0x01;
;   delay(5000);
;   //清零(不影响其他位),使pb0为0,led亮; 
;   PORTB &= ~0x01;
;   delay(5000);
;   //反转(不影响其他位),使pb0为1,led灭;
;   PORTB ^= 0x01;
;   delay(5000);
;  }
; }
L24:
	.dbline 0 ; func end
	ret
	.dbend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?