📄 main.s
字号:
.module main.c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 21
; //ICC-AVR application builder : 2009-2-18 11:55:58
; // Target : M16
; // Crystal: 8.0000Mhz
;
; #include <iom16v.h>
; #include <macros.h>
; #define mclk 8000000
;
;
;
;
;
; //=============================================================
; // 函数名: void port_init(void)
; // 功能: 端口初始化,所有端口都变为高阻态
; // 参数: none
; // 返回值: none
; // 使用方法:port_init();
; //=============================================================
; void port_init(void)
; {
.dbline 22
; DDRA = 0x00;
clr R2
out 0x1a,R2
.dbline 23
; PORTA = 0x00;
out 0x1b,R2
.dbline 24
; DDRB = 0x00;
out 0x17,R2
.dbline 25
; PORTB = 0x00;
out 0x18,R2
.dbline 26
; DDRC = 0x00;
out 0x14,R2
.dbline 27
; PORTC = 0x00;
out 0x15,R2
.dbline 28
; DDRD = 0x00;
out 0x11,R2
.dbline 29
; PORTD = 0x00;
out 0x12,R2
.dbline -2
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e motor_a _motor_a fV
; speed -> R18,R19
; fx -> R16
.even
_motor_a::
.dbline -1
.dbline 44
; }
;
;
; //////////////////////////////////////////////////////////////////////////////////////////////////////
;
;
; //=============================================================
; // 函数名: void motor_a(unsigned char fx,int speed)
; // 功能: 控制电机A的旋转方向以及转速
; // 参数: unsigned char fx,int speed fx为0或者1,speed为0-1023
; // 返回值: none
; // 使用方法:motor_a(0,1000);
; //=============================================================
; void motor_a(unsigned char fx,int speed)
; {
.dbline 45
; if(fx)
tst R16
breq L3
.dbline 46
; {
.dbline 47
; PORTB |= BIT(2);
sbi 0x18,2
.dbline 48
; PORTB &= ~BIT(0);
cbi 0x18,0
.dbline 49
; }
xjmp L4
L3:
.dbline 51
; else
; {
.dbline 52
; PORTB |= BIT(0);
sbi 0x18,0
.dbline 53
; PORTB &= ~BIT(2);
cbi 0x18,2
.dbline 54
; }
L4:
.dbline 55
; OCR1A = speed;
out 0x2b,R19
out 0x2a,R18
.dbline -2
L2:
.dbline 0 ; func end
ret
.dbsym r speed 18 I
.dbsym r fx 16 c
.dbend
.dbfunc e motor_b _motor_b fV
; speed -> R18,R19
; fx -> R16
.even
_motor_b::
.dbline -1
.dbline 66
; }
;
; //=============================================================
; // 函数名: void motor_b(unsigned char fx,int speed)
; // 功能: 控制电机A的旋转方向以及转速
; // 参数: unsigned char fx,int speed fx为0或者1,speed为0-1023
; // 返回值: none
; // 使用方法:motor_b(0,1000);
; //=============================================================
; void motor_b(unsigned char fx,int speed)
; {
.dbline 67
; if(fx)
tst R16
breq L6
.dbline 68
; {
.dbline 69
; PORTB |= BIT(4);
sbi 0x18,4
.dbline 70
; PORTB &= ~BIT(1);
cbi 0x18,1
.dbline 71
; }
xjmp L7
L6:
.dbline 73
; else
; {
.dbline 74
; PORTB |= BIT(1);
sbi 0x18,1
.dbline 75
; PORTB &= ~BIT(4);
cbi 0x18,4
.dbline 76
; }
L7:
.dbline 77
; OCR1B = speed;
out 0x29,R19
out 0x28,R18
.dbline -2
L5:
.dbline 0 ; func end
ret
.dbsym r speed 18 I
.dbsym r fx 16 c
.dbend
.dbfunc e motor_init _motor_init fV
.even
_motor_init::
.dbline -1
.dbline 87
; }
; //=============================================================
; // 函数名: void motor_init(void)
; // 功能: 电机控制初始化
; // 参数: none
; // 返回值: none
; // 使用方法:motor_init();
; //=============================================================
; void motor_init(void)
; {
.dbline 88
; DDRB |= 0x17;
in R24,0x17
ori R24,23
out 0x17,R24
.dbline 89
; PORTB &= ~0x03;
in R24,0x18
andi R24,252
out 0x18,R24
.dbline 90
; PORTB |= 0x14;
in R24,0x18
ori R24,20
out 0x18,R24
.dbline 91
; DDRD |= 0x30;
in R24,0x11
ori R24,48
out 0x11,R24
.dbline 92
; PORTD |= 0x30;
in R24,0x12
ori R24,48
out 0x12,R24
.dbline 93
; TCCR1A = 0xA3;
ldi R24,163
out 0x2f,R24
.dbline 94
; TCCR1B = 0x0A;
ldi R24,10
out 0x2e,R24
.dbline 95
; OCR1A = 0;
clr R2
clr R3
out 0x2b,R3
out 0x2a,R2
.dbline 96
; OCR1B = 0;
out 0x29,R3
out 0x28,R2
.dbline -2
L8:
.dbline 0 ; func end
ret
.dbend
.dbfunc e uart_init _uart_init fV
; baud -> R10,R11
.even
_uart_init::
xcall push_gset3
movw R10,R16
.dbline -1
.dbline 111
; }
;
;
; ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
;
;
; //=============================================================
; // 函数名:void uart_init(unsigned int baud)
; // 功能: 异步串行通信初始化
; // 参数: unsigned int baud 设置通信波特率
; // 返回值: none
; // 使用方法:uart_init(19200);
; //=============================================================
; void uart_init(unsigned int baud)
; {
.dbline 112
; UCSRB=0x00;
clr R2
out 0xa,R2
.dbline 113
; UCSRA=0x00; //控制寄存器清零
out 0xb,R2
.dbline 114
; UCSRC=(1<<URSEL)|(0<<UPM0)|(3<<UCSZ0); //选择UCSRC,异步模式,禁止校验,1位停止位,8位数据位
ldi R24,134
out 0x20,R24
.dbline 115
; baud=mclk/16/baud-1 ; //波特率最大为65K
movw R2,R10
clr R4
clr R5
ldi R20,32
ldi R21,161
ldi R22,7
ldi R23,0
st -y,R5
st -y,R4
st -y,R3
st -y,R2
movw R16,R20
movw R18,R22
xcall div32s
ldi R20,1
ldi R21,0
ldi R22,0
ldi R23,0
movw R2,R16
movw R4,R18
sub R2,R20
sbc R3,R21
sbc R4,R22
sbc R5,R23
movw R10,R2
.dbline 116
; UBRRL=baud;
out 0x9,R2
.dbline 117
; UBRRH=baud>>8; //设置波特率
mov R2,R3
clr R3
out 0x20,R2
.dbline 118
; UCSRB=(1<<TXEN)|(1<<RXEN)|(1<<RXCIE); //接收、发送使能,接收中断使能
ldi R24,152
out 0xa,R24
.dbline 119
; DDRD|=0X02; //配置TX为输出(很重要)
sbi 0x11,1
.dbline -2
L9:
xcall pop_gset3
.dbline 0 ; func end
ret
.dbsym r baud 10 i
.dbend
.dbfunc e uart_sendB _uart_sendB fV
; data -> R16
.even
_uart_sendB::
.dbline -1
.dbline 129
; }
; //=============================================================
; // 函数名:void uart_sendB(unsigned char data)
; // 功能: 串口发送一个字节
; // 参数: unsigned char data 写入要发送的数据
; // 返回值: none
; // 使用方法:uart_sendB('a');
; //=============================================================
; void uart_sendB(unsigned char data)
; {
L11:
.dbline 130
L12:
.dbline 130
; while(!(UCSRA&(BIT(UDRE)))) ;
sbis 0xb,5
rjmp L11
.dbline 131
; UDR=data;
out 0xc,R16
L14:
.dbline 132
L15:
.dbline 132
; while(!(UCSRA&(BIT(TXC))));
sbis 0xb,6
rjmp L14
.dbline 133
; UCSRA|=BIT(TXC);
sbi 0xb,6
.dbline -2
L10:
.dbline 0 ; func end
ret
.dbsym r data 16 c
.dbend
.dbfunc e uart_send _uart_send fV
; d -> y+0
; data -> R20,R21
.even
_uart_send::
xcall push_gset1
movw R20,R16
sbiw R28,4
.dbline -1
.dbline 143
; }
; //=============================================================
; // 函数名:void uart_send(int data)
; // 功能: 串口发送一个4位10进制数
; // 参数: int data 写入要发送的数据
; // 返回值: none
; // 使用方法:uart_sendB(1234);
; //=============================================================
; void uart_send(int data)
; {
.dbline 145
; unsigned char d[4];
; d[3]=data/1000;
ldi R18,1000
ldi R19,3
movw R16,R20
xcall div16s
std y+3,R16
.dbline 146
; data=data%1000;
ldi R18,1000
ldi R19,3
movw R16,R20
xcall mod16s
movw R20,R16
.dbline 147
; d[2]=data/100;
ldi R18,100
ldi R19,0
xcall div16s
std y+2,R16
.dbline 148
; data=data%100;
ldi R18,100
ldi R19,0
movw R16,R20
xcall mod16s
movw R20,R16
.dbline 149
; d[1]=data/10;
ldi R18,10
ldi R19,0
xcall div16s
std y+1,R16
.dbline 150
; d[0]=data%10;
ldi R18,10
ldi R19,0
movw R16,R20
xcall mod16s
std y+0,R16
.dbline 151
; uart_sendB(d[3]+'0');
ldd R16,y+3
subi R16,208 ; addi 48
xcall _uart_sendB
.dbline 152
; uart_sendB(d[2]+'0');
ldd R16,y+2
subi R16,208 ; addi 48
xcall _uart_sendB
.dbline 153
; uart_sendB(d[1]+'0');
ldd R16,y+1
subi R16,208 ; addi 48
xcall _uart_sendB
.dbline 154
; uart_sendB(d[0]+'0');
ldd R16,y+0
subi R16,208 ; addi 48
xcall _uart_sendB
.dbline 155
; uart_sendB(';');
ldi R16,59
xcall _uart_sendB
.dbline -2
L17:
adiw R28,4
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym l d 0 A[4:4]c
.dbsym r data 20 I
.dbend
.dbfunc e uart_senddata _uart_senddata fV
; ptr -> R20,R21
; data -> R22,R23
.even
_uart_senddata::
xcall push_gset2
movw R22,R16
.dbline -1
.dbline 165
; }
; //=============================================================
; // 函数名:void uart_senddata(unsigned char *data)
; // 功能: 通过串口发送字符串
; // 参数: unsigned char *data 指针指向要发送的字符串
; // 返回值: none
; // 使用方法:uart_senddata(abc);
; //=============================================================
; void uart_senddata(unsigned char *data)
; {
.dbline 167
; unsigned char *ptr;
; ptr = data;
movw R20,R22
xjmp L26
L25:
.dbline 169
.dbline 170
movw R30,R20
ldd R16,z+0
xcall _uart_sendB
.dbline 171
subi R20,255 ; offset = 1
sbci R21,255
.dbline 172
L26:
.dbline 168
; while(*ptr)
movw R30,R20
ldd R2,z+0
tst R2
brne L25
.dbline -2
L24:
xcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r ptr 20 pc
.dbsym r data 22 pc
.dbend
.dbfunc e adc_init _adc_init fV
.even
_adc_init::
.dbline -1
.dbline 187
; {
; uart_sendB(*ptr);
; ptr++;
; }
; }
;
;
; /////////////////////////////////////////////////////////////////////////////////////////////////////////
;
;
; //=============================================================
; // 函数名:void adc_init(void)
; // 功能: Adc0 初始化 内部2.56v比较电压
; // 参数: none
; // 返回值: none
; // 使用方法:adc_init();
; //=============================================================
; void adc_init(void)
; {
.dbline 188
; DDRA&=~BIT(PA0);
cbi 0x1a,0
.dbline 189
; PORTA&=~BIT(PA0);
cbi 0x1b,0
.dbline 190
; ADMUX=0xc0;
ldi R24,192
out 0x7,R24
.dbline 191
; ADCSRA=0X80;
ldi R24,128
out 0x6,R24
.dbline -2
L28:
.dbline 0 ; func end
ret
.dbend
.dbfunc e mega16_ad _mega16_ad fi
; addata -> R20,R21
.even
_mega16_ad::
xcall push_gset1
.dbline -1
.dbline 201
; }
; //=============================================================
; // 函数名:unsigned int mega16_ad(void)
; // 功能: 读取一次ADC0的值
; // 参数: none
; // 返回值: addata
; // 使用方法:add = mega16_ad();
; //=============================================================
; unsigned int mega16_ad(void)
; {
.dbline 203
; unsigned int addata;
; ADCSRA|=BIT(ADSC);
sbi 0x6,6
L30:
.dbline 204
L31:
.dbline 204
; while(!(ADCSRA&(BIT(ADIF))));
sbis 0x6,4
rjmp L30
.dbline 205
; addata=ADCL;
in R20,0x4
clr R21
.dbline 206
; addata=addata+ADCH*256;
in R18,0x5
clr R19
ldi R16,256
ldi R17,1
xcall empy16s
add R20,R16
adc R21,R17
.dbline 207
; return addata;
movw R16,R20
.dbline -2
L29:
xcall pop_gset1
.dbline 0 ; func end
ret
.dbsym r addata 20 i
.dbend
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
_nRF2401_Conf::
.blkb 2
.area idata
.byte 142,8
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 28,16
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 224,0
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 28,204
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 204,204
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 0,204
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 204,204
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 204,'C
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.blkb 2
.area idata
.byte 'O,4
.area data(ram, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.dbsym e nRF2401_Conf _nRF2401_Conf A[18:18]c
.area text(rom, con, rel)
.dbfile C:\DOCUME~1\haolxy\桌面\smartcar\smartcar\main.c
.dbfunc e delay_1us _delay_1us fV
.even
_delay_1us::
.dbline -1
.dbline 381
; }
;
;
;
; ///////////////////////////////////////////////////////////////////////////////////////////////////////
;
; #define BYTE_BIT0 0x01
; #define BYTE_BIT1 0x02
; #define BYTE_BIT2 0x04
; #define BYTE_BIT3 0x08
; #define BYTE_BIT4 0x10
; #define BYTE_BIT5 0x20
; #define BYTE_BIT6 0x40
; #define BYTE_BIT7 0x80
; //<nRF2401_Pins 对应引脚>
; /*sbit PWR_UP = P1^6;
; sbit CE = P1^2;
; //sbit DR2 = P3^5; //暂时没有用到
; //sbit CLK2 = P3^4;
; //sbit OUT2 = P3^3;
; sbit CS = P1^1;
; sbit DR1 = P1^0;
; sbit CLK1 = P3^7;
; sbit DATA = P3^3;
; sbit LED0 = P3^4;
; sbit LED1 = P3^5;
; sbit KEY0 = P3^0;
; sbit KEY1 = P3^1;
; */
; #define NRF_PORT PORTC
; #define NRF_DDR DDRC
; #define NRF_PIN PINC
;
; #define PWR_UP PC0
; #define CE PC1
; #define CS PC4
; #define DR1 PC2
; #define CLK1 PC3
; #define DATA PC5
;
; #define PWR_UP_STATE (NRF_PIN&(1<<PWR_UP))==(1<<PWR_UP)
; #define CE_STATE (NRF_PIN&(1<<CE))==(1<<CE)
; #define CS_STATE (NRF_PIN&(1<<CS))==(1<<CS)
; #define DR1_STATE (NRF_PIN&(1<<DR1))==(1<<DR1)
; #define CLK1_STATE (NRF_PIN&(1<<CLK1))==(1<<CLK1)
; #define DATA_STATE (NRF_PIN&(1<<DATA))==(1<<DATA)
;
; #define PWR_UP_SET() {NRF_PORT|=1<<PWR_UP;}
; #define PWR_UP_CLR() {NRF_PORT&=~(1<<PWR_UP);}
; #define CE_SET() {NRF_PORT|=1<<CE;}
; #define CE_CLR() {NRF_PORT&=~(1<<CE);}
; #define CS_SET() {NRF_PORT|=1<<CS;}
; #define CS_CLR() {NRF_PORT&=~(1<<CS);}
; #define DR1_SET() {NRF_PORT|=1<<DR1;}
; #define DR1_CLR() {NRF_PORT&=~(1<<DR1);}
; #define CLK1_SET() {NRF_PORT|=1<<CLK1;}
; #define CLK1_CLR() {NRF_PORT&=~(1<<CLK1);}
; #define DATA_SET() {NRF_PORT|=1<<DATA;}
; #define DATA_CLR() {NRF_PORT&=~(1<<DATA);}
; /*
; #define LED0_SET() {PORTC|=1<<PC0;DDRC|=1<<PC0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -