#include<STC12C5A60S2.H>
#define uchar unsigned char
#define uint unsigned int
#define dashuchu P3
sbit dacs = P1^1;
sbit dawr = P1^2;
sbit WE = P1^3;
sbit OE = P1^4;
sbit key1 = P1^6;
uchar date,addr1,addr2;
void delay(uint z) //delay 1ms
{
uint x,y;
for(x=z;x>0;x--)
for(y=124;y>0;y--);
}
unsigned char ad()
{
ADC_CONTR=0xC0; //开 A/D 转换
电源,选择AD速度
P1ASF=0x00; //选择 P1.0 作为 A/D 转换通道
ADC_CONTR|=0x08; //启动 A/D 转换
while((ADC_CONTR&0x10)==0); //等待 A/D 转换结束
ADC_CONTR&=0xE7; //将 ADC_FLAG 清 0
return(ADC_RES); //保存 A/D 转换结果
}
/*void DAC0832()
{
dacs = 0;
dawr = 0;
//P2=ad();
} */
void write_62256()
{
WE=0;
//OE=1; //62256写选通
addr1=0;
addr2=0;
for(addr1=0;addr1<=255;addr1++)
{
P0=addr1;
P3=addr2;
OE=0;
P2=ad();
delay(5);
OE=1;
}
if(addr1==256)
{
for(addr2=0;addr2<=127;addr2++)
{
P0=addr1;
P3=addr2;
OE=0;
P2=ad();
delay(5);
OE=1;
}
}
}
void read_62256()
{ dacs=0;
dawr=0;
OE=0;
//WE=1;
addr1=0;
addr2=0;
for(addr1=0;addr1<=255;addr1++)
{
P0=addr1;
P3=addr2;
WE=1;
//P2=date;
delay(5);
WE=0;
}
if(addr1==256)
{
for(addr2=0;addr2<=127;addr2++)
{
P0=addr1;
P3=addr2;
WE=1;
// P2=date;
delay(5);
WE=0;
}
}
}
void jianpan() //按键扫描
{
if(key1==1)
write_62256();
if(key1==0)
read_62256();
}
void main()
{
while(1)
{
jianpan();
}
}
一周热门 更多>