/************************************************************
Experiment name: Clock chip DS12C887 driver program
Crystal oscillator: internal 8M
Wiring method:
1. PD port connects to DS12C887 data I/O port
2. PA port connects to DS12C887 control port
Instructions for use:
This program can read and write DS12C887
**************************************************************/
#include
#include
#define uchar unsigned char
#define CS_H PORTA|=BIT(PA5)
#define CS_L PORTA&=~BIT(PA5)
#define AS_H PORTA|=BIT(PA4)
#define AS_L PORTA&=~BIT(PA4)
#define R_H PORTA|=BIT(PA3)
#define W_L PORTA&=~BIT(PA3)
#define DS_H PORTA|=BIT(PA2)
#define DS_L PORTA&=~BIT(PA2)
void delay(int k) //delay
{
int i;
for(i=0;i;
}
void init_ds12887() //initialize DS12C887
{
DDRA=0xff; //control port
DDRD=0xff; //data port
delay(10);
R_H ;
delay(10);
DS_H;
delay(10);
DS_L;
delay(10);
AS_L;
delay(10);
AS_H;}
void write_ds12887(uchar addr,uchar data)//向DS12C887写入数据
{
init_ds12887();
PORTD=addr;
CS_L;
delay(10);
AS_L;
delay(10);
W_L ;
delay(10);
DS_H;
PORTD=data;
delay(10);
DS_L;
delay(10);
AS_H;
delay(10);
CS_H;
}
uchar read_ds12887(uchar addr)//从DS12C887读出数据
{
uchar data;
init_ds12887();
CS_L;
delay(10);
PORTD=addr;
AS_L;
delay(10);
R_H ;
PORTD=0x00;
DDRD=0x00;
delay(10);
DS_H;
delay(10);
data=PIND;
return data;
DS_L;
delay(10);
AS_H;
delay(10);
CS_H;
}
Previous article:DS1302 driver (automatic adjustment of days in common and leap years)
Next article:ISD2560 recording and playback control program
Recommended ReadingLatest update time:2024-11-15 14:53
- Popular Resources
- Popular amplifiers
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- Modern Product Design Guide
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- [Me and Yatli] + First acquaintance
- TI's new automotive linear LED driver TPS92613-Q1 with enhanced heat dissipation
- Do you need to persist?
- What are the common reasons for LED errors?
- Need help choosing safer lithium batteries?
- STM32H743IIT6 core board schematic diagram
- [BearPi-HM Nano, play Hongmeng "touch and go"] Part 1: Unboxing summary
- AD9 usage issues
- TI Blog - Tips for Debugging Audio Amplifiers
- How is the 4-20mA output circuit of a pressure sensor or temperature sensor usually implemented?