📄 twimain.s
字号:
.module twimain.c
.area vector(rom, abs)
.org 34
rjmp _twi_isr
.area data(ram, con, rel)
_receive_data::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e receive_data _receive_data c
_error_state::
.blkb 1
.area idata
.byte 0
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e error_state _error_state c
_slave_address::
.blkb 1
.area idata
.byte 160
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e slave_address _slave_address c
_bit_race::
.blkb 1
.area idata
.byte 32
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e bit_race _bit_race c
_send_data::
.blkb 1
.area idata
.byte 2
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e send_data _send_data c
_trandata::
.blkb 2
.area idata
.byte 0,1
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.blkb 2
.area idata
.byte 2,3
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e trandata _trandata A[4:4]c
_RC0::
.blkb 1
.area idata
.byte 76
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e RC0 _RC0 c
_RC1::
.blkb 1
.area idata
.byte 12
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e RC1 _RC1 c
_Add::
.blkb 1
.area idata
.byte 161
.area data(ram, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbsym e Add _Add c
.area text(rom, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbfunc e port_init _port_init fV
.even
_port_init::
.dbline -1
.dbline 81
;
; /*函数的使用说明:
; 1.该twi模块包含四种工作模式,主发,主收,从收,从发,其中主发由
; twiWriteByte(从机地址,要发送的数据)实现,主收由twiReadByte(从机地址)实现,从机
; 的发送与接收均通过中断实现
; 2.在从机模式下,需调用twi_init()来使能并初始化twi总线
; 3.在主机模式下,调用twiWriteByte(从机地址,要发送的数据)向指定的从机写入数据,
; 调用twiReadByte(从机地址)从指定的从机读取数据,然后可通过查询错误状态error_state
; 的值决定下一步如何操作。
; */
;
; #include "twi.h"
;
; //TWI同程序的接口参数
; //receive_data,error_state不用设置
; char receive_data=0; // 接收到的数据
; char error_state=0; // twi错误状态
; //以下三个参数根据需求进行设置
; char slave_address=0xa0; // 设置从机地址,Bits 7..1:存放从机地址,Bit 0:最低位为广播识别使能位
; char bit_race=0x20; // 设置主机模式的比特率,SCL=CPU频率/(16+2*(TWBR)*4TWPS),TWPS在4的指数位置
; char send_data=0x02; // 从机发送模式下从机向主机发送的数据
; //要发送的数据
; char trandata[num] = {0x00,0x01,0x02,0x03};
; //*************************PTR8000全局变量**********************************
; unsigned char Recv;
; unsigned char RC0 = 0x4c,RC1 = 0x0c;//用于设置发送频率
; unsigned char Add = 0xa1; //设置发送地址
; //*************************** twi错误状态说明*********************************
; // 0:twi传送无错误
; // 1:在主发模式下,SLA+W已发送,返回NOT ACK
; // 2:在主发模式下,DATA已发送,返回NOT ACK
; // 3:在主发模式下,SLA+W或者数据的仲裁失败
; // 4:在主收模式下,SLA+R或者数据的仲裁失败
; // 5:在主收模式下,SLA+R已发送,返回NOT ACK
; // 6:在主发模式下,START信号发送不成功
; // 7:在主收模式下,START信号发送不成功
; // 8:在主收模式下,数据接受完成
; // 9:在主收模式下,数据接受不成功
; //*****************************************************************************
;
;
; //*************************函数定义部分**************************************
; void port_init(void); //初始化MEGA各控制引脚
;
; void Delay_1ms(void); //延时1ms函数
; void Delay_Nms(unsigned int N); //延时Nms函数
; void LED(unsigned char i); //点亮/熄灭LED
;
; //串口通讯用函数
; void Uart_Init(void); //UART初始化
; void Uart_Send(unsigned char c); //UART发送一个字符
;
;
; //SPI通讯用函数
; void SPI_MasterInit(void); //SPI主机初始化
; void SPI_M_Send(unsigned char c); //主机方式发送一个字符
; unsigned char SPI_M_Recv(unsigned char c); //主机接收一个字符
;
; //PTR8000用函数
; void PTR8_Standby(void); //set TRC_CE Disable
; void PTR8_TREN(void); //set TRX_CE Enable
; void PTR8_TX(void); //无线模块发送状态
; void PTR8_RX(void); //无线模块接收状态
; void Init_PTR8_CR(void); //初始化PTR8000控制状态
;
; void Init_Device(void); //初始化串口、SPI口及其他设备
;
; //******************************函数实现部分************************************
;
; //*************************** I/O 初始化****************************************
; //******************************************************************************
; /* 函数名: init_port
; 功能说明:初始化各MEGA8各控制引脚
; 参数说明:无
; 函数作者:Haibo YU
; 版本号: 1.0
; 创建时间:2005-12-23
; 修改时间:
; 修改内容: */
; void port_init(void)
; {
.dbline 82
; PORTB = 0x2f; //置PB0,PB1,PB2,PB3,PB5为1,PB4,PB6,PB7为0
ldi R24,47
out 0x18,R24
.dbline 83
; DDRB = 0x2f; //置PB0,PB1,PB2--SS,PB3--MOSI,PB5--SCK为输出,PB4--MISO为输入
out 0x17,R24
.dbline 84
; PORTC = 0x0f;
ldi R24,15
out 0x15,R24
.dbline 85
; DDRC = 0x0f; //PC4--SDA,PC5--SCL为输入,PC0--PC3全为输出以便测试
out 0x14,R24
.dbline 86
; PORTD = 0x05; //置PWR,TXEN为1, TRXCE为0
ldi R24,5
out 0x12,R24
.dbline 87
; DDRD = 0x07; //置PD3,PD4,PD5输入;PD2--PWR,PD0--TXEN,PD1--TRXCE输出
ldi R24,7
out 0x11,R24
.dbline -2
.dbline 88
; }
L1:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Delay_1ms _Delay_1ms fV
; i -> R16,R17
.even
_Delay_1ms::
.dbline -1
.dbline 101
; //**************************************************************************************
;
; /* 函数名: Delay_1ms
; 功能说明:软件延时1ms
; 参数说明:无
; 函数作者:Haibo YU
; 版本号: 1.0
; 创建时间:2005-12-06
; 修改时间:
; 修改内容: */
;
; void Delay_1ms(void)
; {
.dbline 103
; unsigned int i;
; for ( i = 0 ; i < ( unsigned int ) 11 * 143 - 2 ; i ++ )
clr R16
clr R17
rjmp L6
L3:
.dbline 104
L4:
.dbline 103
subi R16,255 ; offset = 1
sbci R17,255
L6:
.dbline 103
cpi R16,35
ldi R30,6
cpc R17,R30
brlo L3
.dbline -2
.dbline 105
; ;
; }
L2:
.dbline 0 ; func end
ret
.dbsym r i 16 i
.dbend
.dbfunc e Delay_Nms _Delay_Nms fV
; j -> R20,R21
; N -> R22,R23
.even
_Delay_Nms::
rcall push_gset2
movw R22,R16
.dbline -1
.dbline 117
; //******************************************************************
;
; /* 函数名: Delay_Nms
; 功能说明:软件延时Nms,适用于所有CPU
; 参数说明:N值决定延时长度。范围为0~65536之间的整数
; 函数作者:Haibo YU
; 版本号: 1.0
; 创建时间:2005-12-06
; 修改时间:
; 修改内容: */
; void Delay_Nms(unsigned int N)
; {
.dbline 119
; unsigned int j;
; for( j = 0 ; j < N ; j ++ )
clr R20
clr R21
rjmp L11
L8:
.dbline 120
rcall _Delay_1ms
L9:
.dbline 119
subi R20,255 ; offset = 1
sbci R21,255
L11:
.dbline 119
cp R20,R22
cpc R21,R23
brlo L8
.dbline -2
.dbline 121
; Delay_1ms();
; }
L7:
rcall pop_gset2
.dbline 0 ; func end
ret
.dbsym r j 20 i
.dbsym r N 22 i
.dbend
.dbfunc e LED _LED fV
; i -> R16
.even
_LED::
.dbline -1
.dbline 134
; //*******************************************************************
;
; /* 函数名: LED
; 功能说明:点亮/熄灭LED
; 参数说明:0----点亮;1----熄灭
; 函数作者:Haibo YU
; 版本号: 1.0
; 创建时间:2005-12-23
; 修改时间:
; 修改内容: */
;
; void LED(unsigned char i)
; {
.dbline 135
; if(i == 0)
tst R16
brne L13
.dbline 136
; PORTB &= ~BIT(PB1);
cbi 0x18,1
rjmp L14
L13:
.dbline 138
sbi 0x18,1
L14:
.dbline -2
.dbline 139
; else
; PORTB |= BIT(PB1);
; }
L12:
.dbline 0 ; func end
ret
.dbsym r i 16 c
.dbend
.dbfunc e Uart_Init _Uart_Init fV
.even
_Uart_Init::
.dbline -1
.dbline 155
;
; //*******************************************************************
;
; //串口通讯用函数
;
; /* 函数名: Uart_Init
; 功能说明:串口初始化函数,适用于所有CPU
; 波特率9600,8位字节,无奇偶校验
; 参数说明:无
; 函数作者:Haibo YU
; 版本号: 1.0
; 创建时间:2005-12-02
; 修改时间:
; 修改内容: */
; void Uart_Init(void)
; {
.dbline 156
; UCSRB = 0x00; //disable while setting baud rate
clr R2
out 0xa,R2
.dbline 157
; UCSRA = 0x00;
out 0xb,R2
.dbline 158
; UCSRC = 0x86;
ldi R24,134
out 0x20,R24
.dbline 159
; UBRRL = 0x47; //set baud rate lo
ldi R24,71
out 0x9,R24
.dbline 160
; UBRRH = 0x00; //set baud rate hi
out 0x20,R2
.dbline 161
; UCSRB = 0x98;
ldi R24,152
out 0xa,R24
.dbline -2
.dbline 162
; }
L15:
.dbline 0 ; func end
ret
.dbend
.dbfunc e Uart_Send _Uart_Send fV
; c -> R16
.even
_Uart_Send::
.dbline -1
.dbline 174
; //********************************************************************
;
; /* 函数名: Uart_Send
; 功能说明:通过查询方式,串口发送一个字节函数,适用于所有CPU
; 参数说明:c为所要发送的字节
; 函数作者:Haibo YU
; 版本号: 1.0
; 创建时间:2005-12-02
; 修改时间:
; 修改内容: */
; void Uart_Send(unsigned char c)
; {
L17:
.dbline 176
L18:
.dbline 175
; while(!(UCSRA&(1<<UDRE)))
sbis 0xb,5
rjmp L17
.dbline 177
; ; //等待空闲
; UDR=c; //发送数据
out 0xc,R16
.dbline -2
.dbline 178
; }
L16:
.dbline 0 ; func end
ret
.dbsym r c 16 c
.dbend
.area vector(rom, abs)
.org 22
rjmp _uart0_rx_isr
.area text(rom, con, rel)
.dbfile E:\iccavr\无线+I2C\test1--mt\twimain.c
.dbfunc e uart0_rx_isr _uart0_rx_isr fV
.even
_uart0_rx_isr::
rcall push_lset
.dbline -1
.dbline 182
; /*接收中断函数*/
; #pragma interrupt_handler uart0_rx_isr:12
; void uart0_rx_isr(void)
; {
.dbline 183
; Recv = UDR;
in R2,0xc
sts _Recv,R2
.dbline 184
; Uart_Send(Recv);//接收到的数据立即通过串口返回
mov R16,R2
rcall _Uart_Send
.dbline -2
.dbline 186
;
; }
L20:
rcall pop_lset
.dbline 0 ; func end
reti
.dbend
.dbfunc e SPI_MasterInit _SPI_MasterInit fV
.even
_SPI_MasterInit::
.dbline -1
.dbline 203
; //**********************************************************************
;
; //SPI通讯用函数
;
; /* 函数名: SPI_MasterInit
; 功能说明:SPI主机初始化函数。使能SPI,MSB在前,主模式
; 起始上升沿,采样上升沿。16分频
; 参数说明: 无
; 返回值: 无
; 函数作者:Haibo YU
; 版本号: 1.0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -