Microcontroller › AVR › LCD Library for AVR Atmega32
- This topic has 1 reply, 2 voices, and was last updated 10 years, 8 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
August 11, 2013 at 5:28 pm #2588Shishir K ChakravarthyParticipant//An LCD library for interfacing Atmega 32 to a 16X2 LCD…//Author: Shishir K Chakravarthy ~Blitz//Interface manual://Enable –> PORTD PIN0//Register Select –> PORTD PIN1//Read/Write –> PORTD PIN2//D0 –> PORTB PIN0 |//D1 –> PORTB PIN1 |//D2 –> PORTB PIN2 |//D3 –> PORTB PIN3 | for 8 bit data//D4 –> PORTB PIN4 |//D5 –> PORTB PIN5 |//D6 –> PORTB PIN6 |//D7 –> PORTB PIN7 |//Commands ://LCD_INIT(); –> Initializes the LCD for Display PS:Cursor OFF//LCD_WRITE(“string”); –> To display characters//LCD_WRITE_NUM(value,width); –>To display number of specified width//LCD_SETCURSOR(x,y); –>To set cursor coordinates//LCD_CLEAR(); –>Erases LCD memory//Enjoy!!!#ifndef m32_16X2_LCD_H_#define m32_16X2_LCD_H_#include <avr/io.h>#include <util/delay.h>#include <stdlib.h>#define DATADIR_PORTB DDRB#define DATADIR_PORTD DDRD#define LCD_CONTROL PORTD#define LCD_DT PORTB#define EN PIND0#define RS PIND1#define RW PIND2void LCD_INIT();void LCD_CMD(unsigned char);void LCD_DATA(unsigned char);void LCD_WRITE(char *string);void LCD_WRITE_NUM(unsigned char, unsigned char);void LCD_SETCURSOR(uint8_t, uint8_t);void LCD_CLEAR();void LCD_BUSY_CHECK();void LCD_FLASH();unsigned char InitColumn[2]={0,64};void LCD_INIT(){DATADIR_PORTD |= (1<<EN|1<<RS|1<<RW);DATADIR_PORTB = 0xFF;_delay_ms(20);LCD_CMD(0x01);_delay_ms(2);LCD_CMD(0x38);_delay_us(50);LCD_CMD(0x0C);_delay_us(50);LCD_CMD(0x06);_delay_us(50);}void LCD_CMD(unsigned char cmd){LCD_CHECK_BUSY();LCD_DT = cmd;LCD_CONTROL &=~((1<<RW)|(1<<RS));LCD_FLASH();LCD_DT = 0;}void LCD_DATA(unsigned char data){LCD_CHECK_BUSY();LCD_DT = data;LCD_CONTROL &=~(1<<RW);LCD_CONTROL |=1<<RS;LCD_FLASH();LCD_DT = 0;}void LCD_WRITE(char *string){while(*string>0){LCD_DATA(*string++);_delay_us(50);}}void LCD_WRITE_NUM(unsigned char val, unsigned char width){unsigned char array[width];itoa(val,array,10);LCD_WRITE(array);_delay_us(50);}void LCD_SETCURSOR(uint8_t x, uint8_t y){LCD_CMD(0x80 + InitColumn[y] + x);_delay_us(50);}void LCD_CLEAR(){LCD_CMD(0x01);_delay_us(50);}void LCD_CHECK_BUSY(){DATADIR_PORTB = 0;LCD_CONTROL |= 1<<RW;LCD_CONTROL &=~(1<<RS);while(LCD_DT >=0x80){LCD_FLASH();}DATADIR_PORTB = 0xFF;}void LCD_FLASH(){LCD_CONTROL |=1<<EN;asm volatile(“nop”);asm volatile(“nop”);LCD_CONTROL &=~(1<<EN);}#endif /*m32_16X2_LCD_H_*/August 12, 2013 at 5:03 am #10314AJISH ALFREDParticipant
Nice, and thanks for sharing.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- You must be logged in to reply to this topic.