AVR 1602 LCD character movement

Publisher:YuexiangLatest update time:2015-06-23 Source: 51heiKeywords:AVR Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
#include
#include
#define uchar unsigned char
#define uint unsigned int
 uchar str1[16]="This is a ASCII";
 uchar str2[16]="      Test     ";
#include "1602.h"
void port_init()
{
  PORTA=0xff;
  DDRA=0xff;
  PORTB=0xff;
  DDRB=0xff;
  PORTD=0xff;
  DDRD=0xff;
}
void init()
{
  MCUCR=0x0a;
  GICR=0xc0;
  SREG=0x80;
}
void disline(uchar w) //Character movement function
{
  uchar i;
  for(i=0;i<16;i++)
  {
    displayonechar(i,1,w); //Characters are displayed on the second line, i.e. letters A--Z
    w++;
    if(w>90)w=65; //Character display is limited to A--Z
   
  }
  delay(500);
}
   
void main()
{
  uchar w=65;
  port_init();
  init();
  //1602 device initialization
   delay(15);
writecmd(0x38);
delay(5);
writecmd(0x38);
delay(5);
writecmd(0x38);
writecmd(0x80);
writecmd(0x01);
writecmd(0x06);
writecmd(0x0c);
delay(500);
  //End of initialization
    writecmd(0x01);
    writecmd(0x0c);
    displaychar(0,0,str1);
    delay(1000);
    writecmd(0x01);
    writecmd(0x0c);
    displaychar(0,1,str2);
    delay(1000);
    writecmd(0x01);
    writecmd(0x0c);
  while(1)
  { 
  disline(w++);               //字符移动模式 
  if(w>90)w=65;
  }
}

//-----------------1602 library function-----------------------
#define RS PORTB_Bit0
#define RW PORTB_Bit1
#define EN PORTB_Bit2
#define DATA PORTA
#define busy 0x80
[page]
void delay(int k)
{
  int i,j;
  for(i=0;i   {
    for(j=0;j<1140;j++);
  }
}
void wait()
{
  uchar val;
  DATA=0xff;
  RS=0;
  RW=1;
  __no_operation();
  __no_operation();
  EN=1;
  __no_operation();
  __no_operation();
  DDRA=0x00;
  val=PINA;
  while(val&busy)
  {
    val=PINA;
  }
  EN=0;
  DDRA=0xff;
}

void writecmd(uchar cmd)
{
  wait();
  RS=0;
  RW=0;
  __no_operation();
  DATA=cmd;
  __no_operation();
  EN=1;
  __no_operation();
  __no_operation();
  EN=0;
}
void writedata(uchar data)
{
  wait();
  RS=1;
  RW=0;
 __no_operation();
 DATA=data;
 __no_operation();
 EN=1;
 __no_operation();
 __no_operation();
 EN=0;
}
  
void displayonechar(uchar x,uchar y,uchar dda)
{
  y&=0x01;
  x&=0x0f;
  if(y)x|=0x40;
  x|=0x80;
  writecmd(x);
  writedata(dda);
}
 
void displaychar(uchar x,uchar y,uchar *p)
{
  y&=0x01;
  x&=0x0f;
  while(*p!='')
  {
    if(x<=0x0f)
    {
      displayonechar(x,y,*p);
      p++;
      x++;
    }
  }
}
Keywords:AVR Reference address:AVR 1602 LCD character movement

Previous article:AVR CTC mode waveform output experiment
Next article:AVR EEPROM simple experiment

Recommended ReadingLatest update time:2024-11-16 19:44

Main features of AVR microcontrollers
1) It has its own cheap program memory (FLASH) and non-volatile data memory (EEPROM). These memories can be electrically erased and rewritten many times, making program development experiments more convenient and working more reliable.  2) High speed and low power consumption. Under the same crystal oscillator conditi
[Microcontroller]
AVR MCU Tutorial - Button Status
Today we are going to talk about buttons. There are 4 buttons on the lower right corner of the development board, and there will be a noticeable "click" sound when pressed. How to detect whether the button is pressed? First, the button must be connected to the microcontroller directly or indirectly. Unlike the 4 LEDs
[Microcontroller]
Electronic engineers pass on their experience: classic experience in using AVR microcontrollers
Using better devices only creates a good foundation and possibility for designing and implementing a good system. If you still use and follow the traditional hardware and software design ideas and methods, you can't use AVR well, and you can't even really understand the characteristics and strengths of AVR.
[Analog Electronics]
Electronic engineers pass on their experience: classic experience in using AVR microcontrollers
Design of power management system based on AVR
    Preface     Nowadays, the wide application of aerial robot technology in many fields such as civil and national defense has been increasingly valued by people and has attracted the attention of experts and scholars from various countries. The small rotor robot is based on a model helicopter and is equipped with a
[Microcontroller]
Design of power management system based on AVR
AVR mega16 SPI dual-machine communication example that has been debugged
//ICC-AVR application builder : 2007-7-18 13:01:11 // Target : M16 // Crystal: 7.3728Mhz // 作者:古欣 // AVR与虚拟仪器 http://www.avrvi.com // 功能:SPI主机模式,循环发送从1~255 #include iom16v.h #include macros.h void port_init(void) { PORTA = 0x00; DDRA = 0x00; PORTB = 0x00; DDRB = 0x00; PORTC = 0x00; //m103 output only
[Microcontroller]
Implementation of AVR single button state machine
#include #include macros.h #include "1602.h" #define key_state_0  0 #define key_state_1  1 #define key_state_2  2 #pragma interrupt_handler timer0:20 flash unsigned char led_7 ={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f}; unsigned char time ; unsigned char time_counter,key_stime_counter; char po
[Microcontroller]
AVR AD conversion interrupt
System functions Most AVRs have internal AD. This section uses the internal AD of ATMEGA16 as an example to give the AD conversion interrupt program.    hardware design AVR main control circuit schematic diagram     AD conversion value low, LED control circuit schematic AD conversion value high, LED control c
[Microcontroller]
AVR AD conversion interrupt
PIC microcontroller LCD1602 display
P IC   single chip   LCD 1602 displays the website address and phone number ;************************************ PCL EQU 2H ;Define the low byte address of program memory STATUS EQU 3H ;Define the status register address PORTD EQU 8H ;Define the RD port data register address PORTC EQU 7H ;define the address of RC po
[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号