AVR M16 Experiment 2 LCD1602 Display

Publisher:学海星空Latest update time:2015-11-12 Source: eefocusKeywords:AVR  M16 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
/**********************************************************************
* File name: main.c
* Program author: kidcao1987
* Program version: V1.0
* Function description: Install LCD1602 and use it to display on LCD1602. It is recommended to connect an external power supply.
"This a LCD demo!
www.CEPARK.com
Keep moving!!
By:kicao1987"
* Compiler: WinAVR-20090313
* Chip: ATmega16, external 11.0592MHZ crystal oscillator
* Technical support: http://bbs.cepark.com
***********************************************************************/
#include 
#include 

#define SETLCD1602RS PORTA |= (1<#define CLRLCD1602RS PORTA &= ~(1<#define SETLCD1602RW PORTA |= (1<#define CLRLCD1602RW PORTA &= ~(1<#define SETLCD1602EN PORTA |= (1<#define CLRLCD1602EN PORTA &= ~(1<
unsigned char const ucString1[]={"This a LCD demo!"};
unsigned char const ucString2[]={" www.CEPARK.com "}; 
unsigned char const ucString3[]={" Keep moving!! "};
unsigned char const ucString4[]={" By:kicao1987 "};

void LCD1602BusyCheck(void); //Busy detection
void LCD1602WriteOperation(unsigned char,unsigned char); //Write operation
void LCD1602Init(void); //Initialization function
void LCD1602MoveToPosition(unsigned char,unsigned char); //Locate to the specified position
void LCD1602PrintString(unsigned char const * str); //Output a string of characters

int main(void)
{
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
LCD1602Init();
while(1)
{
LCD1602MoveToPosition(0,0);
LCD1602PrintString(ucString1);
LCD1602MoveToPosition(1,0);
LCD1602PrintString(ucString2);
_delay_ms(5000); //Delay 5 milliseconds
LCD1602MoveToPosition(0,0);
LCD1602PrintString(ucString3);
LCD1602MoveToPosition(1,0); //Delay 5 milliseconds
LCD1602PrintString(ucString4);
_delay_ms(5000);
}
}


//Busy detection
void LCD1602BusyCheck(void)
{
unsigned char i = 254;
DDRB = 0x00; //Set the highest bit to input
CLRLCD1602RS;
SETLCD1602RW;
SETLCD1602EN;
_delay_us(5);
while((i--) && (PINB & 0x80));
DDRB = 0xff;
_delay_us(5);
CLRLCD1602EN;
_delay_us(5);
}



//Write operation
void LCD1602WriteOperation(unsigned char Data,unsigned char ComOrData) 
{
LCD1602BusyCheck(); //ComOrData=0 is command, 1 is data

if(0 == ComOrData)
CLRLCD1602RS;
else if(1 == ComOrData)
SETLCD1602RS;
CLRLCD1602RW;
SETLCD1602EN;
_delay_us(5);
PORTB = Data;
_delay_us(5);
CLRLCD1602EN;
_delay_us(100);
}


void LCD1602Init(void) //Initialization

LCD1602WriteOperation(0x38,0);
_delay_ms(15);
LCD1602WriteOperation(0x38,0);
_delay_ms(5);
LCD1602WriteOperation(0x38,0);
_delay_ms(5);
LCD1602WriteOperation(0x38,0);
_delay_ms(5);

LCD1602WriteOperation( 0x0c,0);
_delay_ms(1);
LCD1602WriteOperation(0x06,0);
_delay_ms(1);
LCD1602WriteOperation(0x01,0);
_delay_ms(1);
}



void LCD1602MoveToPosition(unsigned char ucx,unsigned char ucy) 
{
if(0 == ucx) //First line
{
LCD1602WriteOperation(0x80 + ucy,0); //Yth column
}
if(1 == ucx) //Second row
{
LCD1602WriteOperation(0xC0 + ucy,0); //第Y列
}
}


void LCD1602PrintString(unsigned char const * str)
{
while(*str != '')
{
LCD1602WriteOperation(*str,1);
str++;
}
}

 

Video address: http://v.youku.com/v_show/id_XMTYxNDg1MDQ0.html

Keywords:AVR  M16 Reference address:AVR M16 Experiment 2 LCD1602 Display

Previous article:AVR M16 Experiment 3 PWM Experiment
Next article:AVR M16 Experiment 1: LED Flashing

Recommended ReadingLatest update time:2024-11-17 00:44

AVR microcontroller's CPU core structure and assembly language
I have been studying microcontrollers for so long, and I feel that if I want to go deeper, I have to read assembly language, or at least understand the internal structure of the microcontroller. Below, we will take ATmega16 as an example to introduce the AVR microcontroller structure and assembly language. AVR mic
[Microcontroller]
AVR microcontroller's CPU core structure and assembly language
LED drive control dedicated circuit TM1628 AVR test program source code
#include avr/io.h #include util/delay.h #define TM1628_DIO_PORTNAME     B #define TM1628_DIO_BIT          5 #define TM1628_CLK_PORTNAME     B #define TM1628_CLK_BIT          7 #define TM1628_STB_PORTNAME     B #define TM1628_STB_BIT          4 #ifndef _CONCAT_ #define _CONCAT_ #define CONCAT(a, b)            a ##
[Microcontroller]
AVR MEGA8 reads and writes 93C46 via SPI bus
       AVR MEGA8 reads and writes 93C46 via SPI bus. It is mainly to practice the use of SPI bus. The driver of 93C46 is quite simple. The code is also easy to write and debug. The code has been in cold storage for a while, and I am too lazy to organize it. I just copy it out and take a look at it.     /*  * Projec
[Microcontroller]
AVR fuse setting tutorial
Introduction: The configuration of AVR fuse bits is a relatively delicate task, and users often overlook its importance or find it difficult to master. Here are some key points and related matters that need to be paid attention to when configuring the AVR fuse bits. (1) In the AVR device manual, the fuse bit is defi
[Microcontroller]
ATtiny13 I/O Memory
ATtiny13 I/O P150 "Register Overview". All ATtiny13 I/O and peripherals are placed in I/O. I/O locations can be accessed through LD/LDS/LDD and ST/STS/STD instructions to transfer data between 32 general working registers and I/O. I/O registers with addresses 0x00 - 0x1F can also be directly bit-addressed using SBI a
[Microcontroller]
AVR register configuration assistant made with excel --- easily handle AVR
/***********************************************************  -Function description: boot initialization  -Parameter Description: None -Return Description: None ***********************************************************/ void Init_Start(void) {   ADC_InitTypeDef ADC_InitStruct;      /*ADC configuration*/   ADC_InitSt
[Microcontroller]
AVR register configuration assistant made with excel --- easily handle AVR
AVR MCU Timing Counter Study Notes Sharing
  The structure and application of timer counters Timer counters (Timer/Counter) are often used for counting, delaying, measuring cycle, frequency, pulse width, providing timing pulse signals, etc. In practical applications, the measurement of physical quantities such as rotation speed, displacement, speed, flow, etc.
[Microcontroller]
AVR MCU Timing Counter Study Notes Sharing
Using serial communication to implement ISP download of AVR
I have been reading Xinyi's AVR tutorials recently and I am ready to make a serial port download tool myself. The idea is very simple. I will use the serial port interaction to send data to the AVR microcontroller, implement the real download function in the microcontroller, and download programs to other microcontrol
[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号