Code
Code
H>
#include <intrins.h>
#define SDA
#define SCK
#define DATA
#define SH_CP
#define ST_CP
#define coloum
of coloums
#define speed
speed hi & vice versa
#define extend
size
#define Device_Address
#define status
P3_7
P3_6
P3_2
P3_3
P3_4
145
2
208
//Maximum buffer
0xA0
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
!
"
#
$
%
&
'
(
)
*
+
,
.
/
0
1
2
3
4
5
6
7
8
9
:
;
<
=
>
?
@
A
B
C
D
E
F
G
H
I
{0x04,0x02,0x02,0x7c,0x00},
{0x7e,0x18,0x24,0x42,0x00},
{0x7e,0x02,0x02,0x02,0x00},
{0x7e,0x30,0x30,0x7e,0x00},
{0x7e,0x30,0x0c,0x7e,0x00},
{0x3c,0x42,0x42,0x3c,0x00},
{0x7e,0x48,0x48,0x30,0x00},
{0x3c,0x46,0x42,0x3d,0x00},
{0x7e,0x48,0x4c,0x32,0x00},
{0x24,0x52,0x4a,0x24,0x00},
{0x00,0x40,0x7e,0x40,0x00},
{0x7c,0x02,0x02,0x7c,0x00},
{0x78,0x06,0x06,0x78,0x00},
{0x7e,0x0c,0x0c,0x7e,0x00},
{0x66,0x18,0x18,0x66,0x00},
{0x00,0x70,0x0e,0x70,0x00},
{0x46,0x4a,0x52,0x62,0x00},
{0x00,0x7e,0x42,0x42,0x00},
{0x20,0x10,0x08,0x04,0x00},
{0x00,0x42,0x42,0x7e,0x00},
{0x00,0x20,0x40,0x20,0x00},
{0x02,0x02,0x02,0x02,0x00},
{0x00,0x40,0x20,0x00,0x00},
{0x0c,0x12,0x14,0x1e,0x00},
{0x7e,0x12,0x12,0x0c,0x00},
{0x0c,0x12,0x12,0x00,0x00},
{0x0c,0x12,0x12,0x7e,0x00},
{0x0c,0x16,0x1a,0x08,0x00},
{0x08,0x3e,0x48,0x20,0x00},
{0x0a,0x15,0x15,0x19,0x00},
{0x7e,0x10,0x10,0x0e,0x00},
{0x00,0x12,0x5e,0x02,0x00},
{0x00,0x02,0x01,0x5e,0x00},
{0x7e,0x08,0x14,0x02,0x00},
{0x00,0x42,0x7e,0x02,0x00},
{0x1e,0x08,0x18,0x0e,0x00},
{0x1e,0x10,0x10,0x0e,0x00},
{0x0c,0x12,0x12,0x0c,0x00},
{0x1f,0x12,0x12,0x0c,0x00},
{0x0c,0x12,0x12,0x1f,0x00},
{0x1e,0x10,0x10,0x08,0x00},
{0x0a,0x1a,0x16,0x14,0x00},
{0x10,0x7c,0x12,0x02,0x00},
{0x1c,0x02,0x02,0x1e,0x00},
{0x00,0x1c,0x02,0x1c,0x00},
{0x1e,0x06,0x06,0x1e,0x00},
{0x12,0x0c,0x0c,0x12,0x00},
{0x18,0x05,0x02,0x1c,0x00},
{0x12,0x16,0x1a,0x12,0x00},
{0x00,0x10,0x3c,0x42,0x00},
{0x00,0x00,0x7e,0x00,0x00},
{0x00,0x42,0x3c,0x10,0x00},
{0x20,0x40,0x20,0x40,0x00},
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
J
K
L
M
N
O
P
Q
R
S
T
U
V
W
X
Y
Z
[
"\"
]
^
_
`
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
{
|
}
~
};
code unsigned char reply[]="Press RESET button if display don't start automatica
lly\r\n\0";
code unsigned char prcs[]= "Processing...\r\n\0";
unsigned char pwcount;
// when it is confirm th
at SCK is low
delay(1);
SDA = 0;
delay(1);
SCK = 1;
delay(1);
SDA = 1;
delay(1);
delay(100);
}
void I2C_Send_NACK(void)
{
SCK = 0;
at SCK is low
delay(1);
SDA = 1;
delay(1);
SCK = 1;
delay(1);
}
at SCK is low
delay(1);
SDA=((Byte<<i)&0x80);
SCK = 1;
}
SCK = 0;
delay(1);
SDA = 1;
delay(1);
SCK = 1;
delay(1);
return SDA;
}
unsigned char I2C_read_byte(void)
{
unsigned char i, d, RxData = 0;
for(i=0;i<8;i++)
{
SCK = 0;
SCK pin low
delay(1);
SDA = 1;
drive SDA
delay(1);
// Make
// Don't
SCK = 1;
// Make
// Capture R
eceived Bit
RxData = RxData|(d<<(7-i));
delay(1);
// Copy it in RxData
}
return RxData;
ed byte
}
// Return receiv
//wait u
I2C_write_byte((unsigned char)Address);
//write address lower byte
I2C_write_byte(Data);
//write data byte
I2C_Stop();
//stop i2c communication
}
void I2C_Send_ACK(void)
{
SCK = 0;
// Make SCK pin low
delay(1);
// when it is confirm that SCK is low
SDA = 0;
// Make SDA Low
delay(1);
SCK = 1;
// Make SCK pin high
delay(1);
}
void read_bytes(unsigned int Address, unsigned char pData[], unsigned int NoOfBy
tes)
{
unsigned int i;
I2C_Start();
// Start i2c communication
while(I2C_write_byte((Device_Address|((Address>>7) & 0x000E)))) //wait u
ntill device is free
{I2C_Start();}
I2C_write_byte((unsigned char)Address);
// Write Address lower byte
I2C_ReStart();
// Restart i2c
I2C_write_byte((Device_Address | 1)|((Address>>7) & 0x000E));
pData[0] = I2C_read_byte();
// Read First byte from EEPROM
for(i=1;i<NoOfBytes;i++)
// Read NoOfBytes
{
I2C_Send_ACK();
// Give Ack to slave to start receiving next byte
pData[i] = I2C_read_byte();
// Read next byte from EEPROM
}
I2C_Send_NACK();
SDA=0;
delay(1);
SDA=1;
delay(1);
}
void Write_data(unsigned int Address,unsigned char pData,unsigned char NoOfBytes
)
{
unsigned char i;
I2C_Start();
// Start i2c communication
}
}
RI=0;
}
else RI=0;
}
void putc(unsigned char oho)
{
SBUF=oho;
while(TI==0);
TI=0;
}
void puts(unsigned char sdata[])
{
unsigned char i=0;
while(sdata[i]!='\0')
{
putc(sdata[i]);
i++;
}
}
void save_location()
{
l=eeprom;
write_byte(0x07FE,l>>8);
delay(50);
write_byte(0x07FF,(unsigned char)l);
delay(50);
}
void get_location()
{
l=read_byte(0x07FE);
l=(l<<8);
l=l+read_byte(0x07FF);
}
void eeprom_data(char eedata)
{
if(eedata<='~' && eedata>=' ')
{
Write_data(eeprom,eedata-' ',5);
eeprom=eeprom+6;
}
}
void eeprom_save(char edata[])
{
unsigned int i3=0;
while(edata[i3]!='\r')
{
eeprom_data(edata[i3]);
putc(edata[i3]);
i3++;
}
}
}
void latch()
{
ST_CP=1;
ST_CP=0;
}
void blank(unsigned int Address)
{
unsigned char j;
I2C_Start();
// Start i2c communication
while(I2C_write_byte((Device_Address|((Address>>7) & 0x000E)))) //wait u
ntill device is free
{I2C_Start();}
I2C_write_byte((unsigned char)Address);
// Write Address lower byte
for(j=0;j<coloum;j++)
// Write NoOfBytes
{
I2C_write_byte(0x00);
Address++;
if(Address%16==0)
{
I2C_Stop();
delay(5);
I2C_Start();
// Start i2c communication
while(I2C_write_byte((Device_Address|((Address>>7) & 0x0
00E)))) //wait untill device is free
{I2C_Start();}
I2C_write_byte((unsigned char)Address);
// Write Address lower byte
}
}
// Write data byte
I2C_Stop();
delay(5);
eeprom=eeprom+coloum;
}
void display(char line,char ud)
{
unsigned char j;
for(j=0;j<coloum;j++)
{
DSend(buffer[j] & ud);
}
P2=0xFF;
latch();
P2=~line;
}
void serial_init()
//Initialization of serial commu
nication and interrups
{
SCON = 0x50;
/* mode 1, 8-bit uart, enable receiver *
/
TMOD = 0x20;
/* timer 1, mode 2, 8-bit reload */
TH1 = 0xFD;
/* reload value for 9600 baud */
TR1 = 1;
/* start the timer */
IE = 0x90;
/* 1001 0000 enable serial inter
rupt*/
}
void show_time()
{
unsigned char j;
for(j=0;j<speed;j++)
{
display(0x40,0x02);
display(0x20,0x04);
display(0x10,0x08);
display(0x08,0x10);
display(0x04,0x20);
display(0x02,0x40);
display(0x01,0x80);
}
buffer[coloum]=read_byte(eeprom+coloum);
eeprom++;
if(eeprom>=l)
{eeprom=0x0000;}
for(j=0;j<coloum;j++)
{buffer[j]=buffer[j+1];}
}
void main()
{
serial_init();
InitI2C();
puts("Author : P.J.Suthar\r\n\0");
status=0;
pwcount=0;
eeprom=0x0000;
delay(1000);
while(1)
{
while(status==0)
{
get_location();
read_bytes(eeprom,buffer,coloum);
eeprom=0x0000;
status=1;
}
while(status==10)
{
eeprom=0x0000;
blank(eeprom);
eeprom_save(reply);
blank(eeprom);
read_bytes(0x0000,buffer,coloum);
IE=0x90;
status=1;
eeprom=0;
}
while(status==2)
{
eeprom=0x0000;
blank(eeprom);
puts(prcs);
eeprom_save(buffer);
puts("\r\n\0");
save_location();
blank(eeprom);
read_bytes(0x0000,buffer,coloum);
eeprom=0;
puts("Done\r\n\0");
puts(reply);
IE=0x90;
status=1;
}
while(status==1)
{
show_time();
}
}
}