新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計應用 > 24C04擴展存儲器C和匯編程序

24C04擴展存儲器C和匯編程序

作者: 時間:2016-11-30 來源:網(wǎng)絡 收藏

uchar rdbyt(void)
{
uchar a,c;
scl=0;
delaym(1);
sda=1;
delaym(1);
for(c=0;c<8;c++)
{
scl=1;
delaym(1);
a=(a<<1)|sda;
scl=0;
delaym(1);
}
return a;
}
void read_data()
{
Start_I2c();
wrbyt(0xa0);
cack();
wrbyt(1);
cack();
Start_I2c();
wrbyt(0xa1);
cack();
temp=rdbyt();
mnack();
Stop_I2c();
delayic(50);
}
void write_data()
{
if(temp<=10)
{
state=temp;
state++;
Start_I2c();
wrbyt(0xa0);
cack();
wrbyt(1);
cack();
Stop_I2c();
delayic(50);
}
else
{
temp=0;
state=temp;
Start_I2c();
wrbyt(0xa0);
cack();
wrbyt(1);
cack();
wrbyt(state);
cack();
Stop_I2c();
delayic(50);
}
}
void dispaly(uchar count)
{
uchar num;
num=count;
if(num>=5)
{
P2=0x00;
delayic(400);
}
data_l=num%10;
data_h=num/10;
P2=0x01;
P0=tab[data_h];
delayic(150);
P2=0x02;
P0=tab[data_l];
delayic(150);
}
void main()
{
read_data();
write_data();
while(1)
{
dispaly(temp);
}
}
匯編程序:
;24c02的開機計數(shù)器,系統(tǒng)復位一次數(shù)碼管加1
SDA24 EQU P1.1
SCLK24 EQU P1.0
ORG 0000H
AJMP MAIN
ORG 0030H
MAIN:
CLR P3.7 ;打開寫保護
MOV DPTR,#TAB
MOV A,#00H ;讀地址
LCALL RD24
CJNE A,#10,TT
TT: JNC TT1
AJMP TT2
TT1: MOV A,#00
TT2: MOV 30H,A
MOVC A,@A+DPTR
SETB P2.0 ;開數(shù)碼管
MOV P0,A ;送顯示
MOV A,30H
INC A
MOV B,A
MOV A,#00H
LCALL WT24
AJMP $
TAB: DB 28H,7EH,0A2H,62H,74H,61H,21H,7AH,20H,60H

RD24: PUSH ACC ;讀24C02子程序。
SETB SDA24
CLR SCLK24
CALL START24
MOV A,#0A0H
CALL SHIFT8
CALL ACK
POP ACC
CALL SHIFT8
CALL ACK
CALL START24
MOV A,#0A1H
CALL SHIFT8
CALL ACK
SETB SDA24
MOV R7,#8
CLR A
SETB SDA24
RD000: RL A
SETB SCLK24
MOV C,SDA24
MOV ACC.0,C
CLR SCLK24
DJNZ R7,RD000
RET
;-------------------------------
;寫入24C02程序:
WT24: PUSH ACC
SETB SDA24
CLR SCLK24
CALL START24
MOV A,#0A0H
CALL SHIFT8
CALL ACK
POP ACC
CALL SHIFT8
CALL ACK
MOV A,B
CALL SHIFT8
CALL ACK
CALL STOP
CALL DELAY2
RET
; -------------------------------
;開始條件
START24:CLR SDA24
SETB SDA24
SETB SCLK24
CLR SDA24
CLR SCLK24
RET
;停止條件
STOP: CLR SDA24
SETB SCLK24
SETB SDA24
RET
;應答信號
ACK: SETB SCLK24
CLR SCLK24
RET
;讀、寫數(shù)據(jù)
SHIFT8: MOV R7,#8
SH01: RLC A
MOV SDA24,C
SETB SCLK24
CLR SCLK24
DJNZ R7,SH01
RET
DELAY2:
NOP
NOP
NOP
NOP
RET
END

上一頁 1 2 下一頁

關(guān)鍵詞: 24C04擴展存儲器匯編程

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