i have this code that is used to program lcd 16X2 using atmega16A:
what additions can i add on it?
like: to check if the lcd is busy or not , clear only the first line...
thanks
Rich (BB code):
/*----------------------------------------------------------------
-----------------HEADER FILES-------------------------------------
-----------------------------------------------------------------*/
#include<avr/io.h>
#include <util/delay.h>
#define SETBIT(ADDRESS,BIT) (ADDRESS |= (1<<BIT))
#define CLEARBIT(ADDRESS,BIT) (ADDRESS &= ~(1<<BIT))
#define CHECKBIT(ADDRESS,BIT) (ADDRESS & (1<<BIT))
/*----------------------------------------------------------------
-------------CONNECTION BETWEEN LCD AND ATMEGA32-----------------
-----------------------------------------------------------------*/
#define DATA_DDR DDRB
#define DATA_PORT PORTB
#define CONTROL_DDR DDRA
#define CONTROL_PORT PORTA
#define Enable_Pin 2
#define RegSelect_Pin 0
#define ReadWrite_Pin 1
#define CONTROL_MASK 0X07
/*----------------------------------------------------------------
-------------CONTROL BITS OF LCD --------------------------------
-----------------------------------------------------------------*/
#define Set_Enable CONTROL_PORT|=_BV(Enable_Pin)
#define Clear_Enable CONTROL_PORT&=~_BV(Enable_Pin)
#define Write_Lcd CONTROL_PORT&=~_BV(ReadWrite_Pin)
#define Read_Lcd CONTROL_PORT|=_BV(ReadWrite_Pin)
#define Select_InstructionRegister CONTROL_PORT&=~_BV(RegSelect_Pin)
#define Select_DataRegister CONTROL_PORT|=_BV(RegSelect_Pin)
#define Data_Lcd(a) DATA_PORT=a
#define delay(a) _delay_ms(a)
/*----------------------------------------------------------------
-----------------SEND A CHARACTER TO LCD-------------------------
-----------------------------------------------------------------*/
void Lcd_Send(unsigned char a)
{
Select_DataRegister;
Write_Lcd;
Data_Lcd(a);
Set_Enable;
delay(30);
Clear_Enable;
delay(30);
}
/*----------------------------------------------------------------
-----------------FUNCTIONS TO INITIALIZE PORTS--------------------
-----------------------------------------------------------------*/
void Init_Ports(void)
{
DATA_DDR=0XFF; //Setting data port for output
CONTROL_DDR=CONTROL_MASK;//setting selected pins of control port for output
CONTROL_PORT&=~(_BV(Enable_Pin)|_BV(RegSelect_Pin )|_BV(ReadWrite_Pin)); //setting values to 0 at starting
}
/*----------------------------------------------------------------
------------FUNCTION TO INITIATE LCD -----------------------------
-----------------------------------------------------------------*/
void Init_Lcd(void)
{
char init[10];
int i;
init[0] = 0x01;
init[1] = 0x38;
init[2] = 0x0c;
init[3] = 0x06;
init[4] = 0x80;
Select_InstructionRegister;
Write_Lcd;
for(i=0;i<5;i++)
{
Data_Lcd(init);
Set_Enable;
delay(30);
Clear_Enable;
delay(30);
}
}
///////////////////
void gotos(char x,char y)
{
char val;
switch (y)
{
case 0:
val=0x80+0x00+x;
break;
case 1:
val=0x80+0x40+x;
break;
default:break;
}
Select_InstructionRegister;
Write_Lcd;
delay(30);
Data_Lcd(val);
Set_Enable;
delay(30);
Clear_Enable;
delay(30);
}
/*----------------------------------------------------------------
----------------MAIN FUNCTION--------------------------------------
-----------------------------------------------------------------*/
int main(void)
{
int len,i;
char string[] = {'H','E','L','L','O',' ','J','O','J','O'};
Init_Ports();
Init_Lcd();
len=10;
gotos(0x04,1);
for (i=0; i< len;i++)
Lcd_Send(string);
}
what additions can i add on it?
like: to check if the lcd is busy or not , clear only the first line...
thanks