📄 51
字号:
if(write_8bit(*ufirstr_ad)!=0){stop_bit();return(0);}//写1字节
ufirstr_ad++; //地址加1
}
stop_bit(); //写停止位
return(1);
}
/*-----------------------------------------------
调用方式:void page_rd(uint firstrd_ad,uint count,uint *firstwr_ad)
函数说明:2416页面读函数,firstrd-ad为所读字节首地址,count为读字节数
ufirstwr-ad为读出数据存储首地址
-----------------------------------------------*/
uchar page_rd(uint firstrd_ad,uint count,uchar *firstwr_ad)
{
uchar j=8;
uchar data *ufirstwr_ad;
ufirstwr_ad=firstwr_ad;
start_bit(); //写开始位
if(write_8bit(0xA0)!=0){stop_bit();return(0);} //写命令
if(write_8bit(firstrd_ad)!=0){stop_bit();return(0);} //写首地址
start_bit(); //写开始位
if(write_8bit(0xA1)!=0){stop_bit();return(0);} //读命令
while(count--) //读字节数减1
{
uchar i=8;
while(i--)
{
(*ufirstwr_ad)<<=1; //读对应地址的数据左移
SCL=1;_nop_(); //上升沿
if(SDA) (*ufirstwr_ad)|=0x01; //数据端为1时 存1
SCL=0; _nop_();
}
ufirstwr_ad++; //地址加1
mast_ack(); //应答信号
}
while(j--)
{
(*ufirstwr_ad)<<=1;
SCL=0;_nop_();_nop_();SCL=1;
if(SDA) (*ufirstwr_ad)|=0x01;
}
stop_bit(); //写停止位
return(1);
}
/////////////////////以下是PCF8563读写/////////////////////以下是PCF8563读写
/* I2C的起始条件,在时钟端SCK为高电平时,数据端SDA发生由高到低的变化,为起始条件,
启动I2C总线。程序代码如下。 */
void xie_start()
{
clk=1;_nop_();
dat=1;_nop_();
dat=0;_nop_();
clk=0;_nop_();
}
/* I2C的停止条件,在时钟端SCL为高电平时,数据端SDA发生由低到高的变化,
为停止条件,停止I2C总线数据传输。 */
void xie_stop()
{
dat=0;_nop_();
clk=1;_nop_();
dat=1;_nop_();
}
bit xie1(uchar shu) //向8563中写入1个字
{
uchar i=8;
bit fan_w;
clk=0;_nop_();
while(i--)
{
dat=(bit)(shu&0x80); //取字节的最高位
_nop_();
shu<<=1; //字节左移一位
clk=1; //上升沿锁存数据
_nop_();
clk=0;
_nop_();
}
dat=1;
_nop_();
clk=1;
_nop_();
fan_w=dat; //读应答信号
clk=0;
_nop_();
return(fan_w); //返回应答信号
}
uchar du1() //从8563中读出1个字
{
uchar shu=0;
uchar data rdata;
uchar i=8;
while(i--)
{
rdata<<=1; //字节左移一位
dat=1;
clk=1;_nop_(); //上升沿锁存数据
if(dat) rdata|=0x01; //数据线为1时 对应位存1
clk=0;_nop_();
}
shu=rdata; //读到的数据存于SHU
return(shu); //返回读到的数据
}
uchar du()
{
EA=0; //关总中断
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
if(xie1(0x02)!=0){xie_stop();return(0);}//取读时间的首字节地址从秒开始读
xie_start(); //起始条件
if(xie1(0xa3)!=0){xie_stop();return(0);}//取器件地址 读
miao=du1()&0x7f; //读秒 屏蔽最高位
xie_stop(); //停止条件
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
if(xie1(0x03)!=0){xie_stop();return(0);}//取读分钟字节地址
xie_start(); //起始条件
if(xie1(0xa3)!=0){xie_stop();return(0);}//取器件地址 读
fen=du1()&0x7f; //读分 屏蔽最高位
xie_stop(); //停止条件
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
if(xie1(0x04)!=0){xie_stop();return(0);}//取读小时字节地址
xie_start(); //起始条件
if(xie1(0xa3)!=0){xie_stop();return(0);}//取器件地址 读
shi=du1(); //读时
shi&=0x3f; //屏蔽最高2位
xie_stop(); //停止条件
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//写
if(xie1(0x05)!=0){xie_stop();return(0);}//取读日期字节地址
xie_start(); //起始条件
if(xie1(0xa3)!=0){xie_stop();return(0);}//读
riqi=du1(); //读日期
riqi&=0x3f; //屏蔽最高2位
xie_stop(); //停止条件
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//写
if(xie1(0x07)!=0){xie_stop();return(0);}//取读月份字节地址
xie_start(); //起始条件
if(xie1(0xa3)!=0){xie_stop();return(0);}//读
yuefen=du1(); //读月份
yuefen&=0x1f; //屏蔽最高3位
xie_stop(); //停止条件
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//写
if(xie1(0x06)!=0){xie_stop();return(0);}//星期字节地址
xie_start(); //起始条件
if(xie1(0xa3)!=0){xie_stop();return(0);}//读
xingqi=du1(); //读星期
xingqi&=0x07; //保留低3位
xie_stop(); //停止条件
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//写
if(xie1(0x08)!=0){xie_stop();return(0);}//年份字节地址
xie_start(); //起始条件
if(xie1(0xa3)!=0){xie_stop();return(0);}//读
nian=du1(); //读年份
xie_stop(); //停止条件
EA=1; //开总中断
return(1);
}
uchar xie()
{
EA=0;
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
if(xie1(0x02)!=0){xie_stop();return(0);}//写秒地址
if(xie1(miao)!=0){xie_stop();return(0);}//写秒
xie_stop(); //停止条件
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
if(xie1(0x03)!=0){xie_stop();return(0);}//写分地址
if(xie1(fen)!=0){xie_stop();return(0);} //写分
xie_stop();
xie_start(); //起始条件
if(xie1(0xa2)!=0){xie_stop();return(0);}//取器件地址 写
if(xie1(0x04)!=0){xie_stop();return(0);}//写小时地址
if(xie1(shi)!=0){xie_stop();return(0);} //写时
xie_stop();
xie_start(); //写日期
if(xie1(0xa2)!=0){xie_stop();return(0);}
if(xie1(0x05)!=0){xie_stop();return(0);}
if(xie1(riqi)!=0){xie_stop();return(0);}
xie_stop();
xie_start(); //写月份
if(xie1(0xa2)!=0){xie_stop();return(0);}
if(xie1(0x07)!=0){xie_stop();return(0);}
if(xie1(yuefen)!=0){xie_stop();return(0);}
xie_stop();
xie_start(); //写星期
if(xie1(0xa2)!=0){xie_stop();return(0);}
if(xie1(0x06)!=0){xie_stop();return(0);}
if(xie1(xingqi)!=0){xie_stop();return(0);}
xie_stop();
xie_start(); //写年份
if(xie1(0xa2)!=0){xie_stop();return(0);}
if(xie1(0x08)!=0){xie_stop();return(0);}
if(xie1(nian)!=0){xie_stop();return(0);}
xie_stop();
EA=1;
return(1);
}
/////////////////////以上是PCF8563读写/////////////////////以上是PCF8563读写
/*------------写数据或命令到LCD--------------*/
void wr_lcd (uchar dat_comm,uchar content)
{
chk_busy (); //
di=dat_comm; //命令标志
rw=0; //写
data_ora=content; //写数据到LCD的数据端
e=1; //下降沿锁定数据
e=0;
}
void chk_busy()
{
data_ora=0xff; //写1到LCD的数据端
di=0;
rw=1; //读
e=1;
e=0;
}
/*--------------写点阵------------------*/
void lat_disp (uchar data1,uchar data2)
{
uchar i,j;
cs1=0;cs2=0; //左右屏幕同时选中
wr_lcd (comm,disp_on); //写命令字,显示开
for(j=0;j<8;j++) //8页
{
wr_lcd (comm,disp_x+j); //页地址调整
wr_lcd (comm,disp_z); //指向对应页的0行
wr_lcd (comm,disp_y); //指向对应页的0列
for(i=0;i<32;i++) //写64个数据
{
wr_lcd (dat1,data1); //左屏
wr_lcd (dat1,data2); //右屏
}
}
}
/*---指定位置(x,y)显示row_xl行(每行row_yl个)汉字(大小8xl*yl)---*/
void chn_disp (uchar x,uchar y,uchar xl,uchar yl,uchar row_xl,uchar row_yl,uchar code *chn)
{
uchar i,j,k,l,a;
wr_lcd (comm,disp_on); //写命令字,显示开
for(l=0;l<row_xl;l++) //行数循环
{
for(k=0;k<row_yl;k++) //字数循环
{
for(j=0;j<xl;j++)
{
wr_lcd (comm,disp_x+x+l*xl+j); //行数调整
wr_lcd (comm,disp_z); //列数调整
wr_lcd (comm,disp_y+y+k*yl); //字数调整
a=l*xl*yl*row_yl+k*xl*yl+j*yl;
for(i=0;i<yl;i++) //写数据
wr_lcd (dat1,chn[a+i]);
}
}
}
}
/*------------------初始化-----------------*/
void init_lcd ()
{
delay(50);
cs1=0;cs2=0; //左右屏幕同时选中
wr_lcd (comm,disp_off); //写命令字,显示关
wr_lcd (comm,disp_on); //写命令字,显示开
}
void disp()
{
cs1=0;cs2=1; //左半屏幕选中
chn_disp (0,8,2,8,1,1,tabma[2]); //固定显示数字“2”
chn_disp (0,16,2,8,1,1,tabma[0]); //固定显示数字“0”
chn_disp (0,24,2,8,1,1,tabma[nian/16]); //显示年的数字十位
chn_disp (0,32,2,8,1,1,tabma[nian%16]); //显示年的数字个位
chn_disp (0,40,2,16,1,1,nianma); //固定显示汉字“年”
chn_disp (0,56,2,8,1,1,tabma[yuefen/16]); //显示月份的数字十位
cs1=1;cs2=0; //右半屏幕选中
chn_disp (0,0,2,8,1,1,tabma[yuefen%16]); //显示月份的数字个位
chn_disp (0,8,2,16,1,1,yuema); //固定显示汉字“月”
chn_disp (0,24,2,8,1,1,tabma[riqi/16]); //显示日期的数字十位
chn_disp (0,32,2,8,1,1,tabma[riqi%16]); //显示日期的数字个位
chn_disp (0,40,2,16,1,1,rima); //固定显示汉字“日”
cs1=0;cs2=1; //左半屏幕选中
chn_disp (3,8,2,16,1,2,xingqima); //固定显示汉字“星期”
chn_disp (3,40,2,16,1,1,tab2ma[xingqi]); //显示汉字星期几
chn_disp (6,16,2,8,1,1,tabma[shi/16]); //显示小时的数字十位
chn_disp (6,24,2,8,1,1,tabma[shi%16]); //显示小时的数字个位
chn_disp (6,32,2,16,1,1,shima); //固定显示汉字“时”
chn_disp (6,48,2,8,1,1,tabma[fen/16]); //显示分钟的数字十位
chn_disp (6,56,2,8,1,1,tabma[fen%16]); //显示分钟的数字个位
cs1=1;cs2=0; //右半屏幕选中
chn_disp (6,0,2,16,1,1,fenma); //固定显示汉字“分”
chn_disp (6,16,2,8,1,1,tabma[miao/16]); //显示秒的数字十位
chn_disp (6,24,2,8,1,1,tabma[miao%16]); //显示秒的数字个位
chn_disp (6,32,2,16,1,1,miaoma); //固定显示汉字“秒”
}
void dispVi() //显示压力
{
uchar k;
cs1=0;cs2=1; //先左半屏幕选中
for(k=0;k<8;k++)
{
chn_disp ((k/2)*2,8,2,8,1,1,tabma[k]); //显示路号
chn_disp ((k/2)*2,24,2,8,1,1,tabma[Vi[k]/100]); //显示压力的百位
chn_disp ((k/2)*2,32,2,8,1,1,tabma[Vi[k]%100/10]);//显示压力的十位
chn_disp ((k/2)*2,40,2,8,1,1,tabma[Vi[k]%10]); //显示压力的个位
cs1=!cs1; //切换左右屏
cs2=!cs2;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -