Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
h>
#include <absacc.h>
#define REG0
XBYTE[0x0000]
//LCD instruction register to write the address,
according to configuration changes
#define REG1
XBYTE[0x0001]
//D0 ~ D7 LCD read data to the address, according to
configuration changes
#define REG2
XBYTE[0x0002]
//LCD write data register address, configuration
changes can
#define REG3
XBYTE[0x0003]
//LCD read data register address, configuration
changes can
unsigned char bdata busyflag;
unsigned char dat,datn;
unsigned char
unsigned char
code unsigned
ROM in curing
code unsigned
ROM in curing
code unsigned
ROM in curing
code unsigned
ROM in curing
char word5[16]={"
Wellcome To "};
sbit busyflag_7=busyflag^7;
sbit p10=P1^0;
sbit p11=P1^1;
sbit p12=P1^2;
sbit p13=P1^3;
sbit p14=P1^4;
sbit p15=P1^5;
sbit p16=P1^6;
sbit p17=P1^7;
//////////////////////////////////////start of IIC ////////////////////////////
#define uchar unsigned char
#define uint unsigned int
#include "reg51.h"
#include "intrins.h"
sbit
sbit
Scl=P3^4;
Sda=P3^5;
//Serial Clock
//Serial Data
}while(BitCounter);
Scl=0;
}
uchar Read(void) /*Read one byte of data, and returns the byte value*/
{
uchar temp=0;
uchar temp1=0;
uchar BitCounter=8;
Sda=1;
do{
Scl=0;
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
Scl=1;
_nop_ ();
_nop_ ();
_nop_ ();
_nop_ ();
if(Sda)
/*If Sda=1;*/
temp=temp|0x01; /*The lowest temp 1*/
else
temp=temp&0xfe; /*Otherwise, the lowest temp clear 0*/
if(BitCounter-1)
{
temp1=temp<<1;
temp=temp1;
}
BitCounter--;
}while(BitCounter);
return(temp);
}
void WrToROM(uchar Data[],uchar Address,uchar Num)//Write a set of data to the AT24C02
in
{
//The first parameter is an array address, data in the AT24C02 in the beginning
of the address, number of data
uchar i=0;
uchar *PData;
PData=Data;
Start();
Send(0xa0);
//A0, A1, A2 earth, solid AT24C02 write address 0XA0
Ack();
Send(Address);
Ack();
for(i=0;i<Num;i++)
{
Send(*(PData+i));
Ack();
}
Stop();
}
void RdFromROM(uchar Data[],uchar Address,uchar Num)//Read out in a set of data to
the AT24C02
//The first parameter is an array address, data in the AT24C02 in the beginning
of the address, number of data
{
uchar i=0;
uchar *PData;
PData=Data;
for(i=0;i<Num;i++)
{
Start();
void rdd()
//Subroutine read data register
{
busy();
dat=REG3;
}
void lcdint()
//LCD initialization subroutine
{
wrc(0x38);
wrc(0x01);
wrc(0x06);
wrc(0x0c);
}
void wrn(unsigned char word[])
//Continuous data write n characters to the LCD data
register
{
unsigned char i;
for(i=0;i<16;i++)
{
wrd(word[i]);
}
}
///////////////////////////////////
void main()
{
unsigned char i;
lcdint();
//
wrc(0x80);
//11
wrn(word1);
wrc(0xc0);
//21
wrn(word2);
while(1)
{
if(p10==0) //P1.0EEPROM
{
for(i=0;i<16;i++)
word1[i]='d';
WrToROM(word1,0x00,16);
wrc(0x80);
wrn(word1);
}
if(p11==0) //P1.1
{
RdFromROM(word2,0x00,16);
WrToROM(word2,0x80,16);
wrc(0x80);
wrn(word1);
wrc(0xc0);
wrn(word2);
}
if(p12==0) //P1.2
{
wrc(0x80);
wrn(word3);
wrc(0xc0);
wrn(word4);
}
if(p13==0) //P1.3
{
wrc(0x80);
wrn(word5);
wrc(0xc0);
wrn(word6);
}
if(p14==0) //P1.4
{
wrc(0x80);
wrn(word3);
wrc(0xc0);
wrn(word4);
}
if(p15==0) //P1.5
{
wrc(0x80);
wrn(word5);
wrc(0xc0);
wrn(word6);
}
if(p16==0)//P1.6
{
wrc(0x80);
wrn(word3);
wrc(0xc0);
wrn(word4);
}
if(p17==0)//P1.7
{
wrc(0x80);
wrn(word5);
wrc(0xc0);
wrn(word6);
}
}
}