
as circuit image is attached and for the circuit the is also attach...
i hav a problem in this module...
problem is sensor donot showing its distance calculation on lcd...
can anybody plzzz tell me how i get solve this problem.....
its v urgent plzzz help me.....
the program is...
C:
/*****************************
EZO sensors test code
******************************
Program by : Manu krishnan
version : 1.0.0.0 (beta)
Assembled in : winavr
core : mega 16 (16k)
fuse : 11.0592Mhz interna
AVR Studio : 4.15.623
GUI Version : 4, 15, 0, 623
AVR Simulator: 1, 0, 2, 1
ATMEGA16 247
date : 25 March 2013 20.44
*******************************/
/*******************************
Preprovcessor Directive
*******************************/
#define F_CPU 11059200UL
#include<avr/io.h>
#include<util/delay.h>
#include<avr/interrupt.h>
/******************************/
/*******************************
LCD definitions
*******************************/
#define ctrl PORTC //dataport
#define en PC3 //enable signal
#define rs PC2 //resister select signal
//MACROS
#define output_low(port,pin) port &= ~(1<<pin)
#define output_high(port,pin) port |= (1<<pin)
#define set_input(portdir,pin) portdir &= ~(1<<pin)
#define set_output(portdir,pin) portdir |= (1<<pin)
/*******************************
uart definitions
*******************************/
#define USART_BAUDRATE 4800
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)
/*******************************
Function definitions
*******************************/
void convert(unsigned int value,unsigned int numb);
void dis_data(char data_value);
void dis_cmd(char cmd_value);
/////////////////////////////////
void lcdcmd(char cmdout);
void lcddata(char dataout);
void lcd_write_string(unsigned char *str);
void lcd_init();
void to_line(char line,char pos);
void clear();
void convert(unsigned int value,unsigned int numb);
////////////////////////////////
void setup();
////////////////////////////////
void usart_init();
void usart_putch(unsigned char send);
unsigned int usart_getch();
void uart_string(unsigned char *str);
////////////////////////////////////
char txt[];
char a;
volatile unsigned char serial,i;
volatile unsigned char data[3];
/*******************************
Main Function Start
*******************************/
int main()
{
setup();
to_line(1,0);
lcd_write_string("Distance:-");
while(1)//infinite loop
{
to_line(2,0);
for(a=0;a<=2;a++)
{
data[a]= usart_getch();
}
for(a=0;a<=2;a++)
{
dis_data(data[a]);
}
lcd_write_string("c.m.");
}
}
/*******************************
End main
*******************************/
void setup()
{
DDRA=0x00;
DDRC=0xff;
// PORTD=0xff;
lcd_init();
usart_init();
uart_string("test");
// t2_fastpwm_init();
}
/*******************************
Class LCD 4 bit for 4 bit lcd
interface
*******************************/
void lcd_init() // fuction for intialize
{
dis_cmd(0x02); // to initialize LCD in 4-bit mode.
dis_cmd(0x28); //to initialize LCD in 2 lines, 5X7 dots and 4bit mode.
dis_cmd(0x0C);
dis_cmd(0x06);
dis_cmd(0x80);
}
void dis_cmd(char cmd_value)
{
char cmd_value1;
cmd_value1 = cmd_value & 0xF0; //mask lower nibble because PA4-PA7 pins are used.
lcdcmd(cmd_value1); // send to LCD
cmd_value1 = ((cmd_value<<4) & 0xF0); //shift 4-bit and mask
lcdcmd(cmd_value1); // send to LCD
}
void to_line(char line,char pos)
{
if(line ==1)
{
dis_cmd(0x80 + pos);
}
else
{
dis_cmd(0xC0+pos);
}
}
void clear()
{
to_line(1,0);
lcd_write_string(" ");
to_line(2,0);
lcd_write_string(" ");
}
void dis_data(char data_value)
{
char data_value1;
data_value1=data_value&0xF0;
lcddata(data_value1);
data_value1=((data_value<<4)&0xF0);
lcddata(data_value1);
}
void lcdcmd(char cmdout)
{
ctrl=cmdout;
ctrl&=~(1<<rs);
ctrl|=(1<<en);
_delay_ms(1);
ctrl&=~(1<<en);
}
void lcddata(char dataout)
{
ctrl=dataout;
ctrl|=(1<<rs);
ctrl|=(1<<en);
_delay_ms(1);
ctrl&=~(1<<en);
}
void lcd_write_string(unsigned char *str) //take address vaue of the string in pionter *str
{
int i=0;
while(str[i]!='\0') // loop will go on till the NULL charaters is soon in string
{
dis_data(str[i]); // sending data on CD byte by byte
i++;
}
return;
}
/*******************************
uart thingies
*******************************/
void usart_init()
{
UCSRB |= (1<<RXCIE) | (1 << RXEN) | (1 << TXEN); // Turn on the transmission reception ..
// circuitry and receiver interrupt
UCSRC |= (1 << URSEL) | (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
}
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
}
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
}
void uart_string(unsigned char *str) //take address vaue of the string in pionter *str
{
int i=0;
while(str[i]!='\0') // loop will go on till the NULL charaters is soon in string
{
usart_putch(str[i]); // sending data on CD byte by byte
i++;
}
return;
}
Last edited by a moderator: