新手上路
- 积分
- 49
- 金钱
- 49
- 注册时间
- 2015-3-29
- 在线时间
- 0 小时
|
楼主 |
发表于 2015-4-19 21:13:56
|
显示全部楼层
回复【2楼】八度空间:
---------------------------------
#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
uchar num1,b,flag;
uchar code table_2[]="郑更濠";
uchar code table_1[]="44";
uchar data table_3[2];
uchar data table_4[6];
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
sbit sda=P3^5;
sbit scl=P3^6;
sbit key=P3^2;
sbit key1=P3^3;
sbit key2=P3^4;
void delay()
{;;}
void start() //开始信号
{
sda=1;
delay();
scl=1;
delay();
sda=0;
delay();
}
void stop() //停止
{
sda=0;
delay();
scl=1;
delay();
sda=1;
delay();
}
void respons() //应答
{
uchar i;
scl=1;
delay();
while((sda==1)&&(i<250))i++;
scl=0;
delay();
}
void init()
{
sda=1;
delay();
scl=1;
delay();
SCON=0x50;
TMOD=0x20;
TL1=0xFa;
TH1=0XFa;
TR1=1;
ES=1;
EA=1;
num1=44;
}
void write_byte(uchar date)
{
uchar i,temp;
temp=date;
for(i=0;i<8;i++)
{
temp=temp<<1;
scl=0;
delay();
sda=CY;
delay();
scl=1;
delay();
// scl=0;
// delay();
}
scl=0;
delay();
sda=1;
delay();
}
uchar read_byte()
{
uchar i,k;
scl=0;
delay();
sda=1;
delay();
for(i=0;i<8;i++)
{
scl=1;
delay();
k=(k<<1)|sda;
scl=0;
delay();
}
return k;
}
void delay1(uchar x)
{
uchar a,b;
for(a=x;a>0;a--)
for(b=100;b>0;b--);
}
void write_add(uchar address,uchar date)
{
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
write_byte(date);
respons();
stop();
}
uchar read_add(uchar address)
{
uchar date;
start();
write_byte(0xa0);
respons();
write_byte(address);
respons();
start();
write_byte(0xa1);
respons();
date=read_byte();
stop();
return date;
}
void display(uchar shi_h,uchar ge_h)
{
P2=0xfb;
P0=table[ge_h];
delay1(5);
P2=0xf7;
P0=table[shi_h];
delay1(5);
shi_h=num1/10;
ge_h=num1%10;
}
void keyscan()
{
uchar i;
if(key1==0)
{
delay1(5);
if(key1==0)
{
for(i=0;i<2;i++)
{
write_add(0x01+i,table_1);
flag=1;
ES=0;
SBUF=table_3;
delay1(500);
while(!TI);
TI=0;
}
ES=1;
while(!key1);
delay1(500);
while(!key1);
}
}
if(key==0)
{
delay1(5);
if(key==0)
{
for(i=0;i<6;i++)
{
write_add(0x05+i,table_2);
ES=0;
SBUF=table_4;
delay1(500);
while(!TI);
TI=0;
}
ES=1;
while(!key);
delay1(500);
while(!key);
}
}
}
void main()
{
uchar i,t;
init();
for(i=0;i<2;i++)
table_3=read_add(0x01+i);
num1=atoi(table_3);
for(t=0;t<6;t++)
table_4[t]=read_add(0x05+t);
while(1)
{
keyscan();
if(flag==1)
display(num1/10,num1%10);
}
}
void ser()interrupt 4
{
while(RI!=1);
RI=0;
b=SBUF;
}
**************************************************************************************************
这个今晚调出来的 把num1=44换成table_1[]="44"两个字节写进去 然后再把字符串用atoi转换成数字给num1 。程序大部分功能能实现,只不过是名字发到串口助手上还是会有些乱码而已。 |
|