📄 main.c
字号:
#include <REG52.h>
#include <intrins.h>
#include <math.h>
#include <absacc.h>
#define C_ADD XBYTE[0xD000] //指令口地址
#define D_ADD XBYTE[0xD001] //数据口地址
#define PARA1 0x0A0 //80个字节/行
sbit SCL= P1^3 ;
sbit SDA= P1^4 ;
unsigned char xdata ppp[10] ={10,0xaa,30,40,50,60,70,80,90,100} ;
unsigned char xdata ppp[10] _at_ 0x00;
void clear();
void ccw_pr(unsigned int x,unsigned int y,unsigned int g);
void cc24pr(unsigned int s,unsigned int d ,unsigned int h);
void cw_pr(unsigned int m,unsigned int n, unsigned int d);
void w_dot(unsigned int x ,unsigned int y );
void cl_dot(unsigned int x,unsigned int y);
void onebyte_pr(unsigned int x,unsigned int y,unsigned int dataa);
void clcw_pr(unsigned int x, unsigned int y);
void clonebyte_pr(unsigned int x,unsigned int y);
void WriteIns(unsigned char d);
void WriteData(unsigned int,unsigned int ,unsigned int,unsigned int );
void cw_prr(unsigned int m,unsigned int n, unsigned int d);
void clcw_prr(unsigned int m,unsigned int n);
extern data unsigned char GRAYB;
unsigned int G_INSNUM;
void writeins(unsigned char d){
switch(d)
{case 12: /*8*8 英文*/
G_INSNUM=1;
break;
case 15:
G_INSNUM=2; /* 写点 */
break;
case 1: /*16*16汉文*/
G_INSNUM=3;
break;
case 2: /*擦一个字节*/
G_INSNUM=4;
break;
case 3: /*擦点*/
G_INSNUM=5;
break;
case 4: /*擦8*8英文*/
G_INSNUM=6;
break;
case 5: /*写一个字节*/
G_INSNUM=7;
break;
case 6: /*擦8*8字符*/
G_INSNUM=8;
break;
case 7: /*24*24汉文*/
G_INSNUM=9;
break;
case 8: /*16*8英文*/
G_INSNUM=10;
break;
case 9: /*擦16*8字符*/
G_INSNUM=11;
break;
default: break;
}
}
void WriteData(unsigned int x,unsigned int y,unsigned int dataa,unsigned int disp_type)
{
switch(disp_type) /*disp_type最高位是正显反显,最低位是灰显还是亮显*/
{
case 0x00: /*反显灰显*/
{
GRAYB=0X80;
break;
}
case 0x01: /*反显亮显*/
{
GRAYB=0XC0;
break;
}
case 0x80: /*正显灰显*/
{
GRAYB=0X08;
break;
}
case 0x81: /*正显亮显*/
{
GRAYB=0X0C;
break;
}
default:
break;
}
switch(G_INSNUM){
case 1:
{
cw_pr(x,y,dataa);
break;
}
case 2:
{
w_dot(x,y);
break;
}
case 3:
{
ccw_pr(x,y,dataa);
break;
}
case 4:
{
clonebyte_pr(x,y);
break;
}
case 5:
{
cl_dot(x,y);
break;
}
case 6:
{
clcw_pr(x,y);
break;
}
case 7:
{
onebyte_pr(x,y,dataa);
break;
}
case 8:
{
clcw_pr(x,y);
break;
}
case 9:
{
cc24pr(x,y,dataa);
break;
}
case 10:
{
cw_prr(x,y,dataa);
break;
}
case 11:
{
clcw_prr(x,y);
break;
}
default:
break;
}
}
void clonebyte_pr(unsigned int x,unsigned int y)
{ onebyte_pr(x,y,0);
}
void Start()
{
SDA=1;
SCL=1;
SDA=0;
SCL=0;
} /*开始的前导符*/
void Stop()
{
SDA=0;
SCL=1;
SDA=1;
SCL=0;
SDA=0;
}
void Send(unsigned char SendData)
{
unsigned char data temp;
unsigned char data i;
SCL=0;
for (i=0;i<8;i++)
{
temp=SendData ;
temp=temp&0x80;
if (temp==0x80) /*bit 7 is 1*/
{
SDA=1;
}
else
{
SDA=0;
}
SCL=1;
SCL=0;
SendData=SendData<<1;
} /* end for i*/
SDA=1;
SCL=1;
while(SDA) {} /*JUDGE WHETHER ACKNOWLEDGE IS OCCUR OR NOT*/
SCL=0;
} /*发送数据*/
void Start_2464(unsigned char rw, /*读或写的标志*/
unsigned char h_addr /*24c256的硬件的编址*/
)
{
unsigned char data byte;
rw&=0x01;
byte=0xa0;
byte|=rw;
h_addr&=0x07; /*get low three bit */
h_addr=h_addr<<1;
byte|=h_addr;
Start();
Send(byte);
}
void ByteWrite_2464( unsigned int addr, /*待发送的数的首址*/
unsigned char senddata) /* 待发送的数 */
{
unsigned char data temp;
Start_2464(0x00,0x00);
temp= addr>>8 ; /*high address */
Send(temp);
temp=addr&0x00ff; /*low address */
Send(temp);
Send(senddata);
Stop();
for (temp=0;temp<0xff ;temp++); /*对于I2C总线而言延时是最重要的,*/
for (temp=0;temp<0xff;temp++) ;
for (temp=0;temp<0xff ;temp++) ; /*对于I2C总线而言延时是最重要的,*/
for (temp=0;temp<0xa0 ;temp++) ; ; /*我们上一次就因为这个部分而吃亏*/
}
char Get_2464 () /*获取一个字节的数据*/
{
unsigned char data getdata;
unsigned char data cycle;
getdata=0x00;
for (cycle=0;cycle<8;cycle++) /*一共要接受8个字节的数据*/
{
getdata=getdata<<1;
SCL=1;
if (SDA) /*SDA=1*/
{
getdata|=0x01;
}
else /*SDA=0*/
{
getdata|=0x00;
}
SCL=0;
} /*end for cycle*/
return getdata;
}
void SequentialRead_2464( unsigned int addr , /*存放数据的首址,读取的数据全部存储到外部的数据存储器*/
unsigned int num) /*读取数据的字节数*/
{
unsigned int data cycle;
unsigned char data senddata;
Start_2464(0X01,0X00);
for (cycle=0;cycle<num;cycle++)
{
senddata=Get_2464();
XBYTE[addr]=senddata; /*送到外部的数据存储器*/
addr++;
if(cycle==num-1) /*the last byte data need not ACK*/
{
SDA=1;
SCL=1;
SCL=0; /*NOACK*/
Stop();
break;
}
SDA=0; /*ACK*/
SCL=1; /*ACK*/
SCL=0; /*ACK*/
SDA=1; /*ACK*/
} /*end for cycle*/
}
void RandomRead_2464(unsigned int waddr,/*读取的数据放到外部的数据存储器waddr就是外部的数据存储器的地址*/
unsigned int raddr,/*raddr就是数据从24C64的哪个地址开始*/
unsigned int num /*读取数据的字节数*/
)
{
unsigned int data cycle;
unsigned char data senddata;
Start_2464(0x00,0x00);
senddata= raddr>>8 ; /*high address */
Send(senddata);
senddata=raddr&0x00ff; /*low address */
Send(senddata);
{
Start_2464(0X01,0X00);
for (cycle=0;cycle<num;cycle++)
{
senddata=Get_2464();
XBYTE[waddr]=senddata; /*送到外部的数据存储器*/
waddr++;
if(cycle==num-1) /*the last byte data need not ACK*/
{
SDA=1;
SCL=1;
SCL=0; /*NOACK*/
Stop();
break;
}
SDA=0; /*ACK*/
SCL=1; /*ACK*/
SCL=0; /*ACK*/
SDA=1; /*ACK*/
} /*end for cycle*/
}
}
main()
{
unsigned int i;
ByteWrite_2464( 0X00 , 0X80 );
RandomRead_2464(0x20 , 0x00 ,1 );
clear();
WriteIns(0x07);
WriteData(0x00,0x00,0x01,0X00);
WriteData(0x00,0x30,0x01,0X01);
WriteData(0x00,0x60,0x01,0X80);
WriteData(0x00,0x90,0x01,0X81);
i=XBYTE[0X101];
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -