Home > other >  Dc12c887 so read values are always 5
Dc12c887 so read values are always 5

Time:03-16

This is the program dc12c887
H # include "clock."
# include "REG52. H"

Sbit DSDS=P2 ^ 5;
Sbit DSRW=P2 ^ 4;
Sbit dsas=P2 ^ 3;
Sbit DSCS=P2 ^ 2;

//write 12 c887 function
Void write_ds (uchar addr, uchar date)
{
DSCS=0;
Dsas=1;
DSDS=1;
DSRW=1;
P0=addr;//write address
Dsas=0;
DSRW=0;
P0=date;//to write data
DSRW=1;
Dsas=1;
DSCS=1;
}

//read 12 c887 function
Uchar read_ds (uchar addr)
{
Uchar ds_date;

Dsas=1;
DSDS=1;
DSRW=1;
DSCS=0;
P0=addr;//write address
Dsas=0;
DSDS=0;
P0=0 XFF;
Ds_date=P0;//read data
DSDS=1;
Dsas=1;
DSCS=1;

Return ds_date;
}


/*
Operation for the first time in 12 c887, initialization register
Configuration of 12 c887 current time (20190716-10:54:07)
12 c887 alarm configuration
*/
Void set_time (void)
{
//to electricity initialization time function for the first time
Write_ds (0, 0);
Write_ds (1, 0);
Write_ds (2, 0);
Write_ds (3, 0);
Write_ds (4, 0);
Write_ds (5, 0);
Write_ds (6, 0);
Write_ds (7, 0);
Write_ds (8, 0);
Write_ds (9, 0);

}

/* electrical set DS12C887 to use for the first time, later don't have to call */
Void init (void)
{
X0a write_ds (0, 0 x20);//open the oscillator
X26 x0b write_ds (0, 0);//set 24 hours model, binary data format
Set_time ();
}
The header file
# # ifndef _CLOCK_H
# define _CLOCK_H

# define uchar unsigned char
# define uint unsigned int

Void init (void);
Uchar read_ds (uchar addr);

# endif

Oled program

# include "oled. H"
//# include "stdlib. H"
# include "oledfont. H"
//# include "delay. H"
//OLED memory
//storage format as below.
//[0] 0 1 2 3... 127
//[1] 0 1 2 3... 127
//[2] 0 1 2 3... 127
//[3] 0 1 2 3... 127
//[4] 0 1 2 3... 127
//[5] 0 1 2 3... 127
//[6] 0 1 2 3... 127
//[7] 0 1 2 3... 127
Void delay_ms (unsigned int ms)
{
Unsigned int a;
While (ms)
{
A=1800;
While (a -);
Ms -;
}
return;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//IIC Start
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void IIC_Start ()
{

OLED_SCLK_Set ();
OLED_SDIN_Set ();
OLED_SDIN_Clr ();
OLED_SCLK_Clr ();
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//IIC Stop
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void IIC_Stop ()
{
OLED_SCLK_Set ();
//OLED_SCLK_Clr ();
OLED_SDIN_Clr ();
OLED_SDIN_Set ();

}

Void IIC_Wait_Ack ()
{

//GPIOB - & gt; CRH & amp;=0 xfff0ffff;//set PB12 to pull on the input mode
//GPIOB - & gt; CRH |=0 x00080000;
//OLED_SDA=1;
//delay_us (1);
//OLED_SCL=1;
//delay_us (50000);
/* the while (1)
{
if(! OLED_SDA)//determine whether receives the OLED reply
{
//GPIOB - & gt; CRH & amp;=0 xfff0ffff;//set PB12 for general push from the output mode
//GPIOB - & gt; CRH |=0 x00030000;
return;
}
}
*/
OLED_SCLK_Set ();
OLED_SCLK_Clr ();
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//IIC Write byte
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Void Write_IIC_Byte (unsigned char IIC_Byte)
{
unsigned char i;
Unsigned char m, da;
Da=IIC_Byte;
OLED_SCLK_Clr ();
for(i=0; i<8; I++)
{
M=da;
//OLED_SCLK_Clr ();
M=m& 0 x80.
If (m==0 x80)
{OLED_SDIN_Set (); }
The else OLED_SDIN_Clr ();
Da=da<1;
OLED_SCLK_Set ();
OLED_SCLK_Clr ();
}


}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//IIC Write Command
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Write_IIC_Command (unsigned char IIC_Command)
{
IIC_Start ();
X78 Write_IIC_Byte (0);//Slave address, SA0=0
IIC_Wait_Ack ();
Write_IIC_Byte (0 x00);//write command
IIC_Wait_Ack ();
Write_IIC_Byte (IIC_Command);
IIC_Wait_Ack ();
IIC_Stop();
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//IIC Write Data
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void Write_IIC_Data (unsigned char IIC_Data)
{
IIC_Start ();
X78 Write_IIC_Byte (0);//D/c #=0; R/w #=0
IIC_Wait_Ack ();
Write_IIC_Byte (0 x40);//write data
IIC_Wait_Ack ();
Write_IIC_Byte (IIC_Data);
IIC_Wait_Ack ();
IIC_Stop();
}
Void OLED_WR_Byte (unsigned dat, unsigned CMD)
{
If (CMD)
{

Write_IIC_Data (dat);

}
The else {
Write_IIC_Command (dat);

}


}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//fill_Picture
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Void fill_picture (unsigned char fill_Data)
{
Unsigned char m, n;
For (m=0; M<8; M++)
{
OLED_WR_Byte (0 xb0 + m, 0);//page0 - page1
OLED_WR_Byte (0 x02, 0);//low column start address
OLED_WR_Byte (0 x10, 0);//high column start address
For (n=0; N<128; N++)
{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related