⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 salve.s

📁 用两片AVR(ATmega16)单片机 实现双机通信(双向
💻 S
📖 第 1 页 / 共 2 页
字号:
	.module salve.c
	.area text(rom, con, rel)
	.dbfile D:\MYDOCU~1\MYMCUW~1\AVR\spi\salve.c
	.dbfile D:\MYDOCU~1\MYMCUW~1\AVR\spi\display.c
	.dbfunc e SEND _SEND fV
;              i -> R10,R11
;              x -> y+0
;              j -> R14
;            ads -> R12
;            dat -> R18
;            add -> y+7
	.even
_SEND::
	xcall push_arg4
	xcall push_xgset00FC
	sbiw R28,1
	.dbline -1
	.dbline 5
; #include "display.h"
; 
; //===================MAX7219的核心函数,接收单片机的数据===================== 
; void SEND(unsigned char add,unsigned char dat)//发送2个字节的子函数,第一个字节为地址,第二个字节为操作数  
; {  
	.dbline 8
; unsigned char ads,j,x;  
; unsigned int i;  
; i=0;  
	clr R10
	clr R11
	.dbline 9
; MAX7219_LOAD_0;//load=0  
	cbi 0x18,1
	xjmp L3
L2:
	.dbline 11
;    while(i<16)  
;    {
	.dbline 13
; //   if(add==1||add==5) dat=dat|0x80; //小数点问题解决
;    if (i<8){ads=add;}   
	movw R24,R10
	cpi R24,8
	ldi R30,0
	cpc R25,R30
	brsh L5
X0:
	.dbline 13
	.dbline 13
	ldd R12,y+7
	.dbline 13
	xjmp L6
L5:
	.dbline 14
;    else {ads=dat;}   
	.dbline 14
	mov R12,R18
	.dbline 14
L6:
	.dbline 15
;       for(j=8;j>=1;j--)  
	ldi R24,8
	mov R14,R24
	xjmp L10
L7:
	.dbline 16
;       {  
	.dbline 17
;       x=ads&0x80;  
	mov R24,R12
	andi R24,128
	std y+0,R24
	.dbline 18
;          if (x==0){MAX7219_DIN_0;}  
	mov R0,R24
	tst R24
	brne L11
X1:
	.dbline 18
	.dbline 18
	cbi 0x18,2
	.dbline 18
	xjmp L12
L11:
	.dbline 19
;          else {MAX7219_DIN_1;}  
	.dbline 19
	sbi 0x18,2
	.dbline 19
L12:
	.dbline 20
;             ads=ads<<1;  
	lsl R12
	.dbline 21
;       MAX7219_CLK_1;//clk=1  
	sbi 0x18,0
	.dbline 22
;          MAX7219_CLK_0;//clk=0  
	cbi 0x18,0
	.dbline 23
;       }  
L8:
	.dbline 15
	dec R14
L10:
	.dbline 15
	mov R24,R14
	cpi R24,1
	brsh L7
X2:
	.dbline 24
;    i=i+8;  
	movw R24,R10
	adiw R24,8
	movw R10,R24
	.dbline 25
;    }  
L3:
	.dbline 10
	movw R24,R10
	cpi R24,16
	ldi R30,0
	cpc R25,R30
	brlo L2
X3:
	.dbline 26
; MAX7219_LOAD_1;//load=1  
	sbi 0x18,1
	.dbline -2
L1:
	.dbline 0 ; func end
	adiw R28,1
	xcall pop_xgset00FC
	adiw R28,4
	ret
	.dbsym r i 10 i
	.dbsym l x 0 c
	.dbsym r j 14 c
	.dbsym r ads 12 c
	.dbsym r dat 18 c
	.dbsym l add 7 c
	.dbend
	.dbfunc e SEG_LIGHT _SEG_LIGHT fV
;          light -> R10,R11
	.even
_SEG_LIGHT::
	st -y,R10
	movw R10,R16
	.dbline -1
	.dbline 32
; }  
; //===================================== 
; 
; //==============SEG亮度================ 
; void SEG_LIGHT(unsigned light) 
; { 
	.dbline 33
; SEND(0x0a,light&0x0f); 
	mov R18,R10
	andi R18,15
	andi R19,0
	ldi R16,10
	xcall _SEND
	.dbline -2
L13:
	.dbline 0 ; func end
	ld R10,y+
	ret
	.dbsym r light 10 i
	.dbend
	.dbfunc e SEG_OPEN _SEG_OPEN fV
	.even
_SEG_OPEN::
	.dbline -1
	.dbline 39
; } 
; //=================================== 
; 
; //==============SEG开================ 
; void SEG_OPEN(void) 
; { 
	.dbline 40
; SEND(0x0c,0x01); 
	ldi R18,1
	ldi R16,12
	xcall _SEND
	.dbline -2
L14:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SEG_CLOSE _SEG_CLOSE fV
	.even
_SEG_CLOSE::
	.dbline -1
	.dbline 46
; } 
; //=================================== 
; 
; //==============SEG关================ 
; void SEG_CLOSE(void) 
; { 
	.dbline 47
; SEND(0x0c,0x00); 
	clr R18
	ldi R16,12
	xcall _SEND
	.dbline -2
L15:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SEG_CLEAR _SEG_CLEAR fV
;           part -> R10
	.even
_SEG_CLEAR::
	st -y,R10
	st -y,R11
	mov R10,R16
	.dbline -1
	.dbline 53
; } 
; //=================================== 
; 
; //==============SEG清屏==============
; void SEG_CLEAR(unsigned char part) 
; { 
	.dbline 54
; switch(part) 
	clr R11
	tst R10
	brne X4
	tst R11
	breq L20
X4:
	movw R24,R10
	cpi R24,1
	ldi R30,0
	cpc R25,R30
	breq L21
X5:
	xjmp L17
L20:
	.dbline 57
;         { 
;         case 0://左 
;                 { 
	.dbline 58
;                 SEND(0x01,0x0f);  
	ldi R18,15
	ldi R16,1
	xcall _SEND
	.dbline 59
;                 SEND(0x02,0x0f);  
	ldi R18,15
	ldi R16,2
	xcall _SEND
	.dbline 60
;                 SEND(0x03,0x0f);  
	ldi R18,15
	ldi R16,3
	xcall _SEND
	.dbline 61
;                 SEND(0x04,0x0f); 
	ldi R18,15
	ldi R16,4
	xcall _SEND
	.dbline 62
;                 }break; 
	.dbline 62
	xjmp L18
L21:
	.dbline 64
;         case 1://右 
;                 { 
	.dbline 65
;                 SEND(0x05,0x0f);  
	ldi R18,15
	ldi R16,5
	xcall _SEND
	.dbline 66
;                 SEND(0x06,0x0f);  
	ldi R18,15
	ldi R16,6
	xcall _SEND
	.dbline 67
;                 SEND(0x07,0x0f);  
	ldi R18,15
	ldi R16,7
	xcall _SEND
	.dbline 68
;                 SEND(0x08,0x0f); 
	ldi R18,15
	ldi R16,8
	xcall _SEND
	.dbline 69
;                 }break; 
	.dbline 69
	xjmp L18
L17:
	.dbline 71
;         default://全部 
;                 { 
	.dbline 72
;                 SEND(0x01,0x0f);  
	ldi R18,15
	ldi R16,1
	xcall _SEND
	.dbline 73
;                 SEND(0x02,0x0f);  
	ldi R18,15
	ldi R16,2
	xcall _SEND
	.dbline 74
;                 SEND(0x03,0x0f);  
	ldi R18,15
	ldi R16,3
	xcall _SEND
	.dbline 75
;                 SEND(0x04,0x0f); 
	ldi R18,15
	ldi R16,4
	xcall _SEND
	.dbline 76
;                 SEND(0x05,0x0f);  
	ldi R18,15
	ldi R16,5
	xcall _SEND
	.dbline 77
;                 SEND(0x06,0x0f);  
	ldi R18,15
	ldi R16,6
	xcall _SEND
	.dbline 78
;                 SEND(0x07,0x0f);  
	ldi R18,15
	ldi R16,7
	xcall _SEND
	.dbline 79
;                 SEND(0x08,0x0f); 
	ldi R18,15
	ldi R16,8
	xcall _SEND
	.dbline 80
;                 }break; 
	.dbline 80
L18:
	.dbline -2
L16:
	.dbline 0 ; func end
	ld R11,y+
	ld R10,y+
	ret
	.dbsym r part 10 c
	.dbend
	.dbfunc e SEG_INIT _SEG_INIT fV
	.even
_SEG_INIT::
	.dbline -1
	.dbline 86
;         } 
; } 
; 
; //==============SEG初始化============= 
; void SEG_INIT(void) 
; { 
	.dbline 87
; MAX7219_OUT_DDR|=(1<<MAX7219_CLK_PORT)|(1<<MAX7219_DIN_PORT)|(1<<MAX7219_LOAD_PORT); 
	in R24,0x17
	ori R24,7
	out 0x17,R24
	.dbline 88
; MAX7219_OUT_PORT|=(1<<MAX7219_CLK_PORT)|(1<<MAX7219_DIN_PORT)|(1<<MAX7219_LOAD_PORT); 
	in R24,0x18
	ori R24,7
	out 0x18,R24
	.dbline 89
; SEND(0x0c,0x01); 
	ldi R18,1
	ldi R16,12
	xcall _SEND
	.dbline 90
; SEND(0x0b,0x07);  
	ldi R18,7
	ldi R16,11
	xcall _SEND
	.dbline 91
; SEND(0x0a,0x05);  
	ldi R18,5
	ldi R16,10
	xcall _SEND
	.dbline 92
; SEND(0x09,0xff);  
	ldi R18,255
	ldi R16,9
	xcall _SEND
	.dbline 93
; SEG_CLEAR(3); 
	ldi R16,3
	xcall _SEG_CLEAR
	.dbline -2
L22:
	.dbline 0 ; func end
	ret
	.dbend
	.dbfunc e SEG_L _SEG_L fV
;              i -> R12
;         number -> R10,R11
	.even
_SEG_L::
	xcall push_xgset003C
	movw R10,R16
	.dbline -1
	.dbline 99
; } 
; 
; 
; //=============SEG左四显示数字============== 
; void SEG_L(unsigned int number) 
; { 
	.dbline 100
; unsigned char i=4; 
	ldi R24,4
	mov R12,R24
	.dbline 101
; SEND(0x01,0x0f); //先清除左四位,左四位黑屏 
	ldi R18,15
	ldi R16,1
	xcall _SEND
	.dbline 102
; SEND(0x02,0x0f);  
	ldi R18,15
	ldi R16,2
	xcall _SEND
	.dbline 103
; SEND(0x03,0x0f);  
	ldi R18,15
	ldi R16,3
	xcall _SEND
	.dbline 104
; SEND(0x04,0x0f); 
	ldi R18,15
	ldi R16,4
	xcall _SEND
	.dbline 106
; 
; if(number>9999)//要显示的数值超过4位,则显示4个H 
	ldi R24,9999
	ldi R25,39
	cp R24,R10
	cpc R25,R11
	brsh L24
X6:
	.dbline 107
;         { 
	.dbline 108
;         SEND(0x01,0x0c);  
	ldi R18,12
	ldi R16,1
	xcall _SEND
	.dbline 109
;         SEND(0x02,0x0c);  
	ldi R18,12
	ldi R16,2
	xcall _SEND
	.dbline 110
;         SEND(0x03,0x0c);  
	ldi R18,12
	ldi R16,3
	xcall _SEND
	.dbline 111
;         SEND(0x04,0x0c); 
	ldi R18,12
	ldi R16,4
	xcall _SEND
	.dbline 112
;         } 
	xjmp L25
L24:
	.dbline 114
; else//小于四位可以显示 
;         { 
L26:
	.dbline 121
; /*		for(i=4;i>0;i--)
; 		 {
; 		  SEND(i,number%10);
; 		  number=(number-number%10)/10; 
; 		 }		*/
;         do 
;                 { 
	.dbline 122
;                 SEND(i,number%10); 
	ldi R18,10
	ldi R19,0
	movw R16,R10
	xcall mod16u
	mov R18,R16
	mov R16,R12
	xcall _SEND
	.dbline 123
;                 number=(number-number%10)/10; 

⌨️ 快捷键说明

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