Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Program to display special Characters on LCD using AVR Microcontroller (ATmega16)
- /*
- To display special character on LCD data
- LCD DATA port----PORT B
- ctrl port------PORT D
- rs-------PD0
- rw-------PD1
- en-------PD2
- using internal clock frequency 1MHz
- */
- #include<avr/io.h>
- #include<util/delay.h>
- #define LCD_DATA PORTB //LCD data port
- #define signal PORTD
- #define en PD2 // enable signal
- #define rw PD1 // read/write signal
- #define rs PD0 // register select signal
- void LCD_cmd(unsigned char cmd);
- void init_LCD(void);
- void LCD_write(unsigned char data);
- void LCD_character();
- int main()
- {
- DDRB=0xff;
- DDRD=0x07;
- init_LCD();
- _delay_ms(50); // delay of 50 mili seconds
- LCD_character();
- return 0;
- }
- void init_LCD(void)
- {
- LCD_cmd(0x38); // initialization of 16X2 LCD in 8bit mode
- _delay_ms(1);
- LCD_cmd(0x01); // clear LCD
- _delay_ms(1);
- LCD_cmd(0x0E); // cursor ON
- _delay_ms(1);
- LCD_cmd(0x80); // ---8 go to first line and --0 is for 0th position
- _delay_ms(1);
- return;
- }
- void LCD_cmd(unsigned char cmd)
- {
- 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)
- {
- 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_character()
- {
- LCD_cmd(64); // Address where customized character is to be stored
- LCD_write(0);
- LCD_write(14);
- LCD_write(17);
- LCD_write(2);
- LCD_write(4);
- LCD_write(4);
- LCD_write(0);
- LCD_write(4);
- LCD_cmd(0x80); // Location of LCD where the character is to be displayed
- LCD_write(0); // Displaying the character created at address 0x64
- _delay_ms(10);
- LCD_cmd(72); // Address where customized character is to be stored
- LCD_write(0);
- LCD_write(10);
- LCD_write(21);
- LCD_write(17);
- LCD_write(18);
- LCD_write(4);
- LCD_write(0);
- LCD_write(0);
- LCD_cmd(0x82); // Location of LCD where the character is to be displayed
- LCD_write(1); // Displaying the character created at address 0x72
- _delay_ms(10);
- LCD_cmd(80); //Address where customized character is to be stored
- LCD_write(0);
- LCD_write(0);
- LCD_write(10);
- LCD_write(0);
- LCD_write(4);
- LCD_write(0);
- LCD_write(14);
- LCD_write(17);
- LCD_cmd(0x84); // Location of LCD where the character is to be displayed
- LCD_write(2); // Displaying the character created at address 0x80
- _delay_ms(10);
- LCD_cmd(88); //Address where customized character is to be stored
- LCD_write(1);
- LCD_write(3);
- LCD_write(5);
- LCD_write(9);
- LCD_write(9);
- LCD_write(11);
- LCD_write(27);
- LCD_write(24);
- LCD_cmd(0x86); // Location of LCD where the character is to be displayed
- LCD_write(3); // Displaying the character created at address 0x88
- _delay_ms(10);
- LCD_cmd(96); // Address where customized character is to be stored
- CD_write(0);
- LCD_write(0);
- LCD_write(0);
- LCD_write(4);
- LCD_write(0);
- LCD_write(31);
- LCD_write(0);
- LCD_cmd(0xC0); // location where the character is to be displayed
- LCD_write(4); // Display the character created at address 0x96
- _delay_ms(10);
- LCD_cmd(104); //Address where customized character is stored
- LCD_write(0);
- LCD_write(17);
- LCD_write(10);
- LCD_write(17);
- LCD_write(4);
- LCD_write(0);
- LCD_write(14);
- LCD_write(17);
- LCD_cmd(0xC2); // Location of LCD where the character is to be displayed
- LCD_write(5); // Display the character created at address 0x104
- _delay_ms(10);
- LCD_cmd(112); // Address where customized character is to be stored
- LCD_write(0);
- LCD_write(14);
- LCD_write(17);
- LCD_write(2);
- LCD_write(4);
- LCD_write(4);
- LCD_write(0);
- LCD_write(4);
- LCD_cmd(0xC4); // Location of LCD where the character is to be displayed
- LCD_write(6); // Display the character created at address 0x112
- _delay_ms(10);
- LCD_cmd(120); // Address where customized character is to be stored
- LCD_write(10);
- LCD_write(0);
- LCD_write(4);
- LCD_write(0);
- LCD_write(14);
- LCD_write(17);
- LCD_write(17);
- LCD_write(14);
- LCD_cmd(0xC6); // Location of LCD where the character is to be displayed
- LCD_write(7); // Display the character created at address 0x120
- _delay_ms(10);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement