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 / will this code work for it? i

will this code work for it? i

|

Microcontroller › AVR › problem with program of ATmega16 for sms based device control › will this code work for it? i

May 29, 2013 at 6:36 am #9858
Shashank Rao.C
Participant

will this code work for it? i have not tried this. and not compiled also. please tell me any modification?

 

 

 

#define F_CPU 12000000UL      // set CPU freq.
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) – 1)
#include<avr/io.h>
#include<util/delay.h>

#define LCD_DATA PORTA    // LCD DATA PORT.
#define  ctrl PORTB       // CONTROL PORT FOR LCD.
#define en PB2            // ENABLE SINGNAL FOR LCD.
#define rw PB1            // READ/WRITE SIGNAL FOR LCD.
#define rs PB0            // REGISTER SELECTION SIGNAL FOR LCD.
#define MOTOR_CONTROL PORTC // MOTOR CONTROL PORT.

void LCD_cmd(unsigned char cmd);
void init_LCD(void);
void LCD_write(unsigned char data);

void usart_init();
void usart_putch(unsigned char send);
unsigned int usart_getch();

unsigned char msg[] = “”;

int main(void)
{
while(1)
{
uart_init();                    // initialize UART port.
init_LCD();

usart_get_string(msg[]);
_delay_ms(1000);
LCD_write_string(msg[]);
}
}

void init_LCD(void)              //Function to initialize LCD.
{
LCD_cmd(0x38);
_delay_ms(1);
// initialization of 16X2 LCD in 8bit mode
LCD_cmd(0x01); // clear LCD
_delay_ms(1);
LCD_cmd(0x0E); // cursor ON
_delay_ms(1);
LCD_cmd(0x80);    //first line 0th position
_delay_ms(1);
return;
}

void LCD_cmd(unsigned char cmd)           //Function to LCD command.
{
LCD_DATA=cmd;
ctrl =(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl =(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return;
}

void LCD_write(unsigned char data)            //Function to write a letter in LCD.
{
LCD_DATA= data;
ctrl = (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
ctrl = (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
return ;
}

void LCD_write_string(unsigned char *str)         //Function to write a string in //LCD.
//value of the string in pointer *str
{
int i=0;
while(str!=’’)
//go on till the NULL character in the string
{
LCD_write(str
);  //sending data on LCD byte by byte
i++;
}
return;

void usart_init()                                // Function to initialize USART.
{
UCSRB |= (1 << RXEN) | (1 << TXEN);
// Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1<<USBS) | (1 << UCSZ0) | (1 <<UCSZ1);
// Use 8-bit character sizes
UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value..
// into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate //value..
// into the high byte of the UBRR register
}

void usart_putch(unsigned char send)                  
{
while ((UCSRA & (1 << UDRE)) == 0); // Do nothing until UDR is ready..
// for more data to be written to it
UDR = send; // Send the byte
}

unsigned int usart_getch()
{
while ((UCSRA & (1 << RXC)) == 0);
// Do nothing until data have been
//received and is ready to be read from UDR
return(UDR); // return the byte
}

 usart_get_string(unsigned char msg[])    //To recive a String
{
    unsigned char i=0;
    for(i=0;msg
!=’’;i++)
    usart_getch(msg
);
}

RSS Recent Posts

  • ANOTHER OLD PROJECT REDO April 16, 2026
  • EasyEda program has a major bug April 16, 2026
  • How to set the OSCAL in a PIC 12F675 April 16, 2026
  • issues with level shifter driving a CGHV1A250F April 15, 2026
  • Drawing software April 15, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 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