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

📄 spi.s

📁 AVRkaifashili.rar
💻 S
字号:
	.module SPI.C
	.area data(ram, con, rel)
_Table::
	.blkb 2
	.area idata
	.byte 63,6
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 91,'O
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 'f,'m
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 125,7
	.area data(ram, con, rel)
	.blkb 2
	.area idata
	.byte 127,'o
	.area data(ram, con, rel)
	.dbfile J:\AVRpractice\BOOK\SPI\SPI.C
	.dbsym e Table _Table A[10:10]c
_Data::
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile J:\AVRpractice\BOOK\SPI\SPI.C
	.blkb 2
	.area idata
	.byte 0,0
	.area data(ram, con, rel)
	.dbfile J:\AVRpractice\BOOK\SPI\SPI.C
	.dbsym e Data _Data A[4:4]c
	.area text(rom, con, rel)
	.dbfile J:\AVRpractice\BOOK\SPI\SPI.C
	.dbfunc e DelayMs _DelayMs fV
;              j -> R20
;              i -> R16,R17
	.even
_DelayMs::
	rcall push_gset1
	.dbline -1
	.dbline 10
; #include<io8535v.h>
; #include<macros.h>
; #define uchar unsigned char
; #define uint  unsigned int
; 
; uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
; uchar Data[4]={0,0,0,0};
; 
; void DelayMs(uint i)  
; {uchar j;
	.dbline 11
;  for(;i!=0;i--)
	rjmp L5
L2:
	.dbline 12
	.dbline 12
	ldi R20,208
	rjmp L9
L6:
	.dbline 12
	.dbline 12
	.dbline 12
L7:
	.dbline 12
	dec R20
L9:
	.dbline 12
	tst R20
	brne L6
	.dbline 12
L3:
	.dbline 11
	subi R16,1
	sbci R17,0
L5:
	.dbline 11
	cpi R16,0
	cpc R16,R17
	brne L2
X0:
	.dbline -2
	.dbline 13
;   {for(j=2000;j!=0;j--) {;}}
; }
L1:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r j 20 c
	.dbsym r i 16 i
	.dbend
	.dbfunc e Display _Display fV
;            sel -> R20
;              i -> R22
;              p -> R10,R11
	.even
_Display::
	rcall push_gset3
	mov R10,R16
	mov R11,R17
	.dbline -1
	.dbline 16
; 
; void Display(uchar *p)
; {uchar i,sel=0x01;
	.dbline 16
	ldi R20,1
	.dbline 17
;  for(i=0;i<4;i++)
	clr R22
	rjmp L14
L11:
	.dbline 18
	.dbline 18
	out 0x1b,R20
	.dbline 19
	mov R30,R22
	clr R31
	add R30,R10
	adc R31,R11
	ldd R30,z+0
	clr R31
	ldi R24,<_Table
	ldi R25,>_Table
	add R30,R24
	adc R31,R25
	ldd R2,z+0
	clr R3
	ldi R24,255
	ldi R25,0
	sub R24,R2
	sbc R25,R3
	out 0x15,R24
	.dbline 20
	ldi R16,10
	ldi R17,0
	rcall _DelayMs
	.dbline 21
	lsl R20
	.dbline 22
L12:
	.dbline 17
	inc R22
L14:
	.dbline 17
	cpi R22,4
	brlo L11
	.dbline -2
	.dbline 23
;   {PORTA=sel;
;    PORTC=0xff-Table[p[i]];
;    DelayMs(10);
;    sel=sel<<1;
;   }
; }
L10:
	rcall pop_gset3
	.dbline 0 ; func end
	ret
	.dbsym r sel 20 c
	.dbsym r i 22 c
	.dbsym r p 10 pc
	.dbend
	.dbfunc e DelayNOP _DelayNOP fV
;              i -> R16
	.even
_DelayNOP::
	.dbline -1
	.dbline 26
; 
; void DelayNOP(uchar i)
; {for(;i!=0;i--)  
	.dbline 26
	rjmp L19
L16:
	.dbline 27
	.dbline 27
	nop
	.dbline 27
L17:
	.dbline 26
	dec R16
L19:
	.dbline 26
	tst R16
	brne L16
	.dbline -2
	.dbline 28
;     { NOP();}
; } 
L15:
	.dbline 0 ; func end
	ret
	.dbsym r i 16 c
	.dbend
	.dbfunc e Convert _Convert fV
;              i -> R22
;              p -> R20,R21
	.even
_Convert::
	rcall push_gset2
	mov R22,R18
	mov R20,R16
	mov R21,R17
	.dbline -1
	.dbline 31
; 
; void Convert(uchar *p,uchar i)
; {p[0]=0;
	.dbline 31
	clr R2
	mov R30,R20
	mov R31,R21
	std z+0,R2
	.dbline 32
;  p[1]=i/100;
	ldi R17,100
	mov R16,R22
	rcall div8u
	mov R30,R20
	mov R31,R21
	std z+1,R16
	.dbline 33
;  p[2]=(i-p[1]*100)/10;
	mov R30,R20
	mov R31,R21
	ldd R17,z+1
	ldi R16,100
	rcall mpy8s
	mov R2,R16
	mov R16,R22
	sub R16,R2
	ldi R17,10
	rcall div8u
	mov R30,R20
	mov R31,R21
	std z+2,R16
	.dbline 34
;  p[3]=i-p[1]*100-p[2]*10;
	mov R30,R20
	mov R31,R21
	ldd R17,z+1
	ldi R16,100
	rcall mpy8s
	mov R2,R22
	sub R2,R16
	mov R30,R20
	mov R31,R21
	ldd R17,z+2
	ldi R16,10
	rcall mpy8s
	sub R2,R16
	mov R30,R20
	mov R31,R21
	std z+3,R2
	.dbline -2
	.dbline 35
; }
L20:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r i 22 c
	.dbsym r p 20 pc
	.dbend
	.dbfunc e Write_Byte _Write_Byte fV
