Here we will look into Temperature sensor in Atmega32 .Temperature sensing is an essential component for many applications, and the Atmega32’s incorporation of a dedicated sensor enables the creation of intelligent systems that can react to changes in temperature. Because it makes low-level programming easier and allows code execution to be optimized for certain hardware configurations, assembly language is a good fit for resource-constrained microcontrollers like the Atmega32.
Let us understand it through a program in assembly language.
Firstly, we will include a header file.
CODE:
.INCLUDE “M32DEF.INC”
If you do not know how to include it, you can check by clicking here.
To get to know about the temperature sensor let’s start by writing a mini instruction.
LDI R20,0X00
OUT DDRB, R20 // CONFIG. AS INPUT
First, we took a general-purpose register R20 and loaded the hex 0 value in it.
Then we output that value on the data direction register with port B, which means that we configured port B as the input port. Also, keep in mind that the data direction register is for the configuration of input and output. Here we gave the 8-bit 0 value which means that we are configuring it for input.
IN R25,PINB // IN REGISTER,PINB
When we need to get the data from the special function register, we use the IN command. Also, we use the PIN command instead of PORT to get the data.
Here, in the above command, PINB is a special function register related to port B and to bring the value from the special function register to a general purpose register we use IN command.
So, the value of port B is now saved in register R17.
CPI R25,100 // R25=R25-100
BRNE LOOP
And now by using the CPI command, we compare it with the value 100. What the CPI command does is subtract the value of the general purpose register from the constant that we provide. And if we get the 0 value it will raise the red flag and the command of branch not equal get false. And if we get the non-zero value, the branch not equal command gets true.
NOTE:
In case BRNE is true it will jump to the LOOP command. And if we get the 0 value it will terminate it and jump to LOOP1.
At this point, you need to remember the condition given in the statement that if the value is equal to 100 place it into the register R16, and if it is less than 100 place it in R17.
LOOP1:
MOV R16,R25
JMP LOOP1
LOOP:
MOV R17,R25
JMP LOOP
The MOV command is used to move the value from the general purpose register to another general purpose register.
Now we will build our code by pressing the F7 key the results are shown below.
DEBUG:
Now we will debug our code by pressing the F10.
From the above picture you can see that port B has been considered as port B.
By stepping to the next step, you can see a red flag has not been raised which means that R25 did not have the value of 0. And the BRNE got true it jumped to the loop.
As we know that R25 had the 0 value so that’s why R17 also has the 0 value in the LOOP.
You can see the simulation below.
Conclusion
To sum up, learning how to use ATMEL STUDIO 7’s Assembly language to explore the realm of temperature sensing with the Atmega32 has been a pleasant experience. We now know how to interface our microcontroller with a temperature sensor so that it can detect and react to temperature changes. Even though assembly language was a little more complex, it gave us the precise control we need for our particular microcontroller.
For Complete Trial Watch the Video: Temperature sensor in Atmega32 using ATMEL STUDIO 7 Assembly
For more blogs explore the website: https://ninjatech.live/