直接复制粘贴然后运行
然后打开stc烧录到开发板上面就能用 程序哪里不懂的话问我,我闲的蛋疼!
由于用到了EEPROM,所以大多数的人由于之前给EEPROM程序里面写过数据,所以不能用。
那么就只需要在主程序下面加入一个EEDA(0X00,0);在存储器0x00这个单元里面赋值个0
然后运行一下后,再把这段程序给删除掉,这样程序就可以使用了,不会弄的话问我!
#include <STC15F2K60S2.H>
#include <intrins.h>
unsigned char tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x40,0x79,0x24,0x30,0x19,0x12,0x02,0x78,0x00,0x10,0xc1,0x8c,0xc8,0xff};
unsigned char yi,er,san,si,wu,liu,qi,ba;
int shuju;
unsigned char jiemian=0;
unsigned char yuzhi;
unsigned char jishu=0;
bit a=0;
bit qingling=0;
bit s1=1,s2=1,s3=1;
int b=0;
unsigned char panding=0;
#define somenop {_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();}
#define SlaveAddrW 0xA0
#define SlaveAddrR 0xA1
//总线引脚定义
sbit SDA = P2^1; /* 数据线 */
sbit SCL = P2^0; /* 时钟线 */
void chushihua()
{
P2=0XA0;P0=0X00;P2=0X80;P0=0XFF;
P2=0XC0;P0=0X00;P2=0XFF;P0=0XFF;
}
void Delayms(int ms)
{
int i,j;
for(i=0;i<ms;i++)
for(j=845;j>0;j--);
}
void shumaguan1(unsigned char yi,unsigned char er)
{
P2=0XC0;
P0=0X01;
P2=0XFF;
P0=tab[yi];
Delayms(1);
P2=0XC0;
P0=0X02;
P2=0XFF;
P0=tab[er];
Delayms(1);
}
void shumaguan2(unsigned char san,unsigned char si)
{
P2=0XC0;
P0=0X04;
P2=0XFF;
P0=tab[san];
Delayms(1);
P2=0XC0;
P0=0X08;
P2=0XFF;
P0=tab[si];
Delayms(1);
}
void shumaguan3(unsigned char wu,unsigned char liu)
{
P2=0XC0;
P0=0X10;
P2=0XFF;
P0=tab[wu];
Delayms(1);
P2=0XC0;
P0=0X20;
P2=0XFF;
P0=tab[liu];
Delayms(1);
}
void shumaguan4(unsigned char qi,unsigned char ba)
{
P2=0XC0;
P0=0X40;
P2=0XFF;
P0=tab[qi];
Delayms(1);
P2=0XC0;
P0=0X80;
P2=0XFF;
P0=tab[ba];
Delayms(1);
}
//总线启动条件
void IIC_Start(void)
{
SDA = 1;
SCL = 1;
somenop;
SDA = 0;
somenop;
SCL = 0;
}
//总线停止条件
void IIC_Stop(void)
{
SDA = 0;
SCL = 1;
somenop;
SDA = 1;
}
//等待应答
bit IIC_WaitAck(void)
{
SDA = 1;
somenop;
SCL = 1;
somenop;
if(SDA)
{
SCL = 0;
IIC_Stop();
return 0;
}
else
{
SCL = 0;
return 1;
}
}
//通过I2C总线发送数据
void IIC_SendByte(unsigned char byt)
{
unsigned char i;
for(i=0;i<8;i++)
{
if(byt&0x80)
{
SDA = 1;
}
else
{
SDA = 0;
}
somenop;
SCL = 1;
byt <<= 1;
somenop;
SCL = 0;
}
}
//从I2C总线上接收数据
unsigned char IIC_RecByte(void)
{
unsigned char da;
unsigned char i;
for(i=0;i<8;i++)
{
SCL = 1;
somenop;
da <<= 1;
if(SDA)
da |= 0x01;
SCL = 0;
somenop;
}
return da;
}
unsigned char AD()
{
unsigned char temp;
IIC_Start();
IIC_SendByte(0x90);
IIC_WaitAck();
IIC_SendByte(0x03);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0x91);
IIC_WaitAck();
temp=IIC_RecByte();
IIC_Stop();
return temp;
}
unsigned char EEAD(unsigned char dat)
{
unsigned char temp;
IIC_Start();
IIC_SendByte(0xA0);
IIC_WaitAck();
IIC_SendByte(dat);
IIC_WaitAck();
IIC_Stop();
IIC_Start();
IIC_SendByte(0xA1);
IIC_WaitAck();
temp=IIC_RecByte();
IIC_Stop();
return temp;
}
void EEDA(unsigned char add,unsigned char dat)
{
IIC_Start();
IIC_SendByte(0xA0);
IIC_WaitAck();
IIC_SendByte(add);
IIC_WaitAck();
IIC_SendByte(dat);
IIC_WaitAck();
IIC_Stop();
}
void juzhen()
{
P44=0;P42=1;P35=1;P34=1;
if((P42==1)&&(P35==1)&&(P34==1))
{
if(P30==0)
{
Delayms(5);
if(P30==0)
{
while(!P30);
}
}
if(P31==0)
{
Delayms(5);
if(P31==0)
{
while(!P31);
}
}
if(P32==0)
{
Delayms(5);
if(P32==0)
{
while(!P32);
}
}
if(P33==0)
{
Delayms(5);
if(P33==0)
{
while(!P33);
}
}
}
P44=1;P42=0;P35=1;P34=1;
if((P44==1)&&(P35==1)&&(P34==1))
{
if(P30==0)
{
Delayms(5);
if(P30==0)
{
while(!P30);
}
}
if(P31==0)
{
Delayms(5);
if(P31==0)
{
while(!P31);
}
}
if(P32==0)
{
Delayms(5);
if(P32==0)
{
while(!P32);
}
}
if(P33==0)
{
Delayms(5);
if(P33==0)
{
while(!P33);
}
}
}
P44=1;P42=1;P35=0;P34=1;
if((P44==1)&&(P34==1)&&(P42==1))
{
if(P30==0)
{
Delayms(5);
if(P30==0)
{
while(!P30);
}
}
if(P31==0)
{
Delayms(5);
if(P31==0)
{
while(!P31);
}
}
if(P32==0)
{
Delayms(5);
if(P32==0)
{
while(!P32);
}
if(jiemian==2)
{
if(qingling==0)
{
qingling=1;
panding=0;
}
else
if(qingling==1)
{
qingling=0;
panding=0;
}
}
if((jiemian==1)||(jiemian==0))
{
panding=panding+1;
}
}
if(P33==0)
{
Delayms(5);
if(P33==0)
{
while(!P33);
}
if(jiemian==0)
{
jiemian=1;
panding=0;
}
else
if(jiemian==1)
{
jiemian=2;
panding=0;
}
else
if(jiemian==2)
{
jiemian=0;
panding=0;
}
}
}
P44=1;P42=1;P35=1;P34=0;
if((P44==1)&&(P35==1)&&(P35==1))
{
if(P30==0)
{
Delayms(5);
if(P30==0)
{
while(!P30);
}
}
if(P31==0)
{
Delayms(5);
if(P31==0)
{
while(!P31);
}
}
if(P32==0)
{
Delayms(5);
if(P32==0)
{
while(!P32);
}
if(jiemian==1)
{
if(yuzhi!=0)
{
yuzhi=yuzhi-5;
panding=0;
}
else
if(yuzhi==0)
{
yuzhi=50;
panding=0;
}
}
if((jiemian==2)||(jiemian==0))
{
panding=panding+1;
}
}
if(P33==0)
{
Delayms(5);
if(P33==0)
{
while(!P33);
}
if(jiemian==1)
{
yuzhi=yuzhi+5;
if(yuzhi==55)
{
yuzhi=yuzhi-55;
panding=0;
}
}
if((jiemian==2)||(jiemian==0))
{
panding=panding+1;
}
}
}
}
void LED()
{
P00=s1;
P01=s2;
P02=s3;
P03=1;
P04=1;
P05=1;
P06=1;
P07=1;
if((jishu%10==0)||(jishu%10==2)||(jishu%10==4)||(jishu%10==6)||(jishu%10==8))
{
s2=1;
}
else
{
s2=0;
}
P2=0X80;
}
void Timer0Init(void) //5毫秒@11.0592MHz
{
AUXR |= 0x80; //定时器时钟1T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x00; //设置定时初值
TH0 = 0x28; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
}
void tm0_isr() interrupt 1
{
TL0 = 0x00; //设置定时初值
TH0 = 0x28; //设置定时初值
b++;
if(b==1000)
{
b=0;
s1=0;
}
}
void main()
{
chushihua();
Timer0Init();
yuzhi=EEAD(0X00);
while(1)
{
juzhen();
if(jiemian==0) //数据显示界面
{
shuju=AD()*100/51;
yi=20;er=23;san=23;si=23;wu=23;liu=shuju/100+10;qi=shuju%100/10;ba=shuju%10;
}
if(jiemian==1)
{
yi=21;er=23;san=23;si=23;wu=23;liu=yuzhi/10+10;qi=yuzhi%10;ba=0;
}
if(jiemian==2)
{
if(qingling==1)
{
jishu=0;
qingling=0;
}
yi=22;er=23;san=23;si=23;wu=23;
if(jishu/100==0)
{
liu=23;
}
else
{
liu=jishu/100;
}
if(jishu%100/10==0)
{
qi=23;
}
else
{
qi=jishu%100/10;
}
if(jiemian%10==0)
{
ba=23;
}
else
{
ba=jishu%10;
}
}
if(shuju>=yuzhi*10)
{
a=1;
}
if(a==1)
{
if(shuju<yuzhi*10)
{
jishu=jishu+1;
a=0;
}
}
if(shuju<yuzhi*10)
{
EA=1;
ET0=1;
}
else
{
EA=0;
ET0=0;
}
if(shuju>yuzhi*10)
{
s1=1;
}
if(panding==3)
{
s3=0;
}
if(panding==0)
{
s3=1;
}
EEDA(0x00,yuzhi);
LED();
shumaguan1(yi,er);
shumaguan2(san,si);
shumaguan3(wu,liu);
shumaguan4(qi,ba);
}
}