|
| |||||||||||||
|
Опубликовано 2010-03-07 09:55:14 автором Ruslan Lcd connection to the microcontroller AVRLearning 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.
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.
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
#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)
{ };
}
Комментарии - (4)
Добавить комментарийДля отправки комментария вы должны авторизоваться. |
|||||||||||||