Source code of LCD2004 driven by ATmega16 (avr)

Publisher:达文西happyLatest update time:2011-11-25 Keywords:ATmega16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

/*================================================
20x4 character LCD main program, compilation software (ICCAVR_6.31)
CPU internal crystal oscillator 8M
data line B0~B7 connects PORTB, E=D7 RW=D6 RS=D5
=======================================================
The wiring diagram is as follows:
_______________ ______________
| --1|GND |
| --2| 5V |
| --3|V0 |
| | |
PD5|--------4|RS |
PD6|--------5|RW |
PD7|--------6|E |
CPU | | |
ATmmega16L PB0|--------7|D0 LCD20x4 |
PB1|--------8|D1 |
PB2|--------9|D2 |
PB3|-------10|D3 |
PB4|-------11|D4 |
PB5|-------12|D5 |
PB6|-------13|D6 |
PB7|-------14|D7 |
| | |
| --15| LED |
| --16|-LED |
_______________| |______________|
==============================================================*/
#include //CPU_ATmmega16L
#define RS_H asm("sbi 0x12,5") //RS set to high level
#define RS_L asm("cbi 0x12,5") //RS is set to low level
#define RW_H asm("sbi 0x12,6
") //RW is set to high level#define RW_L asm("cbi 0x12,6") //RW is set to low level
#define E_H asm("sbi 0x12,7") //E is set to high level
#define E_L asm("cbi 0x12,7") //E is set to low level

//=========================================================
//microsecond delay program
void delay_us(int time)
{
do
{
time--;
}
while (time > 1);
}
//===========================================================
//millisecond delay program
void delay_ms(unsigned int time)
{
while(time != 0)
{
delay_us(1000);
time--;
}
}

//=======================================================
//Read whether the LCD is in internal operation (busy) status
char Lcd_Busy()
{
char r;
DDRB = 0x00; //Port B is set to input mode
E_L;RS_L;RW_H; //E=0 (enable), RS=0 (command), RW=1 (read)
delay_us(2); //LCD delay subroutine
E_H;
delay_us(2); //LCD delay subroutine
r = PINB & 0x80; //Read the eighth bit of lcd_data
E_L;
DDRB=0xff; //Port B is set to output mode
return r; //Read result return
}

//=======================================================
//Send command program to LCD
void Lcd_Command(unsigned char Command)
{
while(Lcd_Busy()); //Judge whether LCD is in internal operation state
E_L;RS_L;RW_L; //E=0(enable),RS=0(command),RW=0(write)
delay_us(2); //LCD delay subroutine
E_H;
PORTB = Command; //Send command to LCD
delay_us(2); //LCD delay subroutine
E_L;
}

//=======================================================
//Program to write a character to the LCD
void Lcd_Write(unsigned char Data)
{
while(Lcd_Busy()); //Judge whether the LCD is in internal operation status
E_L;RS_H;RW_L; //E=0(enable),RS=1(data),RW=0(write)
delay_us(2); //LCD delay subroutine
E_H;
PORTB = Data; //Write a character to the LCD
delay_us(2); //LCD delay subroutine
E_L;
}


/*=============================================================
LCD line 1 displays address 1~20 (0x80~0x93)
LCD line 2 displays address 1~20 (0xc0~0xd3)
LCD line 3 displays address 1~20 (0x94~0xa7) LCD line
4 displays address 1~20 (0xd4~ 0xe7 ) ===
... //Set port D to output mode Lcd_Command(0x38); // Lcd_Command (0x38); // Lcd_Command(0x38); // Lcd_Command(0x38); // Lcd_Command(0x08); //Turn the display off Lcd_Command(0x01); //Clear the display Lcd_Command( 0x06); //Set the LCD to automatically increase AC by 1 after receiving 1 Byte of data Lcd_Command(0x0C); //Set the cursor, 0x0c = do not display, 0x0d = display flashing. }













//========================================================
//Write ASCII string program
void asc_tran(unsigned char *asc)
{
while((*asc) != 0) //Judge whether the word ends
{
Lcd_Write(*asc); //Write string asc to LCD
; //Move to the next character
}
}

//========================================================
//Test main LCD main program
void main()
{
Lcd_Init(); //Initialize LCD
while(1)
{
Lcd_Command(0x83); //Set display address
asc_tran("-----@_@------"); //Display string
Lcd_Command(0x97); //Set display address
asc_tran("www.ouravr.com"); //Display string
delay_ms(1000); //Delay 1 second
Lcd_Command(0x01); //Clear display

Lcd_Command(0x83); //Set display address
asc_tran("-----^_^------"); //Display string
Lcd_Command(0x94); //Set display address
asc_tran("http://59.36.96.196"); //Display string
delay_ms(1000); //Delay
Lcd_Command(0x01); //Clear display
}
}

Keywords:ATmega16 Reference address:Source code of LCD2004 driven by ATmega16 (avr)

Previous article:Characteristics and Applications of AVR IO Ports
Next article:High-precision frequency regulator based on Atmega16L microcontroller

Recommended ReadingLatest update time:2024-11-16 18:05

Design of Intelligent Temperature Controller for Dry-Type Transformer Based on ATmega16 Single Chip Microcomputer
1 Working Principle The temperature controller consists of three parts: temperature monitoring, signal processing, and output control. The system block diagram is shown in Figure 1. It obtains the winding temperature value through three platinum resistance sensors embedded in the three-phase winding of the trans
[Microcontroller]
Design of Intelligent Temperature Controller for Dry-Type Transformer Based on ATmega16 Single Chip Microcomputer
B001-Atmega16-Interrupt (GCC-AVR)-(ques=3)
Compiler: AVR Studio 4.19 + avr-toolchain-installer-3.4.1.1195-win32.win32.x86 Chip model: ATmega16 Chip frequency: 8MHz ------------------------------------------------------------------------------------------------------------------------------------- Number of open issues = 3 --------------------------------
[Microcontroller]
B001-Atmega16-Interrupt (GCC-AVR)-(ques=3)
Design of remote temperature difference cycle controller based on ATmega16
This design uses AVR microcontroller, RS 485 technology and NTC thermistor technology to develop the remote temperature difference cycle controller. 1 System structure and working principle The remote temperature difference cycle controller is mainly used to measure and display the water temperature of the water
[Microcontroller]
Design of remote temperature difference cycle controller based on ATmega16
ATMEGA16 and DS18B20 digital tube display
A DS18B20 with a large error value caused me a lot of trouble. I always thought it was a program error, so I changed it and it worked! It took me three days to check the program /*This program is an eight-bit common cathode digital tube with two 573 controlled dynamic scans*/ #include iom16v.h #include macros.h #
[Microcontroller]
ATmega16 Development Board Tutorial (1) - LED Lighting
2. LED lights up When used as a general digital IO, the IO of the AVR microcontroller has read, write and modify functions. Each port has 3 registers: DDRx, PORTx, and PINx. DDRx: 1-output, 0-input. When configured as input, PORTx=1, pull-up enabled, PORTx=0, high configuration; when configured as output, PORTx=1, o
[Microcontroller]
ATmega16 Development Board Tutorial (1) - LED Lighting
Design of digital optical power meter based on ATmega16
0 Introduction Digital optical power meter is a portable instrument controlled by a single-chip microcomputer that can measure the strength of optical signals. It is an important instrument used in laying fiber-optic communication trunk lines, equipment maintenance, scientific research and production. Howeve
[Microcontroller]
Design of digital optical power meter based on ATmega16
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号