fd650驱动程序

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

#includereg52.h#includeFD650.h#defineucharunsignedchar#defineuintunsignedint/*codeuchard[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};*/uintsec=1234;//uintsshi,sge,sbai,sqian;staticcharcourt=0;/*sbitP20=P2^0;sbitP21=P2^1;sbitP22=P2^2;sbitP23=P2^3;sbitP24=P2^4;sbitP25=P2^5;sbitP26=P2^6;sbitP27=P2^7;*/sbitK1=P3^0;sbitK2=P3^1;sbitK3=P3^2;sbitK4=P3^3;ucharsty=0;uchartime[4];uchartable[10]={0x3f,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7f,0x6f};/*******************************************************************//*addSWFPlocationvariable*//*************************************************************************************//******************************************************************FunctionName:FD650_Start**Description:**Parameter:**return:****************************************************************/voidFD650_Start(void){FD650_SDA_SET;//FD650_SDA_D_OUT;FD650_SCL_SET;//FD650_SCL_D_OUT;DELAY;FD650_SDA_CLR;DELAY;FD650_SCL_CLR;}/******************************************************************FunctionName:FD650_Stop**Description:**Parameter:**return:****************************************************************/voidFD650_Stop(void){FD650_SDA_CLR;//FD650_SDA_D_OUT;DELAY;FD650_SCL_SET;DELAY;FD650_SDA_SET;DELAY;//FD650_SDA_D_IN;}/******************************************************************FunctionName:FD650_WrByte**Description:WriteOneBytedata**Parameter:data**return:****************************************************************/voidFD650_WrByte(u_int8dat){u_int8i;//FD650_SDA_D_OUT;for(i=0;i!=8;i++){if(dat&0x80){FD650_SDA_SET;}else{FD650_SDA_CLR;}DELAY;FD650_SCL_SET;dat=1;DELAY;//可选延时FD650_SCL_CLR;}//FD650_SDA_D_IN;FD650_SDA_SET;DELAY;FD650_SCL_SET;DELAY;FD650_SCL_CLR;}/******************************************************************FunctionName:FD650_WrByte**Description:ReadOneBytedata**Parameter:**return:data****************************************************************/u_int8FD650_RdByte(void){u_int8dat,i;FD650_SDA_SET;//FD650_SDA_D_IN;dat=0;for(i=0;i!=8;i++){DELAY;//可选延时FD650_SCL_SET;DELAY;//可选延时dat=1;if(FD650_SDA_IN)dat++;FD650_SCL_CLR;}FD650_SDA_SET;DELAY;FD650_SCL_SET;DELAY;FD650_SCL_CLR;returndat;}/****************************************FD650操作函数*********************************************//******************************************************************FunctionName:FD650_Write**Description:通过发送命令参数**Parameter:cmd见FD650.H**return:无****************************************************************/voidFD650_Write(u_int16cmd)//写命令{FD650_Start();FD650_WrByte(((u_int8)(cmd7)&0x3E)|0x40);FD650_WrByte((u_int8)cmd);FD650_Stop();return;}/******************************************************************FunctionName:FD650_Read**Description:读取按键按下状态的键值,如读到无效按键值返回0**Parameter:无**return:按键按下状态的键值****************************************************************/u_int8FD650_Read(void)//读取按键{u_int8keycode=0;FD650_Start();FD650_WrByte((u_int8)(FD650_GET_KEY7)&0x3E|0x01|0x40);keycode=FD650_RdByte();FD650_Stop();if((keycode&0x00000040)==0)keycode=0;returnkeycode;}voiddelay(){uchari;for(i=0;i15;i++);}voiddelayus(uchari){while(i--);}voiddelays(ucharj)//误差0us{unsignedchara,b,c;for(c=j;c0;c--)for(b=142;b0;b--)for(a=2;a0;a--);}voidFD650_Show_StandbyTime(uchar*sec){uchari=0;uchardat[4];/*iLenth=strlen(TimeString);if(iLenth4){iLenth=4;}*/for(i=0;i4;i++){dat[i]=table[sec[i]];}FD650_Write(FD650_DIG0|(uchar)dat[0]);//点亮第一个数码管FD650_Write(FD650_DIG1|(uchar)dat[1]);//点亮第二个数码管FD650_Write(FD650_DIG2|(uchar)dat[2]);//点亮第三个数码管FD650_Write(FD650_DIG3|(uchar)dat[3]);//点亮第四个数码管}voidint1()interrupt1using2{TH0=0x4c;TL0=0x00;court++;}voidint2()interrupt3{EA=0;if((!P30)|(!P31)|(!P32)|(!P33)){if(P30==0)delayus(10);if(P30==0){sty++;if(sty==5)sty=1;}if(P31==0)delayus(5);if(P31==0){sec++;if(sec==10000)sec=0;}}EA=1;}voidmain(){TMOD=0x21;TH0=0x4c;TL0=0x00;TH1=0xe0;TL1=0xe0;EA=1;ET0=1;ET1=1;TR0=1;TR1=1;FD650_Write(FD650_SYSON);FD650_Write(FD650_7SEG_ON);for(;;){time[0]=sec/1000;time[1]=sec/100%10;time[2]=sec/10%10;time[3]=sec%10;FD650_Show_StandbyTime(time);if(court==20){court=0;sec--;if(sec==10000){sec=0;}}}}

1 / 7
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功