One, DS1302 write time read out the time is hexadecimal, need to convert to decimal
It should be in hexadecimal.
WP write protection bit, register write address 0x8e,1 for write protection, prohibit write. 0 release
CH (clock halt) clock stop bit, register write address 0x80,1 to stop, 0 is normal.
(Year register can only be 00-99, note 20 need to write yourself)
Month and day when the register must be written in decimal to hexadecimal.
It is best to follow the date of the month and the second sequence, the last write seconds, while modifying the second register CH bit to turn on the clock
Turn write protection back on
Second, read the time
No need to change the read-write address, in the operation timing has changed, just put in an address.
Roughly the same as write time, no pause and write protection, and hex to decimal is required
Two 18b20 timing operation problems
(temperature display is not normal, usually timing, delay, return value is not correct)
1. Call the official library and modify the official self-timer function to the STC delay Calculator Generation 15! Microsecond code replacement, 18b20 normal ... Remember 15μs
2. Self-written temperature conversion process function,
(1) Initialize INIT18B20 (call library)
(2) Writing section (Call library) Write_18b20 (0XCC) Skip ROM
(3) Writing section Write_18b20 (0x44) Convert T
(4) (can be delayed)
(5) Writing section write_18b20 (0XCC) skip ROM
(6) Writing section write_18b20 (0xbe) Read data command
(7) After reading the data command, the first second byte is sent back immediately, respectively, low LSB high MSB
read_ DS18B20 (call library) Read convert now OK.
IIC Device Communication
AT2401 just write cannot be read at once, interval (100ms) required
(written with child address device reader) period address, storage address
Write.
1. Start the IIC bus
2. Write the period address, according to the different A0 A1 A2 method to determine the address.
3. Wait for the device to be sent to answer,
4. Write to storage address
5. Wait for the device to send a response
6. Can (continuous) write data into the EEPROM. The format is, write a data, wait for the answer, write down a data, wait for the answer ....
7. Stop the Bus
Read. Random Read
1. Start the IIC bus
2. Write the period address, according to the different A0 A1 A2 method to determine the address.
3. Wait for the device to be sent to answer,
4. Write to storage address
5. Wait for the device to reply (the read pointer is set here)
6. Restart the IIC bus
7. The sending device address (+1) changes the write to read state.
8. The data in the EEPROM can be read (continuously). The format is, read a data, send the active answer bit indicates request to continue to read the data, read the next data, send the active answer bit ....
9. After reading the last data, send the non-reply, telling the device not to need to read the data.
10. Stop the Bus
PCF8591
Adc.
1. Start the IIC bus
2. Write the device address. Write state
3. Wait for the device to answer.
4. Write the control word. Be sure to allow the analog output to select the channel. 0x40| ANx ...
5. Wait for the device to answer (the ADC is configured here)
6. Restart the IIC bus
7. Write the device address (+1) Read State
8. Wait for the device to answer
9. Read the ADC data,
10. Unsolicited non-response bit, indicating no need to read data
11. Stop the IIC bus.
Dac!
1. Start the IIC bus
2. Write the device address, write status
3. Wait for the device to answer
4. Write control word, allow analog output 0x40
5. Wait for the device to answer
6. Continue to write the data, indicating that the data is sent to the DAC in the conversion.
7. Wait for the answer bit.
8. Stop the bus.
The dynamic display of the digital tube.
Set timer 0 th0= (65536-2000)/256; tl0= (65536-2000)%256; 2ms Refresh Once
Display function, set static variable i
P0 value blanking open segment latch closed segment latch xbyte[0xe000]=0xff;
P0 Send bit code [i] open bit latch off bit latch xbyte[0xc000]=seg_wei[i];
P0 send segment code [i] open segment latch closed segment latch xbyte[0xe000]=seg_duan[i];
i++
I==8 zeroing
Matrix keyboard Scan. P44 P42 P35 P34 P33 P32 P31 P30
1. Place the started playing against position high. oxf0 attention will P44 P42 also to change simultaneously
2. if (p3!=0xf0| p42!=1| P44!=1) detects if a button is pressed.
3. Time-lapse detection (the above process proves that the button is pressed)
4. Start progressive Scan, Oxfe oxfd Oxfb,oxf7, scan four lines respectively
5. To determine if the line has a key pressed, get the key value temp= ((((p4<<3)) |0x7f) & ((p4<<4) |0XBF)) &p3
6, wait for the button to let go,
7. Return the key value
SCI Serial Communication
Using the ISP baud rate Calculator Serial 1 counter 1 8-bit auto reload 12T speed generate code SFR auxr=ox8e baud rate transmitter complete
Write your own byte send, string function, note software zeroing