我爱嵌入式系统

当前位置:首页 > 软件天地 > 业内资讯 > 详细内容
OCMJ4×8C与X25045
发布时间:2009/11/13  阅读次数:1987  字体大小: 【】 【】【

显示"范"
#include<reg51.h>
#include<stdio.h>
#include<intrins.h>
sbit SI=P1^0;
sbit SCK=P1^1;
sbit SO=P1^2;
sbit SCS=P3^5;
sbit E=P1^3;
sbit RS=P1^5;
sbit RW=P1^4;
sbit PSB=P3^4;
sbit RESET=P1^7;
sbit bbc=P0^7;
DELAY();
INPUT(unsigned char I);
DELAY01();
void outbyte(unsigned char outda)
{
unsigned char i,a;
a=outda;
for(i=0;i<8;i++)
               {
                               SCK=0;
                               if(a&0x80)     SI=1;
                               else   SI=0;
                               a<<=1;
                               SCK=1;
               }

}
unsigned char inbyte(void)
{
unsigned char i,a;
               a=0;
               for(i=0;i<8;i++)
               {
                               SCK=1;
                               SCK=0;
                               a<<=1;
                               if(SO)     a++;
               }

               return a;
}
unsigned char read_x25045(unsigned int addr)
{
unsigned char b,a;
bit had;
b=addr;
if(b&0x0100)   had=1;
else                         had=0;
SCK=0;
SCS=0;
a=0x03;
if(had) a|=8;
outbyte(a);
a=b;
outbyte(a);
a=inbyte();
SCK=0;
SCS=1;
return a;
}


INITIL()
{
unsigned char f,g,h;
DELAY();
f=0x30;
INPUT(f);
DELAY01();
g=0x01;
INPUT(g);
DELAY01();
h=0x06;
INPUT(h);
DELAY01();
}
CHK_BUSY()
{
RS=0;
RW=1;
E=1;
while(bbc==1){}
E=0;
}
DISPL(unsigned char DAT)
{
CHK_BUSY();
_nop_();
RS=1;
RW=0;
E=1;
P0=DAT;
_nop_();
DELAY01();
_nop_();
E=0;
_nop_();
P0=0xFF;
}
INPUT(unsigned char I)
{
CHK_BUSY();
_nop_();
RS=0;
RW=0;
E=1;
P0=I;
_nop_();
DELAY01();
_nop_();
E=0;
_nop_();
P0=0xFF;
}
DELAY()
{
int i;
i=1;
while(i<100)
{
i=i++;
}
}
DELAY01()
{
int j;
j=1;
while(j<10)
{
j=j++;
}
}
void main()
{
unsigned int addr,adds;
unsigned char q,j;
unsigned char a,b,c,d,e;
addr=0x0190;

adds=0x0191;

RESET=1;
PSB=1;
RW=0;
INITIL();
a=0x0C;
INPUT(a);
DELAY01();
b=0x01;
INPUT(b);
DELAY01();
q=read_x25045(addr);
d=q;
j=read_x25045(adds);
e=j;
c=0x80;
INPUT(c);
DELAY01();
DISPL(d);
DISPL(e);
DELAY01();
_nop_();
}


  

我要评论
  • 匿名发表
  • [添加到收藏夹]
  • 发表评论:(匿名发表无需登录,已登录用户可直接发表。) 登录状态:未登录
最新评论
所有评论[0]
    暂无已审核评论!

51RTOS.com 版权所有  

Copyright 20006-2009 我爱嵌入式 ( 51RTOS.com ) All rights reserved 沪ICP备09080633号