⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 t_lcd.c

📁 schduler for AVR mcu
💻 C
字号:
/*
------------------------------------------------------------------*-

   T_Lcd.C (v1.00)

  ------------------------------------------------------------------
   
   LCD display  program (Test Version 1.0)


   COPYRIGHT
   ---------

   This code is from the book:

   PATTERNS FOR TIME-TRIGGERED EMBEDDED SYSTEMS by Michael J. Pont 
   [Pearson Education, 2001; ISBN: 0-201-33138-1].

   This code is copyright (c) 2001 by Michael J. Pont.
 
   --- Modefied by  sylva zhu to apply for  AVR Microcontroller .
   --- Ver 1.0  Sept 25th , 2006 .

-*------------------------------------------------------------------
*/
#include  <iom32.h>
#include  <inavr.h>
#include  <comp_a90.h>

#include  "T_Lcd.h"
//
//------------------------------------------------------------------
//
void DelayL(void)
{
 unsigned char i,j;
 i=0xff;
 j=0xff;
 while(i--)
 while(j--);
 }
//
void DelayS(void)
{
 unsigned char i;
 i=0x5f;
 while(i--);
 }
//
void WriteCommand(unsigned char Command)
{
 LCD_I();    // COMMAND
 LCD_R();
 LCD_EN();
 _NOP();
 _NOP();
 //
 DelayS();
 LCD_DISEN();
 LCD_I();
 LCD_W();
 _NOP();
 _NOP();
 LCD_EN();
 PORTB=Command;
 _NOP();
 _NOP();
 LCD_DISEN();
 _NOP();
 }
//
void WriteData(unsigned char Data)
{

 LCD_I();   // COMMAND
 LCD_R();
 LCD_EN();
 _NOP();
 _NOP();
 //
 DelayS();
 LCD_DISEN();
 LCD_D();
 LCD_W();
 _NOP();
 _NOP();
 LCD_EN();
 _NOP();
 _NOP();
 PORTB=Data;
 _NOP();
 _NOP();
 LCD_DISEN();
 _NOP();
 LCD_I();
 }
//
void ShowChar(unsigned char Pos,unsigned char Data)
{
 unsigned char p;//change to line ,collumn

 //line 1****0x00
 //line 2****0x40
 //line 3****0x14
 //line 4****0x54
 if(Pos<20)
    {
      p=Pos+0;
     }
 else if((Pos<40)&&(Pos>=20))
         {
           p=Pos+0x40-20;
          }
 else if((Pos<60)&&(Pos>=40))
         {
           p=Pos+0x14-40;
          }
 else if((Pos<80)&&(Pos>=60))
         {
           p=Pos+0x54-60;
          }

 WriteCommand(p+0x80);//DDRAM ADDRESS SET
 WriteData(Data);
 }
//
void ShowString(unsigned char line ,  unsigned char __flash  *ptr)
{
 unsigned char row,i;

 if(line==0)
   {
     row=0;
    }
 else if(line==1)
   {
     row=0x14;
    }
 else if(line==2)
   {
     row=0x28;
    }
 else if(line==3)
   {
     row=0x3C;
    }
 for(i=0;i<20;i++)
    ShowChar(row++,*(ptr+i));
 }
//
void InitLcd(void)
{
   DelayL();
   DelayL();
   DelayL();
   DelayL();
   DelayL();
   DelayL();
   //long delay wait more than 15ms

 WriteCommand(0x38);//set display mode
 DelayL();
 DelayL();
 DelayL();//wait for more than 4.1ms
 WriteCommand(0x38);
 DelayL();//wait for 100us
 WriteCommand(0x38);
 _NOP();
 WriteCommand(0x3c);//set Duty , character font,8 bits interface
 _NOP();
 WriteCommand(0x08);// lcd off , cursor off, blink off
 _NOP();
 WriteCommand(0x0c);//lcd on
 WriteCommand(0x06);//entry mode set :increment , No shift

 WriteCommand(0x01);//Clear LCD
 WriteCommand(0x00);//set cursor to 0,0 position
}



































































⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -