EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Replies / AVR

AVR

|

Microcontroller › AVR › Problem in Programming——AVR——- › AVR

June 23, 2017 at 4:57 am #14618
Manoj
Participant

Thanks Mr. Hari for Replying, i am saying that when it goes in any if case the message shows again and again, like if all three Ports are hight (PB3,4,5) it should show message on screen “TANK IS FULL”, it is showing message correctly but LCD cleares after some time and again this message starts typing on screen

And Yes currently i am using Switches for I/P and i just want to display message if any switch is pressed and starts relay and buzzer when no switch is pressed,

After Posting this Forum i hv done some R&D on my Code, and now Code is

#include
#define F_CPU 1000000UL
#include

/*PORTD = LCD Data line
PB.0 = RS
PB.1 = R/w
PB.2 = EN
PB.3 = Switch 1
PB.4 = Switch 2
PB.5 = Switch 3
PC.1 = Buzzer
PC.2 = Relay 1
PC.3 = Relay 2
PC.4 = Relay 3 */

int main()
{
DDRD = 0xFF; //set PORTD as out put 8 bit lcd data line
DDRB = 0b00000111; //Set PB.0,1 and 2 as Output
DDRC = 0xFF; //PORTC as output
PORTB = 0x00;
init_lcd();
_delay_ms(1000);
lcd_cmd(0x80); //Goto Line-1,first position
lcd_send_string(“Wait…”);
_delay_ms(100);
lcd_cmd(0xC0); //Goto Line-2, first position
_delay_ms(100);
lcd_send_string(“Booting”);
while (1)
{
PORTC=0xFF;
if (bit_is_set(PINB,PB3) && bit_is_set(PINB,PB4) && bit_is_set(PINB,PB5)) // All 3 Switch Pressed
{
PORTC=PORTC & 0x00; // All 3 Relay and Buzzer OFF
lcd_cmd(0x01); //Clear the lcd
_delay_ms(100);
lcd_cmd(0x80); //Goto Line-1,first position
lcd_send_string(“Tank is “);
_delay_ms(100);
lcd_cmd(0xC0); //Goto Line-2, first position
_delay_ms(100);
lcd_send_string(“Full”);
_delay_ms(1000);
}
else if (bit_is_clear(PINB,PB3) && bit_is_set(PINB,PB4) && bit_is_set(PINB,PB5)) // 2 Switch Pressed
{
PORTC=PORTC & 0x00; // All 3 Relay and Buzzer OFF
lcd_cmd(0x01); //Clear the lcd
_delay_ms(100);
lcd_cmd(0x80); //Goto Line-1,first position
lcd_send_string(“TANK IS”);
_delay_ms(100);
lcd_cmd(0xC0); //Goto Line-2, first position
_delay_ms(100);
lcd_send_string(“HALF”);
_delay_ms(1000);
}
else if (bit_is_clear(PINB,PB3) && bit_is_clear(PINB,PB4) && bit_is_set(PINB,PB5)) // 1 Switch Pressed
{
PORTC=PORTC & 0x00; // All 3 Relay and Buzzer OFF
lcd_cmd(0x01); //Clear the lcd
_delay_ms(100);
lcd_cmd(0x80); //Goto Line-1,first position
lcd_send_string(“TANK IS”);
_delay_ms(100);
lcd_cmd(0xC0); //Goto Line-2, first position
_delay_ms(100);
lcd_send_string(“1/4”);
_delay_ms(1000);
}
else if(bit_is_clear(PINB,PB3) && bit_is_clear(PINB,PB4) && bit_is_clear(PINB,PB5)) // No Switch is Pressed
{
PORTC=PORTC & 0xFF; // All 3 Relay and Buzzer ON
lcd_cmd(0x01); //Clear the lcd
_delay_ms(100);
lcd_send_string(“TANK EMPTY”);
_delay_ms(100);
lcd_cmd(0xC0); //Goto Line-2, first position
_delay_ms(100);
lcd_send_string(“PUMP ON”);
_delay_ms(1000);
}
}
}

//LCD function
/*


*/
//Function for sending commands to LCD
void lcd_cmd(unsigned char command)
{
PORTD = command; //Put command on the Data Bus
PORTB = 0b00000100; //Enable LCD for command writing
_delay_ms(50);
PORTB = 0b00000000; //Disable LCD again
_delay_ms(50);
}
//Function for sending Data to LCD
void lcd_data(unsigned char data)
{
PORTD= data; //Put data on Data Bus
PORTB = 0b00000101; //Set R/S (Register Select) to High, and Enable to High
_delay_ms(50);
PORTB = 0b00000000; //Disable LCD again
_delay_ms(50);
}
//Function to send String to LCD
void lcd_send_string(char* string)
{
while(*string)
{
lcd_data(*string); //Send value of pointer as data to LCD
string++; //Increment string pointer
}
}
//Function to InitiALLISE LCD
void init_lcd()
{
lcd_cmd(0x38); //Setup both lines of LCD
lcd_cmd(0x0E); //Set Cursor off – Enable LCD
lcd_cmd(0x01); //Clear Screen
lcd_cmd(0x80); //Goto first position
}

RSS Recent Posts

  • LED circuit for 1/6 scale diorama May 15, 2025
  • stud mount Schottky diodes May 14, 2025
  • using a RTC in SF basic May 14, 2025
  • Hi Guys May 14, 2025
  • Can I use this charger in every country? May 14, 2025

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise