Tuesday, 24 December 2013

ATMEGA 16 LCD MARQUEE

IN MY PREVIOUS POST I ALREADY DISCUSSED ABOUT THE LCD PRINTING USING ATMEGA 16. SO HERE IS THE POST TO LEARN MORE ABOUT THE LCD THAT  IS LCD MARQUEE...

In this ATMega16 AVR project we will be designing and implementing a Marquee with the aid of a Atmel AVR ATMega16 microcontroller and an alphanumeric LCD module.

Note: Although this AVR project was designed around the ATMega16 the project could have utilized another microcontroller such as an ATMega32, ATMega8515, etc.

ATMega16 LCD Marquee Operation & Hardware Description

 
Our LCD Marquee operates as follows. When the circuit is powered ON the text AVR TUTORIALS WELCOMES YOU will display on the screen. This text will blink then move to right, then to left, then to the right again. This sequence repeats.

The figure below gives the circuit diagram for the ATmega16 LCD Marquee system.
 



Important Note: In order for the LCD Marquee unit to work correctly the internal oscillator of the ATMega16 AVR microcontroller must be enabled and set to 4MHz.


Below is the AVR C implementation of the entire code for the ATMega16 based LCD marquee unit. The code was implemented and built using AVR Studio 5. Be reminded that the internal clock of the ATMega16 microcontroller should be enabled and programmed to operate at 4MHz for the AVR C code to operate correctly.
 CODING FOR THE ABOVE CIRCUIT IS WRITTEN BELOW....ENJOY IT
#include <avr/delay.h>
#include <avr/io.h>
 
/*LCD function declarations */
void LCD_send_command(unsignedchar cmnd);
void LCD_send_data(unsignedchar data);
void LCD_init();
void LCD_goto(unsignedchar y,unsignedchar x);
void LCD_print(char*string);
void LCD_blink();
void LCD_scroll(unsignedchar direction);
 
#define LCD_DATA_PORT            PORTB
#define LCD_DATA_DDR              DDRB
#define LCD_DATA_PIN PINB
 
#define LCD_CNTRL_PORT         PORTC
#define LCD_CNTRL_DDR           DDRC
#define LCD_CNTRL_PIN             PINC
 
#define LCD_RS_PIN                     0
#define LCD_RW_PIN                    1
#define LCD_ENABLE_PIN           2
 
int main(void)
{               
unsignedchar i; 
LCD_init();
LCD_goto(1,2);                
LCD_print("AVR TUTORIALS");               
 LCD_goto(2,3);                
LCD_print("WELCOMES YOU");               
 while(1)
{
for(i=0;i<2;i++)                                               
LCD_blink();                               
 for(i=0;i<2;i++)                                               
LCD_scroll(0);                      
 for(i=0;i<4;i++)                                               
LCD_scroll(1);                               
 for(i=0;i<2;i++)                                               
LCD_scroll(0);
}
}
 
/* This function sends a command 'cmnd' to the LCD module*/
void LCD_send_command(unsignedchar cmnd)
{               
 LCD_DATA_PORT = cmnd;                
LCD_CNTRL_PORT &= ~(1<<LCD_RW_PIN);               
 LCD_CNTRL_PORT &= ~(1<<LCD_RS_PIN);
                 
LCD_CNTRL_PORT |=(1<<LCD_ENABLE_PIN);                
_delay_us(2);               
 LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);                
_delay_us(100);
}
 
/* This function sends the data 'data' to the LCD module*/
void LCD_send_data(unsignedchar data)
{                
LCD_DATA_PORT = data;                
LCD_CNTRL_PORT &= ~(1<<LCD_RW_PIN);               
 LCD_CNTRL_PORT |=(1<<LCD_RS_PIN);
                 
LCD_CNTRL_PORT |=(1<<LCD_ENABLE_PIN);                
_delay_us(2);                
LCD_CNTRL_PORT &= ~(1<<LCD_ENABLE_PIN);                
_delay_us(100);
}
 
void LCD_init()
{                
LCD_CNTRL_DDR =0xFF;                
LCD_CNTRL_PORT =0x00;               
 LCD_DATA_DDR =0xFF;               
LCD_DATA_PORT =0x00;                
_delay_ms(10);                
LCD_send_command(0x38);                
LCD_send_command(0x0C);                
LCD_send_command(0x01);                
_delay_ms(10);                
LCD_send_command(0x06);
}
 
/* This function moves the cursor the line y column x on the LCD module*/
void LCD_goto(unsignedchar y,unsignedchar x)
{                
unsignedchar firstAddress[]={0x80,0xC0,0x94,0xD4};                
LCD_send_command(firstAddress[y-1]+ x-1);                
_delay_ms(10);   
}
 
void LCD_print(char*string)
{                
unsignedchar i;                
while(string[i]!=0)                
{                               
 LCD_send_data(string[i]);                                
i++;                
}
}
 
void LCD_blink()
{                
LCD_send_command(0x08);                
_delay_ms(250);               
 LCD_send_command(0x0C);                
_delay_ms(250);
}
 
void LCD_scroll(unsignedchar direction)
{                
if(direction ==0)                                
LCD_send_command(0x18);                
else                               
 LCD_send_command(0x1C);                
_delay_ms(500);
}
 

No comments:

Post a Comment

share your thoughts