📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\zhuji\桌面\新建文件夹\spi主\main.c
.dbfunc e SPIMasterInit _SPIMasterInit fV
.even
_SPIMasterInit::
.dbline -1
.dbline 48
; #include "iom16v.h"
; #include "macros.h"
; #define uchar unsigned char
; #define uint unsigned int
; //串口波特率9600
; /*void uart0_init(void)
; {
; UCSRB = 0x00; //disable while setting baud rate
; UCSRA = 0x00;
; UCSRC = BIT(URSEL) | 0x06;
; UBRRL = 0x0C; //set baud rate lo
; UBRRH = 0x00; //set baud rate hi
; UCSRB = 0x98;
; }*//*
; void uart0_init(void)
; {
; UCSRB = 0x00; //disable while setting baud rate
; UCSRA = 0x00;
; UCSRC = 0x0B;//
; UBRRL = 0x2F; //set baud rate lo
; UBRRH = 0x00; //set baud rate hi fosc=7372800HZ,Baud=115200
; UCSRB = (1<<RXCIE)|(1<<TXCIE)|(1<<RXEN)|(1<<TXEN);//0xD8;//发送接受使能 中断使能
; }
; uchar RecvFlag = 0;
; uchar RecvData = 0;
;
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
; RecvFlag = 1;
; RecvData = UDR;
; while(!(UCSRA&0x20));
; UDR = RecvData;
; }*/
; #define DDR_MISO 6
; #define DDR_MOSI 5
; #define DDR_SCK 7
; #define DDR_SS 4
; #define DDR_SPI DDRB
; #define PORT_SPI PORTB
; /*-----------------------------------------------------------------
; 函数名称: void SPIMasterInit(void)
; 函数功能: SPI主机初始化
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void SPIMasterInit(void)
; {
.dbline 49
; DDR_SPI |= (1<<DDR_SCK)|(1<<DDR_MOSI);//输出
in R24,0x17
ori R24,160
out 0x17,R24
.dbline 50
; DDR_SPI &=~(1<<DDR_MISO);//输入
cbi 0x17,6
.dbline 51
; SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);//|(1<<CPOL)|(1<<CPHA)
ldi R24,83
out 0xd,R24
.dbline -2
.dbline 52
; }
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e SPIMasterTransmit _SPIMasterTransmit fV
; TranData -> R16
.even
_SPIMasterTransmit::
.dbline -1
.dbline 60
; /*-----------------------------------------------------------------
; 函数名称: void SPIMasterTransmit(unsigned char i)
; 函数功能: SPI数据发送
; 参 数:
; 返 回 值: 无
; -----------------------------------------------------------------*/
; void SPIMasterTransmit(uchar TranData)
; {
.dbline 61
; SPDR = TranData; // 启动数据传输
out 0xf,R16
L3:
.dbline 62
L4:
.dbline 62
; while (!(SPSR & (1<<SPIF))); // 等待传输结束
sbis 0xe,7
rjmp L3
.dbline -2
.dbline 63
; }
L2:
.dbline 0 ; func end
ret
.dbsym r TranData 16 c
.dbend
.dbfunc e DeviceInit _DeviceInit fV
.even
_DeviceInit::
.dbline -1
.dbline 65
; void DeviceInit(void)
; {
.dbline 66
; CLI();
cli
.dbline 68
; //uart0_init();
; SPIMasterInit();
xcall _SPIMasterInit
.dbline 70
;
; MCUCR = 0;
clr R2
out 0x35,R2
.dbline 71
; TIMSK = 0;
out 0x39,R2
.dbline 72
; GICR = 0;
out 0x3b,R2
.dbline 73
; SEI();
sei
.dbline -2
.dbline 74
; }
L6:
.dbline 0 ; func end
ret
.dbend
.dbfunc e delay _delay fV
; num -> R16,R17
.even
_delay::
.dbline -1
.dbline 76
; void delay(int num )
; {
L8:
.dbline 77
L9:
.dbline 77
; while(num--);
movw R2,R16
subi R16,1
sbci R17,0
tst R2
brne L8
tst R3
brne L8
X0:
.dbline -2
.dbline 78
; }
L7:
.dbline 0 ; func end
ret
.dbsym r num 16 I
.dbend
.dbfunc e main _main fV
.even
_main::
.dbline -1
.dbline 80
; void main(void)
; {
.dbline 81
; PORT_SPI &=~(1<<DDR_SS);
cbi 0x18,4
.dbline 82
; DDR_SPI |= (1<<DDR_SS);
sbi 0x17,4
.dbline 83
; DeviceInit();
xcall _DeviceInit
.dbline 85
;
; SPIMasterTransmit(0x05);
ldi R16,5
xcall _SPIMasterTransmit
.dbline 87
;
; SPIMasterTransmit(0x32);
ldi R16,50
xcall _SPIMasterTransmit
L12:
.dbline 89
.dbline 99
L13:
.dbline 88
xjmp L12
X1:
.dbline -2
.dbline 100
; while(1)
; {
;
;
;
;
; /*if(RecvFlag)
; {
; RecvFlag = 0;
; SPIMasterTransmit(RecvData);
; }*/
; }
; }
L11:
.dbline 0 ; func end
ret
.dbend
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -