📄 c13.asm
字号:
/* "探索式:" 实验十九: 串行E2PROM24C01扩展实验 */
/* 文件名:(C13.c) */
#pragma code debug small
#include <reg51.h>
#include <intrins.h>
#include <absacc.h>
#include <string.h>
#include <string.h>
#define uchar unsigned char
#define uint unsigned int
sbit SCL=P1^6;
sbit SDA=P1^7;
sbit K0=P1^3;
uchar E24_State;
#define COM XBYTE[0xe100] /*命令口*/
#define OUTBIT XBYTE[0xe101] /* 位控制口 */
#define CLK164 XBYTE[0xe102] /* 段控制口(接164时钟位) */
#define DAT164 XBYTE[0xe102] /* 段控制口(接164数据位) */
#define IN XBYTE[0xe103] /* 键盘读入口 */
uchar buf[6]; /* 显示缓冲 */
uchar code tab[17]={ /* 八段管显示码 */
0x3f, 0x6, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x7,
0x7f, 0x6f,0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71,0
};
void sdelay() /* 延时子程序 */
{ uint x=200;
while(--x);
}
void time10ms(char num)
{ uint lp;
uchar i;
for(i=0;i<=num;i++)
{ lp=200; while(--lp); }
}
void start()
{ SCL=0;SDA=1; SCL=1; SDA=0; SCL=0; }
void endd()
{ SCL=0; SDA=0; SCL=1; SDA=1;}
char rbyte(char ask_flag)
{ uchar x,lp;
x=0;
for(lp=0;lp<8;lp++)
{ SCL=0;
SDA=1; /* set SDA input */
SCL=1;
x=(x<<1)|SDA;
}
SCL=0;
if(ask_flag) SDA=0; /* master ask */
else SDA=1; /* master no ask */
SCL=1;;
return(x);
}
void wbyte(char p)
{ uchar i;
for(i=0;i<8;i++)
{ SCL=0;
SDA=p&0x80;
p<<=1;
SCL=1;
}
SCL=0; /* extra 9th pulse */
SDA=1; /* set SDA input */
SCL=1;
i=255;
while(SDA && --i) /* wait for slave ack */
if(!i)
E24_State|=0x1;
SCL=0;
}
char read_byte(char adr)
{ uchar x;
start();
wbyte(0xa0);
wbyte(adr);
start();
wbyte(0xa1);
x=rbyte(0);
endd();
return(x);
}
void write_byte(char adr,char num)
{ start();
wbyte(0xa0);
wbyte(adr);
wbyte(num);
endd();
time10ms(0);
}
void disp()
{ static uchar temp;
uchar i,j,shift=0x20,x; /* 从左边开始显示 */
for(i=0;i<6;i++) /* 共6个八段管 */
{ OUTBIT=00; /* 关所有八段管 */
temp=0;
x=tab[buf[i]];
for(j=0;j<8;j++) /* 送164 */
{ if( x&0x80) temp|=1;
else temp&=0xfe;
DAT164=temp;
temp|=2; /* CLK='1' */
CLK164=temp;
temp&=0xfd;; /* CLK='0' */
CLK164=temp;
x<<=1;
}
OUTBIT=shift; /* 显示一位八段管 */
shift>>=1; /* 显示下一位 */
sdelay();
}
}
main()
{ uchar i;
SP=0x60;
PSW=0;
COM=0x3; /* 定义8155 PA,PB口 输出,PC口输入*/
while(1)
{if(K0)
{ write_byte(0x10,0x41); /*向0x10,0x11,0x12单元分别写入0x41,0x21,0x86*/
write_byte(0x11,0x21);
write_byte(0x12,0x86);
memset(buf,0,6); /*设置显示"000000" */
}
else
{ i=read_byte(0x10); /*读出0x10,0x11,0x12,三个单元内容*/
buf[0]=(i&0xf0)>>4;
buf[1]=i&0xf;
i=read_byte(0x11);
buf[2]=(i&0xf0)>>4;
buf[3]=i&0xf;
i=read_byte(0x12);
buf[4]=(i&0xf0)>>4;
buf[5]=i&0xf;
}
for(i=0;i<20;i++)
disp(); /* 显示 */
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -