This practice is intended by the LCD visualize date, time, temperature. The data for the date obtained by the DS1307 device which has a battery and a much more accurate oscillator which has the ATMEGA 328P. This device has a memory NVRAM 56bytes.
On the other hand we have another device to take the temperature called DS1621, which takes us to the room temperature (changeable with arrows).
The aim is to understand the connection protocol I2C which is used by the ATMEGA328P to interact with the devices described above.
Having achieved this, the tutor urges us to keep the program within the first minute in a part of the memory of the DS1307 data on temperature and date. Then follow showing the time until the second minute which will be stored the same data as before but obviously outdated one minute (which
is what happened time). As addition has placed a button that wakes the ATMEGA328P to not let frezee.
To end the tutor ordered it done physically, ie in reality, for this we have the above items.
To give a twist, wants to load up the program through a device called a programmer in this case is the ATMEL AVR. Once the process is finished loading addition to checking for correct operation, wants to load up the bootloader with the developer this is due to loading the program eliminated the bootloader and we could not load more programs through the IDE USB (standard practice).
First we make the circuit as shown in the following image.
Returning to explain in brief the method to follow and operation of the SPI protocol and how to save data in memory.
This practice is to date the LCD visualize, time, temperature. To do this we will read through the I2C protocol to watch and temperature sensor. Save NVRAM this data at intervals of one minute each and sleeping ATMEGA328P.
When we look NVRAM DS1307 will have some data, the first are second followed by minutes time, day of the week (1 being Sunday), day, month, year, followed by 00 (SQWE control)and starts at 08H NVRAM that will keep the data as we have indicated by code below.
We also have the I2C debugger in proteus that helps us visualize the Protocol were communication,begins with a start bit or start of the transmission, followed by a control code of 4 bits here are three bit of your host device Seleción another bit read or write and a recognition and for transmission. This would only be for communication, if the slave responds as appropriate.
Repetitive use another start control the choice of dispositvo, read or write, and stop transmission acknowledgment.
Then we explain the Sketch.
Include the libraries.
Statement of objects and variables.
We started the elements and determine the size of 16x2 LCD.
Top 0x48 broadcast address , access settings sensor , determining that the output is active high and continuous conversion , ending transmission. Once activated starts the protocol to start converting transmission and transmission ends.
But have the time set by the RTC gets the computer.
Initializes everything to be prepared disruption , interruption Three types have chosen this , and must be present when you ordered do it. We also put a 1 pin2 for interrupting , when we have it 0 out of interruption. Finalizing have a function that is what we want to do in disruption in this case goes to the event function is an empty function that does not return anything.
We write the start date of the RTC clock in memory print the serial nvram.Después day, month , year and in the next line the hour, minutes and seconds everything in decimal.Seguidamente begin transmission with temperature sensor , started with 0xAA command to read the sensor, completed the transmission. We tell the direction and bytes occupied in this case 1. Then we say that tempC equals reading Wire , print the word serial temperature followed by the value of tempC and a character C.
We clean what's on the LCD , we say we will go to the 3-position of the first row, the LCD and print the current day , followed by the month and year . In the second row that is to position 1 and print the hour, minute, second current and temperature.
Now we are going to save the data from 1 to 2 minutes in NVRAM. For 1 minute, start with a consistent variables in timer in periods of 1 second. If the counter reaches 60 seconds , writes the data to a whole array elements 7 an unsigned byte . The write in position 0 , 7 data. Furthermore we print a warning by the serial to know that you have saved . The same procedure for 2 minutes we give us time to save the data correctly and slept the micro. If you press the button that we have put our micro wakes.
Function we want to do when interrupted , in this case we do not want to do anything or return anything.
Now a video of practice run in proteus.
To download the files from all the practice you must click on the picture below.
Theo ban quạt trần đèn co tot khong
ResponderEliminarquạt trần đèn trang trí đài loan có tốt không