Опубликовано 2010-03-07 09:55:14 автором Ruslan

Lcd connection to the microcontroller AVR


Learning to blink the led, you probably want to connect to the microcontroller something more meaningful, such as Lcd display. How to do this? Yes it is, very simply. Character LCD display we подружим today with our old friends the ATmega8. For this we need to myself Lcd, I used symbols 16x2 LCD, and the atmega8 microcontroller.

connection diagram lcd to the microcontroller

For a start, write a program to be shown on the display. To open the Code Vision AVR, create a new project. Tab LCD select a port which is connected with the display.

Code Vision AVR select a port for output on the lcd

I connected to port D, choose File -> Creative Save and Exit. Indicate, where we store the files and look at the code of the program. Next to output a string, we need to add a few lines of code

  • char *buffer_Lcd="Hello"; //Create the output string
  • lcd_gotoxy(0, 0); // Translate the cursor to the first character of the first line
  • lcd_puts(buffer_Lcd); // display the string
The complete code is shown below:

#include <mega8.h> 
 
// Alphanumeric LCD Module functions 
#asm 
.equ __lcd_port=0x12 ;PORTD is set 
#endasm 
#include <lcd.h> 
 
// Declare your global variables here 
void main(void) 
{ 
// Declare your local variables here 
char *buffer_Lcd="Hello"; //Create the output string  
 
// Input/Output Ports initialization 
// Port B initialization 
PORTB=0x00; 
DDRB=0x00; 
 
// Port C initialization 
PORTC=0x00; 
DDRC=0x00; 
 
// Port D initialization 
PORTD is set=0x00; 
DDRD=0x00; 
 
// Timer/Counter 0 initialization 
// Clock source: System Clock 
// Clock value: Timer 0 Stopped 
TCCR0=0x00; 
TCNT0=0x00; 
 
// Timer/Counter 1 initialization 
// Clock source: System Clock 
// Clock value: Timer1 Stopped 
// Mode: Normal top=FFFFh 
// OC1A output: Discon. 
// OC1B output: Discon. 
// Noise Canceler: Off 
// Input Capture on Falling Edge 
// Timer1 Overflow Interrupt: Off 
// Input Capture Interrupt: Off 
// Compare A Match Interrupt: Off 
// Compare B Match Interrupt: Off 
TCCR1A=0x00; 
TCCR1B=0x00; 
TCNT1H=0x00; 
TCNT1L=0x00; 
ICR1H=0x00; 
ICR1L=0x00; 
OCR1AH=0x00; 
OCR1AL=0x00; 
OCR1BH=0x00; 
OCR1BL=0x00; 
 
// Timer/Counter 2 initialization 
// Clock source: System Clock 
// Clock value: Timer2 Stopped 
// Mode: Normal top=FFh 
// OC2 output: Disconnected 
ASSR=0x00; 
TCCR2=0x00; 
TCNT2=0x00; 
OCR2=0x00; 
 
// External Interrupt(s) initialization 
// INT0: Off 
// INT1: Off 
MCUCR=0x00; 
 
// The Timer(s)/Counter(s) Interrupt(s) initialization 
TIMSK=0x00; 
 
// Analog Comparator initialization 
// Analog Comparator: Off 
// Analog Comparator Input Capture by the Timer/Counter 1: Off 
ACSR=0x80; 
SFIOR=0x00; 
 
// LCD module initialization 
lcd_init(16); 
lcd_gotoxy(0, 0); // Translate the cursor to the first character of the first line 
 
lcd_puts(buffer_Lcd); // Print the line  
 
while (1) 
{ }; 
}

FunctionAds
lcd_init(количество_символов_в_строке)Initializes the LCD with the entered number of characters per line.
lcd_gotoxy(x, y)moves the cursor to the point (x, y).
lcd_clear()Cleans LCD
lcd_puts(char *stroka)Displays an array of characters
lcd_putchar(char simvol) Displays a single character
Table 1. Library functions Lcd.h for work with display now let's make the conclusions of the display.

  • Vdd - + 5 volts. - The Power To The Lcd.
  • Vss - Ground ). - The Power To The Lcd.
  • V0 or VEE - contrast display. - If you put this conclusion on the minus without resistor,we get the maximum visibility. You want this contact to connect to minus via the variable resistor of about 10 kOhm.
  • and To the anode and cathode backlight lcd
  • RS - command flag - if the file is 0, then we send the command. 1 - sent data.
  • R/W - Read/write - 1 - read the data, 0 - record it.
  • E - pulse - to lcd started processing the data with the rest of the conclusions
  • DB0 - DB7 - are used for data transfer between the lcd and microcontroller
Well, really, if something does not work, please write in the comments.

Комментарии - (4)

Добавить комментарий

Для отправки комментария вы должны авторизоваться.