全国电子技能大赛初赛程序代码.pdfVIP

  • 0
  • 0
  • 约1.05万字
  • 约 11页
  • 2026-02-16 发布于北京
  • 举报

Ps:对照题目要求和比赛实验班操作即可

#includereg52.h

#includeintrins.h

sbitRST=P1^3;

sbitSCLK=P1^7;

sbitIO=P2^3;

sbitSCL=P2^0;

sbitSDA=P2^1;

sbitbuzz=P0^6;

sbitrelay=P0^4;

sbits7=P3^0;

sbits6=P3^1;

sbits5=P3^2;

sbits4=P3^3;

bitgzflag=0;//工作状态标志位

bitflag=0;

bitqh=1;

bitbuzzflag=1;

bitxiang=0;

bitkai=0;

unsignedcharsd=50,min,hour,sec;

unsignedcharshidu,num;

unsignedcharcodes[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xbf,0xff};

//ds1302

voidwrite1302(unsignedchardat)

{

unsignedchari;

for(i=0;i8;i++)

{

SCLK=0;

_nop_();

IO=dat0x01;

SCLK=1;

dat=1;

}

}

voidwriteset1302(unsignedcharcmd,unsignedchardat)

{

RST=0;

SCLK=0;

RST=1;

write1302(cmd);

write1302(dat);

RST=0;

SCLK=1;

}

unsignedcharread1302()

{

unsignedchari,dat;

for(i=0;i8;i++)

{

SCLK=1;

_nop_();

SCLK=0;

dat=1;

if(IO)

dat|=0x80;

}

returndat;

}

unsignedcharreadset1302(unsignedcharcmd)

{

unsignedchardate;

RST=0;

SCLK=0;

RST=1;

write1302(cmd);

date=read1302();

RST=0;

SCLK=1;

returndate;

}

voidinit1302()

{

writeset1302(0x8e,0x00);

writeset1302(0x80,((55/10)4)|(55%10));

writeset1302(0x82,((30/10)4)|(30%10));

writeset1302(0x84,((8/10)4)|(8%10));

writeset1302(0x8e,0x80);

}

//pcf8591...iic

voiddelay()

{;;}

voidinitiic()

{

SCL=1;

delay();

SDA=1;

delay();

}

voidstartiic()

{

SDA=1;

delay();

SCL=1;

delay();

SDA=0;

delay();

}

voidstopiic()

{

SDA=0;

delay();

SCL=1;

文档评论(0)

1亿VIP精品文档

相关文档