Microcontroller › AVR › problem with program of ATmega16 for sms based device control › will this code work for it? i
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!=’