Temperature Sensor and LCD 16x2 Interfacing with ATmega16
Proteus Design
YouTube Video Link
*
* Created: 12/12/2017 6:32:40 AM
* Author : Om
*/
#define F_CPU 800000
#include <avr/io.h>
#include <util/delay.h>
#include <stdlib.h>
#define enable 5
#define registerselection 6
void lcd(void);
void send_a_command(unsigned char command);
void send_a_character(unsigned char character);
void send_a_string(char *string_of_characters);
int main(void)
{
DDRC = 0xFF;
DDRA = 0x00;
DDRD = 0xFF;
DDRB = 0xFF;
_delay_ms(50);
lcd();
}
void lcd(void){
ADMUX |=(1<<REFS0)|(1<<REFS1);
ADCSRA |=(1<<ADEN)|(1<<ADATE)|(1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2);
int16_t COUNTA = 0;
char SHOWA [3];
send_a_command(0x01); //Clear Screen 0x01 = 00000001
_delay_ms(50);
send_a_command(0x38);
_delay_ms(50);
send_a_command(0b00001111);
_delay_ms(50);
//while (1)
//{
// ADCSRA |=(1<<ADSC);
//}
while(1)
{
ADCSRA |=(1<<ADSC);
COUNTA = ADC/4;
send_a_string ("Current temp is");
send_a_command(0x80 + 0x40 + 0);
send_a_string ("In (C) = ");
//send_a_command(0x80 + 0x40 + 8);
itoa(COUNTA,SHOWA,10);
send_a_string(SHOWA);
send_a_string (" ");
send_a_command(0x80 + 0);
send_a_command(0x0C);
}
}
void send_a_command(unsigned char command)
{
PORTC = command;
PORTD &= ~ (1<<registerselection);
PORTD |= 1<<enable;
_delay_ms(20);
PORTD &= ~1<<enable;
PORTC = 0;
}
void send_a_character(unsigned char character)
{
PORTC = character;
PORTD |= 1<<registerselection;
PORTD |= 1<<enable;
_delay_ms(20);
PORTD &= ~1<<enable;
PORTC = 0;
}
void send_a_string(char *string_of_characters)
{
while(*string_of_characters > 0)
{
send_a_character(*string_of_characters++);
}
}
Give Something to the world and it will never let you down.
Onkar Dubey
No comments:
Post a Comment