AVR microcontroller - (three), ATMEGA16 drive 16 * 2 dot matrix character LCD module - 01

Publisher:温馨时光Latest update time:2017-11-21 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

3. ATMEGA16 drives 16*2 dot matrix character LCD

3. (01) ATMEGA16 drives 16*2 dot matrix character LCD

This article is just a simple driver to make 1602 display, and does not use the part of reading data and reading status, nor does it use read and write detection (if you are interested, you can still write it here)AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

1. What kind of LCD should be used and how to drive it? Now I will post some pictures of the datasheet. It is so easy~~AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

1) Its pin description (I personally feel that if you want to know more, you can search it on the Internet~~ I just have a simple understanding here~)

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

There are only three pins that need attention here, RS, R/W, and E. These three pins are necessary for transmitting data. There is no need to introduce the others in detail~~ (The following program is written based on the timing diagram of these three pins!

2) (To be honest, I really don't want to go into detail, because many people think driving this 1602 is too simple~~ so I try to be concise) Basic operation timing

1 Read status: Input: RS=L, RW=H, E=H Output: D0~D7=status word

2 Write command: Input: RS=L, RW=L, D0~D7=command code, E=H Output: None

3 Read data: Input: RS=H, RW=H, E=OK Output: D0~D7=data

4 Write data: Input: RS=H, RW=L, D0~D7=data, E=high pulse Output: None

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

Note that since we don’t focus on reading, the important thing to look at above is the write timing and the timing parameters! ! ! !

(I don't need to explain too much here, but please note that 1602 is used to display data. Those functions such as read status and read data are not used for the time being, so I will not introduce them here for the time being. So, let's just use write instructions and write data directly. If you look closely, you will find that there is only one difference between write instructions and write data~~~~ that is, RS is low for write instructions; otherwise~~~)

3) Status word description

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

The read/write detection mentioned later is not needed for the time being, that's because we give it a delay, but if you want to use it, then take a good look at the datasheet~~~~ (To be honest: I don't know how to use the status word yet, if I do, I'll post back later~~haha)

4) RAM address map

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01
5) Instruction description (this is the key point~~ you can find the above as long as you find the datasheet~~~ ah~~ so annoying AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01)

5.1 Initialization settings:

5.1.1 Display mode settings:

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

Just write instruction 0x38

5.1.2 Display switch and cursor setting

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01
This is very simple. I have also watched teacher Guo Tianxiang's teaching video~~He used this to explain~~Hehe

5.2 Data Control (I’m so tired, I really don’t want to write anymore, just post the pictures~~)

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

The read data and write data in the picture are the read timing and write timing. They are all above, so I won’t post them~~

Okay, I simulated the picture

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

AVR microcontroller (learning) - (three), ATMEGA16 driving 16*2 dot matrix character LCD module - 01

Finally, the program~~

//------------------------------------------------------------------------------
//LCD1602 display program
#include "ioavr.h"
#include "intrinsics.h"
//------------------------------------------------------------------------------
typedef unsigned char uchar;
typedef unsigned int uint;
//------------------------------------------------------------------------------
//RS, RW, EN pin output high and low level macro definition
#define lcd_rs_1 PORTB|=1
#define lcd_rs_0 PORTB&=~1
#define lcd_rw_1 PORTB|=2
#define lcd_rw_0 PORTB&=~2
#define lcd_en_1 PORTB|=4
#define lcd_en_0 PORTB&=~4
//------------------------------------------------------------------------------
#define data_port PORTA
#define busy 0x80
#define xtal 8
//------------------------------------------------------------------------------
uchar __flash str0[]={"This is a LCD-!"};
uchar __flash str1[]={"Designed by ME"};
//------------------------------------------------------------------------------
//Delay 1ms function
void delay_1ms()
{
  uint i;
  for(i=1;i<(uint)(xtal*143-2);i++);
}
//------------------------------------------------------------------------------
//Delay nms function
void delay_nms(uint n)
{
  uint i=0;
  while(i  {
    delay_1ms();
    i++;
  }
}
//------------------------------------------------------------------------------
//LCD write data function
void lcd_write_data(uchar dat)
{
  lcd_rs_1;
  lcd_rw_0;
  data_port=dat;
  delay_1ms();
  lcd_en_1;
  delay_1ms();
  lcd_en_0;
}
//------------------------------------------------------------------------------
//LCD write command function
void lcd_write_command(uchar com)
{
  lcd_rs_0;
  lcd_rw_0;
  data_port=com;
  delay_1ms();
  lcd_en_1;
  delay_1ms();
  lcd_en_0;
}
//------------------------------------------------------------------------------
//LCD initialization function
void lcd_init()
{
  lcd_write_command(0x01);
  delay_1ms();
  lcd_write_command(0x38);
  delay_1ms();
  lcd_write_command(0x0c);
  delay_1ms();
  lcd_write_command(0x06);
  delay_1ms();
}
//------------------------------------------------------------------------------
//LCD display function
void lcd_display()
{
  uint num;
  lcd_write_command(0x80);
  for(num=0;num<16;num++)
  {
    lcd_write_data(str0[num]);
    delay_1ms();
  }
  lcd_write_command(0x80+0x40);
  for(num=0;num<16;num++)
  {
    lcd_write_data(str1[num]);
    delay_1ms();
  }
}
//------------------------------------------------------------------------------
//main
void main()
{
  delay_nms(100);
  DDRA=0XFF;
  PORTA=0X00;
  DDRB=0XFF;
  PORTB=0X00;
 
  lcd_init();
  lcd_display();
  while(1);
}


Reference address:AVR microcontroller - (three), ATMEGA16 drive 16 * 2 dot matrix character LCD module - 01

Previous article:AVR microcontroller (learning) - (IV), ATMEGA16 timer/counter - 01
Next article:AVR microcontroller (learning) - (II), ATMEGA16 interrupt system - 02

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

AVR microcontroller atmega16 automatic watering device Proteus simulation + source program
  The microcontroller source program is as follows: #include iom16v.h #include macros.h #define  key_bz   0b00000111 #define uchar  unsigned char #define  uint_16  unsigned short char smg_zx ={0x3f,0x06,0x5b,0x4f,0x66,0x6d, 0x7d,0x07,0x7f,0x6f,0x37}; // global variables char smg_wx ={0B00000001,0B00000010,0B0000010
[Microcontroller]
AVR microcontroller atmega16 automatic watering device Proteus simulation + source program
ATmega16 Development Board Simulation Tutorial - Preface
1. Basic knowledge Briefly introduce the hardware resources of the ATmega16 microcontroller, as well as the use of IAR software and the basic operations of Proteus8.9 simulation software. AVR microcontroller classification: ATtiny series: tiny13/15/26 are low-end and suitable for systems with relatively single fun
[Microcontroller]
ATmega16 Development Board Simulation Tutorial - Preface
Design of pneumatic marker control system based on ATmega16
1 Introduction Pneumatic marking machines are widely used in nameplates, various parts and automobile beams, but as demand changes, higher requirements are placed on the stability, portability and multi-tasking of marking machines. The marking software has been upgraded from the previous DOS system to Win98, Wi
[Microcontroller]
Design of pneumatic marker control system based on ATmega16
Design of intelligent lead-acid battery charger based on atmega16 microcontroller
Aiming at the problems of overcharging, undercharging, battery overheating and slow charging speed in the charging process of lead-acid batteries used in  intelligent controllers of feed switches of permanent magnetic actuators for mines, this paper proposes a design scheme of intelligent charger with atmega16 micr
[Power Management]
Design of intelligent lead-acid battery charger based on atmega16 microcontroller
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号