📄 thermometer.s
字号:
.module Thermometer.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\Thermometer.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\Thermometer.c
.blkb 2
.area idata
.byte 0,0
.area data(ram, con, rel)
.dbfile J:\AVRpractice\BOOK\SPI\Thermometer.c
.dbsym e Data _Data A[4:4]c
_Temp::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile J:\AVRpractice\BOOK\SPI\Thermometer.c
.dbsym e Temp _Temp c
.area text(rom, con, rel)
.dbfile J:\AVRpractice\BOOK\SPI\Thermometer.c
.dbfunc e DelayMs _DelayMs fV
; j -> R20
; i -> R16,R17
.even
_DelayMs::
rcall push_gset1
.dbline -1
.dbline 15
; #include <io8535v.h>
; #include <macros.h>
; #define uchar unsigned char
; #define uint unsigned int
; //SPI-AVR interface
; //sbit CE=PB^4; 0001 0000 0x10 0xef
; //sbit SCLK=PB^7; 1000 0000 0x80 0x7f
; //sbit SDO=PB^6; 0100 0000 0x40 0xbf
; //sbit SDI=PB^5; 0010 0000 0x20 0xdf
; uchar Table[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
; uchar Data[4]={0,0,0,0};
; uchar Temp=0;
;
; void DelayMs(uint i)
; {uchar j;
.dbline 16
; for(;i!=0;i--)
rjmp L5
L2:
.dbline 17
.dbline 17
ldi R20,100
rjmp L9
L6:
.dbline 17
.dbline 17
.dbline 17
L7:
.dbline 17
dec R20
L9:
.dbline 17
tst R20
brne L6
.dbline 17
L3:
.dbline 16
subi R16,1
sbci R17,0
L5:
.dbline 16
cpi R16,0
cpc R16,R17
brne L2
X0:
.dbline -2
.dbline 18
; {for(j=100;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 21
;
; void Display(uchar *p)
; {uchar i,sel=0x01;
.dbline 21
ldi R20,1
.dbline 22
; for(i=0;i<4;i++)
clr R22
rjmp L14
L11:
.dbline 23
.dbline 23
out 0x1b,R20
.dbline 24
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 25
ldi R16,20
ldi R17,0
rcall _DelayMs
.dbline 26
lsl R20
.dbline 27
L12:
.dbline 22
inc R22
L14:
.dbline 22
cpi R22,4
brlo L11
.dbline -2
.dbline 28
; {PORTA=sel;
; PORTC=0xff-Table[p[i]];
; DelayMs(20);
; 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 SPI_Init _SPI_Init fV
.even
_SPI_Init::
.dbline -1
.dbline 31
;
; void SPI_Init(void)
; {//CE=0;//Disable Chip_Select
.dbline 32
; PORTB=PORTB&0xef;
in R24,0x18
andi R24,239
out 0x18,R24
.dbline 34
; //SCLK=1;//Clock Polarity(CPOL)=1
; PORTB=PORTB|0x80;
sbi 0x18,7
.dbline -2
.dbline 35
; }
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SPI_Process _SPI_Process fV
; i -> R22
; p2 -> R20,R21
; p1 -> R10
.even
_SPI_Process::
rcall push_gset3
mov R20,R18
mov R21,R19
mov R10,R16
.dbline -1
.dbline 38
;
; void SPI_Process(uchar p1,uchar *p2)
; {uchar i;
.dbline 39
; i=p1;
mov R22,R10
.dbline 40
; p2[0]=0;
clr R2
mov R30,R20
mov R31,R21
std z+0,R2
.dbline 41
; p2[1]=i/100;
ldi R17,100
mov R16,R22
rcall div8u
mov R30,R20
mov R31,R21
std z+1,R16
.dbline 42
; p2[2]=(i-i/100*p2[1])/10;
ldi R17,100
mov R16,R22
rcall div8u
mov R30,R20
mov R31,R21
ldd R17,z+1
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 43
; p2[3]=i-p2[1]*100-p2[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 44
; }
L16:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r i 22 c
.dbsym r p2 20 pc
.dbsym r p1 10 c
.dbend
.dbfunc e SPI_Write1Byte _SPI_Write1Byte fV
; i -> R20
; Data -> R22
; Address -> R10
.even
_SPI_Write1Byte::
rcall push_gset3
mov R22,R18
mov R10,R16
.dbline -1
.dbline 47
;
; void SPI_Write1Byte(uchar Address,uchar Data)
; {uchar i;
.dbline 48
; PORTB=PORTB&0xdf;//SDI=0;
in R24,0x18
andi R24,223
out 0x18,R24
.dbline 49
; PORTB=PORTB|0x80;//SCLK=1;//CPOL=1
sbi 0x18,7
.dbline 50
; PORTB=PORTB|0x10;//CE=1;//Enable Chip_Select
sbi 0x18,4
.dbline 51
; for(i=0;i<8;i++) //送地址;
clr R20
rjmp L21
L18:
.dbline 52
; {PORTB=PORTB&0x7f;//SCLK=0;//时钟恢复
.dbline 52
in R24,0x18
andi R24,127
out 0x18,R24
.dbline 53
; if(Address&0x80) PORTB=PORTB|0x20;//SDI=1;//MSB first
sbrs R10,7
rjmp L22
.dbline 53
sbi 0x18,5
rjmp L23
L22:
.dbline 54
; else PORTB=PORTB&0xdf;//SDI=0;
in R24,0x18
andi R24,223
out 0x18,R24
L23:
.dbline 55
lsl R10
.dbline 56
sbi 0x18,7
.dbline 57
ldi R16,1
ldi R17,0
rcall _DelayMs
.dbline 57
L19:
.dbline 51
inc R20
L21:
.dbline 51
cpi R20,8
brlo L18
.dbline 58
; Address=Address<<1;//左移
; PORTB=PORTB|0x80;//SCLK=1;//上升沿完成,锁存
; DelayMs(1);}
; for(i=0;i<8;i++) //送地址;
clr R20
rjmp L27
L24:
.dbline 59
; {PORTB=PORTB&0x7f;//SCLK=0;//时钟恢复
.dbline 59
in R24,0x18
andi R24,127
out 0x18,R24
.dbline 60
; if(Data&0x80) PORTB=PORTB|0x20;//SDI=1;//MSB first
sbrs R22,7
rjmp L28
.dbline 60
sbi 0x18,5
rjmp L29
L28:
.dbline 61
; else PORTB=PORTB&0xdf;//SDI=0;
in R24,0x18
andi R24,223
out 0x18,R24
L29:
.dbline 62
lsl R22
.dbline 63
sbi 0x18,7
.dbline 64
ldi R16,1
ldi R17,0
rcall _DelayMs
.dbline 64
L25:
.dbline 58
inc R20
L27:
.dbline 58
cpi R20,8
brlo L24
.dbline 65
; Data=Data<<1;//左移
; PORTB=PORTB|0x80;//SCLK=1;//上升沿完成,锁存
; DelayMs(1);}
; PORTB=PORTB&0xef;//CE=0;
in R24,0x18
andi R24,239
out 0x18,R24
.dbline -2
.dbline 66
; }
L17:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r i 20 c
.dbsym r Data 22 c
.dbsym r Address 10 c
.dbend
.dbfunc e SPI_Read1Byte _SPI_Read1Byte fc
; temp -> R20
; i -> R22
; Address -> R10
.even
_SPI_Read1Byte::
rcall push_gset3
mov R10,R16
.dbline -1
.dbline 69
;
; uchar SPI_Read1Byte(uchar Address)
; {uchar i,temp;
.dbline 71
; // SDO=1;
; PORTB=PORTB|0x80;//SCLK=1;//CPOL=1
sbi 0x18,7
.dbline 72
; PORTB=PORTB|0x10;//CE=1;//Enable Chip_Select
sbi 0x18,4
.dbline 73
; for(i=0;i<8;i++) //送地址;
clr R22
rjmp L34
L31:
.dbline 74
; {PORTB=PORTB&0x7f;//SCLK=0;//时钟恢复
.dbline 74
in R24,0x18
andi R24,127
out 0x18,R24
.dbline 75
; if(Address&0x80) PORTB=PORTB|0x20;//SDI=1;//MSB first
sbrs R10,7
rjmp L35
.dbline 75
sbi 0x18,5
rjmp L36
L35:
.dbline 76
; else PORTB=PORTB&0xdf;//SDI=0;
in R24,0x18
andi R24,223
out 0x18,R24
L36:
.dbline 77
lsl R10
.dbline 78
sbi 0x18,7
.dbline 79
ldi R16,1
ldi R17,0
rcall _DelayMs
.dbline 79
L32:
.dbline 73
inc R22
L34:
.dbline 73
cpi R22,8
brlo L31
.dbline 80
; Address=Address<<1;//左移
; PORTB=PORTB|0x80;//SCLK=1;//上升沿完成,锁存
; DelayMs(1);}
; for(i=0;i<8;i++)
clr R22
rjmp L40
L37:
.dbline 81
; {PORTB=PORTB&0x7f;//SCLK=0;//提供一个下降沿接收一位数据
.dbline 81
in R24,0x18
andi R24,127
out 0x18,R24
.dbline 82
; temp=temp<<1;
lsl R20
.dbline 83
; NOP();
nop
.dbline 84
; NOP();
nop
.dbline 86
; //if(SDO) temp=temp|0x01;//采样
; if(PINB&0x40) temp=temp|0x01;
sbis 0x16,6
rjmp L41
.dbline 86
ori R20,1
L41:
.dbline 87
sbi 0x18,7
.dbline 88
ldi R16,1
ldi R17,0
rcall _DelayMs
.dbline 88
L38:
.dbline 80
inc R22
L40:
.dbline 80
cpi R22,8
brlo L37
.dbline 89
; PORTB=PORTB|0x80;//SCLK=1;//时钟恢复
; DelayMs(1);}
; PORTB=PORTB&0xef;//CE=0;//Disbale Chip_Select
in R24,0x18
andi R24,239
out 0x18,R24
.dbline 90
; return(temp);
mov R16,R20
.dbline -2
L30:
rcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r temp 20 c
.dbsym r i 22 c
.dbsym r Address 10 c
.dbend
.dbfunc e main _main fV
; Read -> R20
.even
_main::
.dbline -1
.dbline 94
; }
;
; void main(void)
; {uchar Read;
.dbline 95
; DDRA=0xff;
ldi R24,255
out 0x1a,R24
.dbline 96
; DDRC=0xff;
out 0x14,R24
.dbline 97
; DDRB=0xbf;//1011 1111
ldi R24,191
out 0x17,R24
.dbline 98
; SPI_Init();
rcall _SPI_Init
.dbline 99
; SPI_Write1Byte(0x80,0xf0);//1 1 1 1SHOT R2 R1 R0 SD
ldi R18,240
ldi R16,128
rcall _SPI_Write1Byte
rjmp L45
L44:
.dbline 102
.dbline 102
ldi R16,1
rcall _SPI_Read1Byte
mov R20,R16
.dbline 103
ldi R16,2
rcall _SPI_Read1Byte
sts _Temp,R16
.dbline 104
ldi R18,<_Data
ldi R19,>_Data
rcall _SPI_Process
.dbline 105
ldi R16,<_Data
ldi R17,>_Data
rcall _Display
.dbline 106
L45:
.dbline 101
rjmp L44
X1:
.dbline -2
.dbline 107
; //1 1 1 1 0 0 0 0//SD=0 indicate continuous convertion
; while(1)
; {Read=SPI_Read1Byte(0x01);//Low Byte
; Temp=SPI_Read1Byte(0x02);//Hign Byte
; SPI_Process(Temp,Data);
; Display(Data);
; }
; }
L43:
.dbline 0 ; func end
ret
.dbsym r Read 20 c
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -