📄 can18b20.s
字号:
.module can18b20.c
.area data(ram, con, rel)
_flag::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.dbsym e flag _flag c
_table::
.blkb 2
.area idata
.byte 63,6
.area data(ram, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.blkb 2
.area idata
.byte 91,'O
.area data(ram, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.blkb 2
.area idata
.byte 'f,'m
.area data(ram, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.blkb 2
.area idata
.byte 125,7
.area data(ram, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.blkb 2
.area idata
.byte 127,'o
.area data(ram, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.dbsym e table _table A[10:10]c
.area text(rom, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.dbfunc e init_SPI _init_SPI fV
.even
_init_SPI::
.dbline -1
.dbline 48
; #include <iom8v.h>
; #include <macros.h>
; #include "mcp2515.h"
;
; #define fosc 7372800 //晶振7.3728MHZ
;
; #define DQ (1<<5) //DQ接PC5
;
; #define S_CS PORTC|=0x02 //PC1片选线
; #define C_CS PORTC&=(~0x02)
;
; #define S_CLK PORTC|=0x01 //PC0时钟线
; #define C_CLK PORTC&=(~0x01)
;
; #define S_DATA PORTC|=0x04 //PC2数据
; #define C_DATA PORTC&=(~0x04)
; /**************************** Definitionen ***********************************/
; void init_SPI (void);
; void reset_MCP (void);
; void write_MCP (unsigned char adress, unsigned char value);
; unsigned char read_MCP(unsigned char adress);
; void fill_msg_box_0(void);
; void send_box_0 (void);
; void wait(unsigned int n);
; void init_can(void);
; void bit_modify(unsigned char adress,unsigned char cc, unsigned char value);
; void delay_1ms(void);
; void HC595_SENDDAT(char dat);
; void delay(unsigned int n);
; unsigned char crccheck(unsigned char *p,unsigned char len);
; void delay_us(unsigned int time);
; unsigned char ds1820_ack(void);
; unsigned char read_byte(void);
; void write_byte(unsigned char value);
; //unsigned char Read_Temperature(unsigned int *temperature);
; //unsigned char Read_RomCode(unsigned char *temp);
; //void ds1820_match(unsigned char *p);
; unsigned int count; //CAN发送间隔
; unsigned char wendu,shi,ge;
; unsigned char dot1;
; unsigned char minus_flag;
; unsigned char flag=0; //初始化,个位显示
; //0-9
; unsigned char table[10]={0x3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
; /**************************** Hauptprogramm **********************************/
; /*SPI初始化*/
; void init_SPI (void)
; {
.dbline 50
; //HW_SPI=0x00; // PortB ist HW_SPI
; DDR_SPI|=0x2D; // CS\MOSI\SCK output MISO input
in R24,0x17
ori R24,45
out 0x17,R24
.dbline 51
; SPCR=0x51; // SPI Controll Register set,Fosc/16
ldi R24,81
out 0xd,R24
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e reset_MCP _reset_MCP fV
; i -> <dead>
.even
_reset_MCP::
.dbline -1
.dbline 55
; }
; /*MCP2515复位*/
; void reset_MCP (void)
; { unsigned char i;
.dbline 56
; PORTB&=~(1<<CS_CAN); // CS Low -> MCP enable
cbi 0x18,2
.dbline 57
; SPDR=RESET_MCP; // sende Reset Kommando
ldi R24,192
out 0xf,R24
L3:
.dbline 58
L4:
.dbline 58
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L3
.dbline 59
; PORTB|=(1<<CS_CAN); // CS High -> MCP disable
sbi 0x18,2
.dbline 60
; wait(1000); // waiting?
ldi R16,1000
ldi R17,3
rcall _wait
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym l i 1 c
.dbend
.dbfunc e send_box_0 _send_box_0 fV
.even
_send_box_0::
.dbline -1
.dbline 64
; }
; /*CAN发送请求*/
; void send_box_0 (void)
; {
.dbline 65
; write_MCP (TXB0CTRL, 0x0B); // sende Telegramm mit h鯿hster Priorit鋞
ldi R18,11
ldi R16,48
rcall _write_MCP
.dbline 66
; PORTB&=~(1<<CS_CAN); // CS Low -> MCP enable
cbi 0x18,2
.dbline 67
; SPDR=(RTS | 0x01); // sende Mailbox Nummer 0
ldi R24,129
out 0xf,R24
L7:
.dbline 68
L8:
.dbline 68
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L7
.dbline 69
; PORTB|=(1<<CS_CAN); // CS High -> MCP disable
sbi 0x18,2
.dbline -2
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e write_MCP _write_MCP fV
; value -> R18
; adress -> R16
.even
_write_MCP::
.dbline -1
.dbline 73
; }
; /*MCP2515写操作*/
; void write_MCP (unsigned char adress, unsigned char value)
; {
.dbline 74
; PORTB&=~(1<<CS_CAN); // CS Low -> MCP enable
cbi 0x18,2
.dbline 75
; SPDR=0x02; // sende Write Kommando
ldi R24,2
out 0xf,R24
L11:
.dbline 76
L12:
.dbline 76
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L11
.dbline 77
; SPDR=adress; // Addresse senden
out 0xf,R16
L14:
.dbline 78
L15:
.dbline 78
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L14
.dbline 79
; SPDR=value; // Wert senden
out 0xf,R18
L17:
.dbline 80
L18:
.dbline 80
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L17
.dbline 81
; PORTB|=(1<<CS_CAN); // CS High -> MCP disable
sbi 0x18,2
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbsym r value 18 c
.dbsym r adress 16 c
.dbend
.dbfunc e read_MCP _read_MCP fc
; spidata -> R20
; adress -> R16
.even
_read_MCP::
rcall push_gset1
.dbline -1
.dbline 85
; }
; /*MCP2515读操作*/
; unsigned char read_MCP(unsigned char adress)
; {
.dbline 88
; unsigned char spidata;
;
; PORTB&=~(1<<CS_CAN); // CS Low -> MCP enable
cbi 0x18,2
.dbline 89
; SPDR=0x03; // sende Read Kommando
ldi R24,3
out 0xf,R24
L21:
.dbline 90
L22:
.dbline 90
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L21
.dbline 91
; SPDR=adress; // Adresse von der gelesen werden soll
out 0xf,R16
L24:
.dbline 92
L25:
.dbline 92
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L24
.dbline 93
; SPDR=0xAA; // Dummy-Byte senden
ldi R24,170
out 0xf,R24
L27:
.dbline 94
L28:
.dbline 94
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L27
.dbline 95
; spidata = SPDR; // Daten aus SPI abholen
in R20,0xf
.dbline 96
; PORTB|=(1<<CS_CAN); // CS High -> MCP disable
sbi 0x18,2
.dbline 97
; return (spidata);
mov R16,R20
.dbline -2
L20:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r spidata 20 c
.dbsym r adress 16 c
.dbend
.dbfunc e bit_modify _bit_modify fV
; value -> R20
; cc -> R18
; adress -> R16
.even
_bit_modify::
rcall push_gset1
ldd R20,y+2
.dbline -1
.dbline 101
; }
; /*位修改*/
; void bit_modify(unsigned char adress,unsigned char cc, unsigned char value)
; { PORTB&=~(1<<CS_CAN); // CS Low -> MCP enable
.dbline 101
cbi 0x18,2
.dbline 103
;
; SPDR=0x05; // bit modify Write Kommando
ldi R24,5
out 0xf,R24
L31:
.dbline 104
L32:
.dbline 104
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L31
.dbline 105
; SPDR=adress; // sende Write Kommando
out 0xf,R16
L34:
.dbline 106
L35:
.dbline 106
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L34
.dbline 107
; SPDR=cc; // sende Write Kommando
out 0xf,R18
L37:
.dbline 108
L38:
.dbline 108
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L37
.dbline 109
; SPDR=value; // sende Write Kommando
out 0xf,R20
L40:
.dbline 110
L41:
.dbline 110
; while(!(SPSR & (1<<SPIF))); // warten bis das Byte gesendet wurde
sbis 0xe,7
rjmp L40
.dbline 112
;
; PORTB|=(1<<CS_CAN); // CS High -> MCP disable
sbi 0x18,2
.dbline -2
L30:
rcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r value 20 c
.dbsym r cc 18 c
.dbsym r adress 16 c
.dbend
.dbfunc e fill_msg_box_0 _fill_msg_box_0 fV
.even
_fill_msg_box_0::
.dbline -1
.dbline 116
; }
; /*填充CAN信息*/
; void fill_msg_box_0(void)
; {
.dbline 117
; write_MCP(TXB0SIDH, (unsigned char) (0x261 >> 3)); // ID = 0x26a
ldi R18,76
ldi R16,49
rcall _write_MCP
.dbline 118
; write_MCP(TXB0SIDL, (unsigned char) (0x261 << 5)); ////需要修改
ldi R18,32
ldi R16,50
rcall _write_MCP
.dbline 119
; write_MCP (TXB0DLC, 0x02); // 1 Bytes
ldi R18,2
ldi R16,53
rcall _write_MCP
.dbline 120
; write_MCP (TXB0D0, wendu);
lds R18,_wendu
ldi R16,54
rcall _write_MCP
.dbline 121
; write_MCP (TXB0D1, dot1);
lds R18,_dot1
ldi R16,55
rcall _write_MCP
.dbline -2
L43:
.dbline 0 ; func end
ret
.dbend
.dbfunc e init_can _init_can fV
.even
_init_can::
.dbline -1
.dbline 126
;
; }
; /*CAN初始化*/
; void init_can(void)
; { write_MCP (CANCTRL, 0x80); //0x80, set mode
.dbline 126
ldi R18,128
ldi R16,15
rcall _write_MCP
.dbline 128
; //TX
; write_MCP (CNF1, 0x03); // Set CAN-Baudrate 125 kBaud
ldi R18,3
ldi R16,42
rcall _write_MCP
.dbline 129
; write_MCP (CNF2, 0xB8); // 16MHz
ldi R18,184
ldi R16,41
rcall _write_MCP
.dbline 130
; write_MCP (CNF3, 0x05); // des MCP2510 bzw. MCP2515
ldi R18,5
ldi R16,40
rcall _write_MCP
.dbline 133
;
; //RX
; write_MCP (RXB0CTRL, 0x20); // receive stand message
ldi R18,32
ldi R16,96
rcall _write_MCP
.dbline 134
; write_MCP (RXM0SIDH, 0xFF); // 屏蔽寄存器高8位,11位都要校验
ldi R18,255
ldi R16,32
rcall _write_MCP
.dbline 135
; write_MCP (RXM0SIDL, 0xE0); // 屏蔽寄存器低3位
ldi R18,224
ldi R16,33
rcall _write_MCP
.dbline 136
; write_MCP (RXF0SIDH, 0x4C); //接收报文ID为:0x260的报文(上位机 cansap)
ldi R18,76
clr R16
rcall _write_MCP
.dbline 137
; write_MCP (RXF0SIDL, 0x00);
clr R18
ldi R16,1
rcall _write_MCP
.dbline 139
;
; write_MCP (CANINTE, 0x25); //enable interrupt
ldi R18,37
ldi R16,43
rcall _write_MCP
.dbline 140
; write_MCP (CANCTRL, 0x00); // Set CLK-Out disable,0x80 set mode,0x40 shou fa ,0x00 normal mode,
clr R18
ldi R16,15
rcall _write_MCP
.dbline 141
; asm("nop");
nop
.dbline -2
L44:
.dbline 0 ; func end
ret
.dbend
.area vector(rom, abs)
.org 2
rjmp _int0_isr
.area text(rom, con, rel)
.dbfile F:\can-18b20(无浮点再调试)\can18b20.c
.dbfunc e int0_isr _int0_isr fV
; err -> <dead>
; i -> R20
.even
_int0_isr::
rcall push_lset
rcall push_gset1
sbiw R28,1
.dbline -1
.dbline 146
; }
; /*CAN中断*/
; #pragma interrupt_handler int0_isr:2
; void int0_isr(void)
; { unsigned char i,err;
.dbline 148
; //unsigned int canid;
; i = read_MCP (CANINTF);
ldi R16,44
rcall _read_MCP
mov R20,R16
.dbline 149
; if((i&0x04)==0x04) //TX0 空
mov R24,R20
andi R24,4
cpi R24,4
brne L46
.dbline 150
; { minus_flag=0; //负温度标志清0
.dbline 150
clr R2
sts _minus_flag,R2
.dbline 152
;
; bit_modify(CANINTF, 0x04,0x00); //清除TX0IF标志
std y+0,R2
ldi R18,4
ldi R16,44
rcall _bit_modify
.dbline 153
; }
L46:
.dbline 154
; if((i&0x20)==0x20) // 出错
mov R24,R20
andi R24,32
cpi R24,32
brne L48
.dbline 155
; {//err = read_MCP (EFLG);
.dbline 156
; reset_MCP();
rcall _reset_MCP
.dbline 157
; init_can();
rcall _init_can
.dbline 159
; //fill_msg_box_0();
; bit_modify(CANINTF, 0x20,0x00); //清除ERRIF标志
clr R2
std y+0,R2
ldi R18,32
ldi R16,44
rcall _bit_modify
.dbline 160
; }
L48:
.dbline 161
mov R24,R20
andi R24,1
cpi R24,1
brne L50
.dbline 162
.dbline 166
clr R2
std y+0,R2
ldi R18,1
ldi R16,44
rcall _bit_modify
.dbline 168
L50:
.dbline -2
L45:
adiw R28,1
rcall pop_gset1
rcall pop_lset
.dbline 0 ; func end
reti
.dbsym l err 2 c
.dbsym r i 20 c
.dbend
.dbfunc e crccheck _crccheck fc
; j -> R20
; r -> R14
; cbit -> y+0
; bit0 -> R8
; byte -> R10
; i -> R12
; temp -> R22
; len -> R6
; p -> R4,R5
.even
_crccheck::
rcall push_gset5
mov R6,R18
movw R4,R16
sbiw R28,1
.dbline -1
.dbline 180
; if((i&0x01)==0x01) //RX0接收满
; {//str[0] = read_MCP (0x61);
; //str[1] = read_MCP (0x62);
; //str[2] = read_MCP (0x65);
; //str[3] = read_MCP (0x66);
; bit_modify(CANINTF, 0x01,0x00); //清除RX0IF标志
;
; }
;
; }
;
; /*===================================================================
; // 函数功能: DS18B20数据校验函数
; // 形参: void
; // 返回: unsigned char 校验结果
; // 编写: 2004/8/25
; // 备注: CRC公式为:CRC = X^8 + X^5 + X^4 + 1
; ===================================================================*/
; unsigned char crccheck(unsigned char *p,unsigned char len)
; {
.dbline 182
; unsigned char bit0,cbit,r,temp,i,j,byte;
; temp = 0;
clr R22
.dbline 183
; for(j = 0; j < len; j++)
clr R20
rjmp L56
L53:
.dbline 184
; {
.dbline 185
; byte = p[j];
mov R30,R20
clr R31
add R30,R4
adc R31,R5
ldd R10,z+0
.dbline 186
; for(i = 0; i < 8; i++)
clr R12
rjmp L60
L57:
.dbline 187
; {
.dbline 188
; cbit = temp & 0x01;
mov R24,R22
andi R24,1
std y+0,R24
.dbline 189
; bit0 = byte&0x01;
mov R24,R10
andi R24,1
mov R8,R24
.dbline 190
; temp >>= 1;
lsr R22
.dbline 191
; r = cbit ^ bit0;
ldd R14,y+0
eor R14,R24
.dbline 192
; if(r == 1)
mov R24,R14
cpi R24,1
brne L61
.dbline 193
; temp ^= 0x8c;
ldi R24,140
ldi R25,0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -