GA8P46的MCU用汇编抓24C256芯片的IIC协议波形
现在已经出来Write的波形,但是没有Read的波形,有一起学习的吗?或者大家?
//.asm代码
include "mp01010.inc"
include "I2CRe.inc"
//include "Branch.inc"
//include "Calc.inc"
//include "I2C.inc"
//include "Pointer.inc"
ORG 0xFFF
jmp Main //开始(复位)
ORG 0x000
jmp Main //hard interrupt
ORG 0x001 //(硬件中断) 0x002(软件中断)
jmp HardInterupt
//ORG 0x060 //需要这个来结尾
Main:
sysyemInit:
MOV A,@0x00
MOV IOC5,A
bs port5, I2C_SCL //把I2C_SCL设置为1
bs port5, I2C_SDA //把I2C_SDA设置为1
MainLoop:
call I2C_Start
call I2C_WByte
call I2C_Stop
main_End:
jmp MainLoop
if 1
//I2C_SDA高信号
I2C_SDAH: //P5
bs port5, I2C_SDA
ret
//I2C_SDA低信号
I2C_SDAL: //P5
bc port5, I2C_SDA
ret
//I2C_SCL高信号
I2C_SCLH: //P5
bs port5, I2C_SCL
ret
//I2C_SCL低信号
I2C_SCLL: //P5
bc port5, I2C_SCL
ret
//I2C_ACKH=1
I2C_ACKH:
MOV a,@1
MOV ACK,a
ret
//开始信号
I2C_Start:
//设SDA为高
call I2C_SDAH
nop
//设SCL为高
call I2C_SCLH
nop
nop
nop
nop
nop
//设SDA为低
call I2C_SDAL
nop
nop
nop
nop
nop
//设SCL为低
call I2C_SCLL
nop
nop
ret
//停止信号
I2C_Stop:
//设SDA为低
call I2C_SDAL
nop
//设SCL为高
call I2C_SCLH
nop
nop
nop
nop
nop
//设SDA为高
call I2C_SDAH
nop
nop
nop
nop
ret
//发送应答信号
I2C_SendACK:
//设SDA为低
call I2C_SDAL
nop
nop
nop
//设SCL为高
call I2C_SCLH
nop
nop
nop
nop
nop
//设SCL为低
call I2C_SCLL
nop
nop
ret
//发送非应答信号
I2C_SendNACK:
//设SDA为高
call I2C_SDAH
nop
nop
nop
//设SCL为高
call I2C_SCLH
nop
nop
nop
nop
nop
//设SCL为低
call I2C_SCLL
nop
nop
ret
//发送数据(W写)(带应答信号检验)
I2C_WByte:
//写入的数据0x70
MOV a,@0x70
MOV SendByte,a
MOV a,@8
MOV count,a //循环八次的计数
nop
nop
nop
nop
nop
WLOOP_for: //相当于循环8次for循环
MOV a,SendByte
MOV retc,a
MOV a,@0x80
AND retc,a
JBc status,z //JBS判断(if)是否为1还是其它
call I2C_SDAL //temp非1
JBs status,z
call I2C_SDAH
RLC SendByte
nop
call I2C_SCLH //时钟拉高,开始接受数据
nop
nop
nop
nop
nop
call I2C_SCLL //时钟拉低
DJZ count //count开始-1
JMP WLOOP_for //非0时执行下的条件
//ret //为0时执行的条件
nop
nop
call I2C_SDAH //发送完数据,释放数据线,准备接受应答
nop
nop
//nop
call I2C_SCLH //拉高时钟
nop
nop
nop
// call I2C_SCLH
//判断SDA是否为高
if 1
bs ioc5, I2C_SDA
jbs port5, I2C_SDA
call I2C_SendACK
jbc port5, I2C_SDA
call I2C_SendNACK
else
JBS status,Z
call I2C_SendACK //SDA非1的时候执行
JBC status,Z
call I2C_SendNACK //SDA为1的时候执行
endif
bc ioc5, I2C_SDA
//拉低SCL时钟
call I2C_SCLL
nop
nop
ret
//读取数据Read
I2C_RByte:
clr ReceiveByte
nop
nop
nop
nop
nop
call I2C_SDAH //设置数据线的输入方式
//开始for循环
MOV a,@8
MOV count,a
RLOOP_for: //循环
call I2C_SCLL //拉低时钟线,准备接受数据
nop
nop
nop
nop
nop
call I2C_SCLH //拉高时钟线,使数据有效
RLC ReceiveByte
//if循环
JBS I2C_SDA,1
MOV a,@10 //SDA非1的时候执行
INC ReceiveByte //SDA为1的时候执行
DJZ count //count开始-1
JMP RLOOP_for
// ret //for循环结束
nop
nop
nop
nop
nop
call I2C_SCLL //拉低时钟线
nop
nop
ret //存储数据在ReceiveByte(读取出来的数据)
endif
HardInterupt:
reti
//i2cre.inc
ACK EQU 0x10
ReceiveByte EQU 0x11
count EQU 0x12
temp EQU 0x13
SendByte EQU 0x14
retc EQU 0x15
//port5
I2C_SCL equ 0
I2C_SDA equ 1
写不出Read波形
怎么写Read波形?网上的例子我找了,需要汇编语言的(有的我也找到,但是看不懂或者用我的MCU写不出来!),需要大家帮忙,非常感谢,如果想要一起学习的话也可以哈!