📄 新建 文本文档 (2).txt
字号:
#include <REG51.H>
#include <intrins.H>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar ACT[4]={0xfe,0xfd,0xfb,0xf7};
sbit SDA=P3^7;
sbit SCL=P3^6;
sbit key1=P3^2;
sbit key2=P3^3;
sbit key3=P3^4;
sbit key4=P3^5;
sbit P10=P0^0;
sbit P11=P0^1;
bdata char com_data;
sbit mos_bit=com_data^7;
sbit low_bit=com_data^0;
uchar cnt,x;
void delay_iic(int n);
uchar rd_24c01(char a);
void wr_24c01(char a,char b);
/***************************************/
void init(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EA=1;
}
/*
uchar scan_key(void)
{
uchar temp;
temp=P3;
return temp;
}
*/
void delay(uint k)
{
uint data i,j;
for(i=0;i<k;i++)
{for(j=0;j<121;j++)
{;}}
}
/******************************/
uchar count;
void main(void)
{ P1=0;
init();
while(1)
{
P2=SEG7[count];
}
}
/************************************/
void time0(void) interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
if(key1==0)
{
count++;
if(count==10)
{count=0;}
while(!key1);
P10=~P10;
}
if(key2==0)
{
count--;
if(count==0)
{count=9;}
while(!key2);
P11=~P11;
}
if(key3==0)
{
// EA=0;
wr_24c01(10,count);
delay_iic(250);
// EA=1;
while(!key3);
P1=0x04;
}
if(key4==0)
{
// EA=0;
count=rd_24c01(10);
delay_iic(250);
// EA=1;
while(!key4);
P1=0x08;
P2=SEG7[count];
}
}
/**************************************/
void start()
{
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=1;_nop_();_nop_();_nop_();_nop_();
SDA=0;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
}
//*****************************************
void stop()
{
SDA=0;_nop_();_nop_();_nop_();_nop_();
SCL=1;_nop_();_nop_();_nop_();_nop_();
SDA=1;_nop_();_nop_();_nop_();_nop_();
}
//***********************
void ack()
{
SCL=1;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
}
//***********************
void shift8(char a)
{
data uchar i;
com_data=a;
for(i=0;i<8;i++)
{
SDA=mos_bit;
SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
com_data=com_data*2;
}
}
//******************
uchar rd_24c01(char a)
{
data uchar i,command;
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
start();
command=160;
shift8(command);
ack();
shift8(a);
ack();
start();
command=161;
shift8(command);
ack();
SDA=1;_nop_();_nop_();_nop_();_nop_();
for(i=0;i<8;i++)
{
com_data=com_data*2;
SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
low_bit=SDA;
SCL=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
stop();
return(com_data);
}
//*****************
void wr_24c01(char a,char b)
{
data uchar command;
_nop_();_nop_();_nop_();_nop_();_nop_();
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
start();
command=160;
shift8(command);
ack();
shift8(a);
ack();
shift8(b);
ack();
stop();
_nop_();_nop_();_nop_();_nop_();_nop_();
}
//***************
void delay_iic(int n)
{
int i,j;
for(i=1;i<n;i++)
{;}
}
#include <REG51.H>
#include <intrins.H>
#define uchar unsigned char
#define uint unsigned int
uchar code SEG7[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar ACT[4]={0xfe,0xfd,0xfb,0xf7};
sbit SDA=P3^7;
sbit SCL=P3^6;
sbit key1=P3^2;
sbit key2=P3^3;
sbit key3=P3^4;
sbit key4=P3^5;
sbit P10=P0^0;
sbit P11=P0^1;
bdata char com_data;
sbit mos_bit=com_data^7;
sbit low_bit=com_data^0;
uchar cnt,x;
void delay_iic(int n);
uchar rd_24c01(char a);
void wr_24c01(char a,char b);
/**************************************
void init(void)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
ET0=1;
TR0=1;
EA=1;
} */
/*
uchar scan_key(void)
{
uchar temp;
temp=P3;
return temp;
}
*/
void delay(uint k)
{
uint data i,j;
for(i=0;i<k;i++)
{for(j=0;j<121;j++)
{;}}
}
/******************************/
uchar count;
void main(void)
{ P1=0;
while(1)
{
P2=SEG7[count];
if(key1==0)
{
count++;
if(count==10)
{count=0;}
while(!key1);
P10=~P10;
}
if(key2==0)
{
count--;
if(count==0)
{count=9;}
while(!key2);
P11=~P11;
}
if(key3==0)
{
wr_24c01(10,count);
delay_iic(250);
while(!key3);
P1=0x04;
}
if(key4==0)
{
count=rd_24c01(10);
delay_iic(250);
while(!key4);
P1=0x08;
P2=SEG7[count];
}
}
}
/**************************************/
void start()
{
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=1;_nop_();_nop_();_nop_();_nop_();
SDA=0;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
}
//*****************************************
void stop()
{
SDA=0;_nop_();_nop_();_nop_();_nop_();
SCL=1;_nop_();_nop_();_nop_();_nop_();
SDA=1;_nop_();_nop_();_nop_();_nop_();
}
//***********************
void ack()
{
SCL=1;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
}
//***********************
void shift8(char a)
{
data uchar i;
com_data=a;
for(i=0;i<8;i++)
{
SDA=mos_bit;
SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
com_data=com_data*2;
}
}
//******************
uchar rd_24c01(char a)
{
data uchar i,command;
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
start();
command=160;
shift8(command);
ack();
shift8(a);
ack();
start();
command=161;
shift8(command);
ack();
SDA=1;_nop_();_nop_();_nop_();_nop_();
for(i=0;i<8;i++)
{
com_data=com_data*2;
SCL=1;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
low_bit=SDA;
SCL=0;_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
}
stop();
return(com_data);
}
//*****************
void wr_24c01(char a,char b)
{
data uchar command;
_nop_();_nop_();_nop_();_nop_();_nop_();
SDA=1;_nop_();_nop_();_nop_();_nop_();
SCL=0;_nop_();_nop_();_nop_();_nop_();
start();
command=160;
shift8(command);
ack();
shift8(a);
ack();
shift8(b);
ack();
stop();
_nop_();_nop_();_nop_();_nop_();_nop_();
}
//***************
void delay_iic(int n)
{
int i,j;
for(i=1;i<n;i++)
{;}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -