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

📄 lcd128x64.c

📁 这是一称的项目原文件,包括T9汉字输入,打印机,24C512,已经引用到产品上
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <intrins.h>         //液晶显示子程序
#include <LCD128x64.h>
#include <LCD_date_2.h>
#include <24C02.h>
#include <weight.h>
#include <print.h>
#include <set.h>

disp_num_address second_buffer = {0};
disp_num_address minute_buffer = {0};
disp_num_address hour_buffer = {0};

disp_num_address day_buffer = {0};
disp_num_address month_buffer = {0};
disp_num_address year_buffer = {0};
disp_num_address week_buffer = {0x20,0};

disp_num_address_1 save_type_buffer = {0};
disp_num_address_2 save_pizhong_buffer = {0};///修改

void delay3(void)
{	
   BYTE i,j,k;
   for(i = 0x16; i > 0; i--){
      for(j = 0xFF; j > 0; j--){
         for(k = 0xFF; k > 0; k--);
      }
   }
}

void delay2(void)
{	
   BYTE i,j;
   for(i = 0xC; i > 0; i--){
      for(j = 0x18; j > 0; j--);               
   }
}

void delay1(void)
{	
   BYTE i,j;
   for(i = 0x6; i > 0; i--){
      for(j = 0x8; j > 0; j--);               
   }
}

void delay4(void)
{	
   BYTE i,j;
   for(i = 200; i > 0; i--){
      for(j = 200; j > 0; j--);               
   }
}

void delay5(void)
{	
   BYTE i,j,k;
   for(i = 0x5; i > 0; i--){
      for(j = 0xFF; j > 0; j--){
         for(k = 0xFF; k > 0; k--);
      }
   }
}


void lcd_Check_Busy(void)
{
   P0 = 0xFF;
   LCD_D_C = 0;
   LCD_R_W = 1;
   LCD_EN  = 1;
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   delay2();
   LCD_EN  = 0;
}
/*
BYTE lcd_Read_Byte(void)
{
   BYTE value;
   
   lcd_Check_Busy();
   LCD_D_C = 1;
   LCD_R_W = 1;
   LCD_EN  = 1;
   _nop_();
   value = P0;
   LCD_EN  = 0;
   return value;
}
*/
void lcd_Write_Cmd(BYTE cmd)
{							
   lcd_Check_Busy();
    
   LCD_D_C = 0;
   LCD_R_W = 0;
   LCD_EN =  1;
   _nop_();
   _nop_();	
   P0 = cmd;
   _nop_();
   _nop_();
   _nop_();
   _nop_();
   LCD_EN = 0;
}


void lcd_Write_Dat(BYTE dat)	
{							
   lcd_Check_Busy();
   LCD_D_C = 1;
   LCD_R_W = 0;
   LCD_EN  = 1;

   P0 = dat;
   _nop_();
   _nop_();
   LCD_EN = 0;	
}

void lcd_Init(void)
{	                         //液晶初始化
   LCD_RST = 0;
   delay4();
   LCD_RST = 1;
   _nop_();
   LCD_P_S = 1;//并口
   P0 = 1;
   lcd_Write_Cmd(0x34); //34H--exp instruction
   lcd_Write_Cmd(0x30); //30H--base instruction
   lcd_Write_Cmd(0x0C); //clear disp
   lcd_Write_Cmd(0x01); //the direction of cursor move
   lcd_Write_Cmd(0x01); //open disp ,close cursor
}

void lcd_Disp_Clear(void)
{                               //液晶清屏
   lcd_Write_Cmd(0x01);
   lcd_Write_Cmd(0x34);
   lcd_Write_Cmd(0x30);
}
/*
void lcd_Disp_Text_Line_Break(BYTE *str)         显示字符
{
   BYTE COUNT;

   COUNT = 0x40;   
   lcd_Write_Cmd(0x80);
   //QUSHU
   for(;COUNT > 0;COUNT--) {
      lcd_Write_Dat(*str);
      str++;
      delay4();
   }
   //QUSHU end
   delay3();  
   flash();
}
*/

/*manipulate a pointer to a string, give the display address and the string's pointer
* use the standard unicode of character,directly send it to the lcd mode.
* support four lines and eight columns display ,the address is below:
* line1 :  0x80-0x87
* line2 :  0x90-0x97
* line3 :  0x88-0x8F
* line4 :  0x98-0x9F
*/
void lcd_Disp_Text_Line_Order(BYTE startaddress, BYTE *str) //chinese or character display in order
{
   //lcd_Disp_Clear();
   lcd_Write_Cmd(startaddress);
   //for(COUNT = 0x10;COUNT > 0;COUNT--) {//set the address counter 16。
   while(*str != 0){
      lcd_Write_Dat(*str);
      str++;
      //delay4();//delay for debug
   }
}
//dispalu a array just like a photo
void lcd_Disp_array(void)
{
   BYTE LCD_DATA1,LCD_DATA2,COUNT3,LCD_X,LCD_Y,COUNT2,COUNT1,LCD_DATA;
   BOOL flag;   
   		
   lcd_Disp_Clear();
   LCD_DATA1 = 0xCC;
   LCD_DATA2 = 0xCC;
   COUNT3    = 0x02;
   LCD_X     = 0x80;
   for(;COUNT3 > 0;COUNT3--){
      LCD_Y     = 0x80;
      flag      = 0;
      COUNT2    = 0x20;
      for (;COUNT2 > 0;COUNT2--){
         COUNT1    = 0x10;
         //WR_ZB
         lcd_Write_Cmd(0x34);
         lcd_Write_Cmd(LCD_Y);
         lcd_Write_Cmd(LCD_X);
         lcd_Write_Cmd(0x30);
   
         if (flag) 
            LCD_DATA = LCD_DATA2;
         else
            LCD_DATA = LCD_DATA1;
   
         for(;COUNT1 > 0;COUNT1--)   
            lcd_Write_Dat(LCD_DATA);
   
         LCD_Y++;
         flag = !flag;
      } 
      LCD_X = 0x88;
   }
   lcd_Write_Cmd(0x36);
   lcd_Write_Cmd(0x30);
}

/*in graphy mode the lcd is divided into two parts in vertical direction, every part is 32 lines
* the first part start address is (0x80,0x80),every line has 16 bytes,has the same address,the 
* second line address is (0x80,0x81),and so on,the last line address is (0x80,0x80+0x20);
* the second part start address is (0x88,0x80),every line has 16 bytes,has the same address,the 
* last line address is (0x88,0x80+0x20);
*/
void lcd_Disp_Pho(BYTE *value)                //显示图形
{
   BYTE LCD_X, LCD_Y, COUNT1, COUNT2, COUNT3;

   LCD_X  = 0x80;
   for(COUNT3 = 0x02;COUNT3 > 0;COUNT3--) {      //the section is divided into two parts
      LCD_Y  = 0x80;                             // both parts first line  Y address
      for(COUNT2 = 0x20;COUNT2 > 0;COUNT2--) {   // every part has 32 lines
         
         lcd_Write_Cmd(0x34);                    // start to give address
         lcd_Write_Cmd(LCD_Y);
         lcd_Write_Cmd(LCD_X);
         lcd_Write_Cmd(0x30);

         for(COUNT1 = 0x10;COUNT1 > 0;COUNT1--) {//every line has 16 bytes, equate  128 bits
            lcd_Write_Dat(*value);
            value++;
         }
         LCD_Y++;                                 //line  Y address add 1
      }
      LCD_X  = 0x88;                              // start the second part
   }
   lcd_Write_Cmd(0x36);
   lcd_Write_Cmd(0x30);
}

//display the five corner input char,has no use in the application
void lcd_Display_Lib_Char(void)                        //显示库里的字符
{
   BYTE COUNT,TEM;

   //lcd_Disp_Clear();
   COUNT = 0x40;   
   lcd_Write_Cmd(0x80);
   TEM = 0x10;
   for(;COUNT > 0;COUNT--){
      lcd_Write_Dat(TEM);
      TEM++;
   }
   delay3();
   lcd_Disp_Clear();
}

/*manipulate the lcd itself char lib,give the display address and the character's code
*support four lines and eight columns display ,the address is below:
* line1 :  0x80-0x87
* line2 :  0x90-0x97
* line3 :  0x88-0x8F
* line4 :  0x98-0x9F
*/
void lcd_Display_Lib_Chinese(BYTE startaddress, WORD ucode) //0xB9F3    //显示库里的汉字
{
   //lcd_Disp_Clear();
   lcd_Write_Cmd(0x80); //use its unicode
   lcd_Write_Cmd(startaddress);//give address

   lcd_Write_Dat(ucode >> 8);   //the high byte
   lcd_Write_Dat(ucode & 0xFF);    //the low byte
}

void LCD_Flash(void)                        //闪动
{ 
   lcd_Write_Cmd(0x08);//close disp 
   delay5();
   lcd_Write_Cmd(0x0c);//open disp,close cursor
   delay5();
   lcd_Write_Cmd(0x08);//close disp 
   delay5();
   lcd_Write_Cmd(0x0c);//open disp,close cursor
   delay5();
   lcd_Write_Cmd(0x08);//close disp 
   delay5();
}

void lcd_clear_line(BYTE linenum)                   //清除某一行
{
   BYTE count,start_address;

   switch (linenum){
      case 0:
         start_address = 0x80;
         break;

⌨️ 快捷键说明

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