;          clear -> R20
;           Data -> R18
;        Address -> R16
	.even
_Write_Byte::
	rcall push_gset1
	.dbline -1
	.dbline 38
; 
; void Write_Byte(uchar Address,uchar Data)
; {uchar clear;
	.dbline 39
;  PORTB=PORTB|0x10; //使能SPI器件
	sbi 0x18,4
	.dbline 40
;  SPDR=Address;
	out 0xf,R16
L22:
	.dbline 41
	.dbline 41
	.dbline 41
L23:
	.dbline 41
;  while(!(SPSR&0x80)) {;}
	sbis 0xe,7
	rjmp L22
	.dbline 42
;  clear=SPSR;
	in R20,0xe
	.dbline 43
;  clear=SPDR;
	in R20,0xf
	.dbline 44
;  SPDR=Data;
	out 0xf,R18
L25:
	.dbline 45
	.dbline 45
	.dbline 45
L26:
	.dbline 45
;  while(!(SPSR&0x80)) {;}
	sbis 0xe,7
	rjmp L25
	.dbline 46
;  clear=SPSR;
	in R20,0xe
	.dbline 47
;  clear=SPDR;
	in R20,0xf
	.dbline 48
;  PORTB=PORTB&0xef;
	in R24,0x18
	andi R24,239
	out 0x18,R24
	.dbline -2
	.dbline 49
; }
L21:
	rcall pop_gset1
	.dbline 0 ; func end
	ret
	.dbsym r clear 20 c
	.dbsym r Data 18 c
	.dbsym r Address 16 c
	.dbend
	.dbfunc e Read_Byte _Read_Byte fc
;           Data -> R20
;          clear -> R22
;        Address -> R16
	.even
_Read_Byte::
	rcall push_gset2
	.dbline -1
	.dbline 52
;  
; uchar Read_Byte(uchar Address)
; {uchar clear;
	.dbline 54
;  uchar Data;
;  PORTB=PORTB|0x10;
	sbi 0x18,4
	.dbline 55
;  SPDR=Address;
	out 0xf,R16
L29:
	.dbline 56
	.dbline 56
	.dbline 56
L30:
	.dbline 56
;  while(!(SPSR&0x80)) {;}
	sbis 0xe,7
	rjmp L29
	.dbline 57
;  clear=SPSR;
	in R22,0xe
	.dbline 58
;  clear=SPDR;
	in R22,0xf
	.dbline 59
;  SPDR=Address;//发空数据
	out 0xf,R16
L32:
	.dbline 60
	.dbline 60
	.dbline 60
L33:
	.dbline 60
;  while(!(SPSR&0x80)) {;}
	sbis 0xe,7
	rjmp L32
	.dbline 61
;  clear=SPSR;
	in R22,0xe
	.dbline 62
;  Data=SPDR;
	in R20,0xf
	.dbline 63
;  PORTB=PORTB&0xef;
	in R24,0x18
	andi R24,239
	out 0x18,R24
	.dbline 64
;  return(Data);
	mov R16,R20
	.dbline -2
L28:
	rcall pop_gset2
	.dbline 0 ; func end
	ret
	.dbsym r Data 20 c
	.dbsym r clear 22 c
	.dbsym r Address 16 c
	.dbend
	.dbfunc e main _main fV
;          value -> R20
	.even
_main::
	.dbline -1
	.dbline 68
; }
; 
; void main(void)
; {uchar value;
	.dbline 69
;  DDRA=0xff;
	ldi R24,255
	out 0x1a,R24
	.dbline 70
;  DDRC=0xff;
	out 0x14,R24
	.dbline 71
;  DDRB=0xbf;
	ldi R24,191
	out 0x17,R24
	.dbline 72
;  PORTA=0xff;
	ldi R24,255
	out 0x1b,R24
	.dbline 73
;  PORTC=0x00;
	clr R2
	out 0x15,R2
	.dbline 74
;  DelayMs(3000);
	ldi R16,3000
	ldi R17,11
	rcall _DelayMs
	.dbline 75
;  PORTC=0xff;
	ldi R24,255
	out 0x15,R24
	.dbline 76
;  SPCR=0x5c;//0101 1100
	ldi R24,92
	out 0xd,R24
	.dbline 77
;  Write_Byte(0x80,0xf0);//8位,自由转换模式
	ldi R18,240
	ldi R16,128
	rcall _Write_Byte
	rjmp L37
L36:
	.dbline 79
	.dbline 79
	ldi R16,1
	rcall _Read_Byte
	.dbline 80
	ldi R16,2
	rcall _Read_Byte
	mov R20,R16
	.dbline 81
	mov R18,R20
	ldi R16,<_Data
	ldi R17,>_Data
	rcall _Convert
	.dbline 82
	ldi R16,<_Data
	ldi R17,>_Data
	rcall _Display
	.dbline 82
L37:
	.dbline 78
	rjmp L36
X1:
	.dbline -2
	.dbline 83
;  while(1)
;   {value=Read_Byte(0x01);
;    value=Read_Byte(0x02);
;    Convert(Data,value);
;    Display(Data);}
; }
L35:
	.dbline 0 ; func end
	ret
	.dbsym r value 20 c
	.dbend

⌨️ 快捷键说明

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