PCF8563 clock program
#include
#include
#define byte unsigned char
sbit scl=0x81; //define serial I/O port
sbit sda=0x80;
idata byte rom_sed[9];
idata byte rom_rec[7];
idata byte j,k;
bit flag,flag1;
void delay(void) //delay subroutine
{
data byte i;
for(i=0;i<6;i++);
}
void I_start(void) //Send I2C bus start condition subroutine
{
sda=1;
;
scl=1;
delay();
sda=0;
delay();
scl=0;
;
}
void I_stop(void) //I2C bus stop condition subroutine
{
sda=0;
;
scl=1;
delay();
sda=1;
delay();
}
bit I_send(byte I_data) //Byte data transmission subroutine
{
data byte i;
for(i=0;i<8;i++)
{
sda=(bit)(I_data&0x80); ;
scl =0; delay(); scl = 1; ; ; //Prepare to receive ACK bit scl=1 ; ; ; //Start receiving ack bit flag=0; if(sda==0)flag=0; else flag=1; //Return(~I_c LOC k()); scl=0; return(flag); } byte I_receive(void) //Byte data receiving subroutine { data byte i; byte I_data=0; sda=1; for(i=0;i<8;i++) { I_data*=2; ; scl=0; delay(); scl=1; ; ; if(sda==1)I_data++; ; ; } scl=0; ; ; ; sda=0; if(flag1==0) //Not the last ACK { ; ; scl=1; delay (); scl = 0; } else //This is the last ACK { sda =1; ; sed[3]=0x55; rom_sed[4]=0x23; rom_sed[5]=0x31; rom_sed [ 6 ] = 0x06 ; rom_sed [7]=0x92; rom_sed[ 8]=0x99; for(i=0;i<255;i++)delay(); I_start(); if(~I_send(0xa2)) //pcf_ write address { if(~I_send(0x02)) //pcf_status register address { for(i=0;i<9;i++) {
if(~I_send(rom_sed[i]));
else;
}
I_stop();
}
else;
}
else;
start: I_start();
if(~I_send(0xa2)) // pcf_write地址
{
if(~I_send(0x02)) // pcf_status寄存器地址
{
I_start();
if(~I_send(0xa3)) //写状态寄存器
{
for(i=0;i<7;i++)
{
if(i==6)
flag1=1;
else
flag1=0;
rom_rec[i]=I_receive();
switch(i)
{
case 1:rom_rec[i]=rom_rec[i]&0x7f;break;
case 2:
case 3:rom_rec[i]=rom_rec[i]&0x3f;break;
case 4:rom_rec[i]=rom_rec[i]&0x07;break;
case 5:rom_rec[i]=rom_rec[i]&0x9f;break;
default:break;
}
}
I_stop();
}
}
}
goto start;
}
Previous article:LCD Thermometer Program
Next article:12864 LCD graphic display program without font library
Recommended ReadingLatest update time:2024-11-16 13:58
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- EEWORLD University----[High Precision Laboratory] Interface: RS-485
- 【Perf-V Review】VIVADO Flowing Light
- Newbie, please help me with CPLD frequency multiplication
- [The third stop of Shijian’s ADI journey] Learn about cutting-edge IoT devices and solutions, and win Kindle and other gifts
- Are there any netizens working in the field of motors?
- Evaluation report summary: Mir MYS-8MMX
- 2020 Share the beauty of Qingdao in my eyes
- Zigbee Technology Exchange
- ST's new 400W power board
- Allwinner V853+XR829 Tina wireless network wifimanger2.0 user guide