Code to send temperature in ATmega16 C
Write an ATmega16 C program to send temperature range of –4 to +4 to port B.
Here we will keep in mind some things like- We need to use the least possible memory space as possible, such as by using unsigned variables etc.
- now as we are also asked to input the values which take - value hence we need to implement a signed array too.
- we will need to set DDR B as output so we put 11111111 in it as 1 makes the port bits output.
- The value which we will write will be send are to be written on PORTB register.
- Code:
#include<ave/io.h>
int main(void)
{
char num[] = {-4,-3,-2,-1,0,+1,+2,+3,+4};
unsigned char z;
DDRB = 0*FF;
for(z=0;z<8;z++)
{
PORTB = num[z];
}
return 0;
}
Note: The negative values will be displayed in the 2’s complement form as FCH, FDH,FEH,FFH, 00H, 01H, 02H,03H,04H .
(hex values of -4,-3,-2,-1,0,1,2,3,4)
Ref : Prof.Gaurav Verma
Comments
Post a Comment