×
单片机 > 单片机程序设计 > 详情

12864(带字库)串行方式显示汉字和字库-CVAVR程序

发布时间:2020-05-26 发布时间:
|
// HS12864-15B —— 串行  

// 带字库
// 芯片 ATMEGA16L 
// 时钟 4MHz 内部
// 采用系统自带延时程序  
// 检测忙闲 
// 功能1:显示汉字和字母
// 功能2:图形显示,显示横线、竖线、边框、128*64图像、64*64图像,图形显示较慢
// 注意:采用了文本区和图形区清零函数,汉字和图形显示切换时要注意,基本指令集和扩充指令集的转换    
// 保存图像的数组最后不能有逗号

#include  
#include

#define  cs        PORTD.2  // 片选信号
#define  sid       PORTD.3  // 串行数据线输出  
#define  sid_in    3        // 串行数据线输入
#define  sclk      PORTD.4  // 时钟输入线
#define  psb       PORTD.5  // psb=H,并口模式, psb=L,串口模式
#define  rst       PORTD.6  // LCD复位,低有效
#define  run       PORTB.7  // 运行标志

void LCD_send_byte(unsigned char a);      // LCD写数据  
unsigned char LCD_read_byte(void);        // LCD读数据  
void chk_busy(void);                      // 检测忙闲
void init_lcd(void);                      // 初始化
void wr_data(unsigned char dat);          // 写数据到LCD
void wr_comm(unsigned char comm);         // 写命令到LCD
void img_disp(unsigned char flash *img);  // 显示图片128*64
void img_disp2(unsigned char flash *img); // 显示图片64*64  左半屏
void img_disp3(unsigned char flash *img); // 显示图片64*64  右半屏
void lcdfill(unsigned char disdata);      // 整屏全亮或显示竖条
void Disp_H_Line(void);                   // 显示横条
void frame(void);                         // 显示边框 
void wr_str(unsigned char flash *s);      // 写字符串
void hz_disp(void);                       // 写汉字或字母
void LcdClearTXT(void);                   // 文本区RAM清零
void LcdClearBMP(void);                   // 图形区RAM清零
                                                            
flash unsigned char ex1[] = {"泰  山  电 子"};  //字符串以结束
flash unsigned char ex2[] = {"  欢  迎  您  "};
flash unsigned char ex3[] = {"TAI SHAN DIAN ZI"};  
flash unsigned char ex4[] = {"Wellcome to you!"};   
flash unsigned char ex5[] = {"黄河远上白云间"}; 
flash unsigned char ex6[] = {"一片孤城万仞山"};
flash unsigned char ex7[] = {"羌笛何须怨杨柳"};  
flash unsigned char ex8[] = {"春风不度玉门关"};
flash unsigned char ex9[] = {"TAI SHAN DIAN ZI"}; 
flash unsigned char ex10[] = {"Designer:Charlie"};  

flash unsigned char tab[]={ 
/*--  调入了一幅图像:联通图标 4567.bmp  --*/
/*--  宽度x高度=128x64  --*/
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X07,0XFF,0X00,0X00,0X1F,0XFC,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X3F,0XFF,0XE0,0X00,0XFF,0XFF,0X80,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0XFF,0XFF,0XF8,0X03,0XFF,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFE,0X0F,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XFF,0XBF,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFF,0X8F,0XFF,0XFF,0XFE,0X3F,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFC,0X03,0XFF,0XFF,0XF0,0X07,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XF8,0X00,0XFF,0XFF,0XE0,0X07,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XF8,0X00,0X3F,0XFF,0X80,0X03,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFC,0X00,0X7F,0XFF,0XC0,0X07,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFC,0X01,0XFF,0XFF,0XF0,0X0F,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0X07,0XFF,0XFF,0XFC,0X1F,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0XC7,0XFF,0XFF,0XF8,0X7F,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0XFF,0XE1,0XFF,0X1F,0XF1,0XFF,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0XFF,0XF8,0X7C,0X0F,0XC3,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X7F,0XFE,0X10,0X03,0X0F,0XFF,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X1F,0XFF,0X00,0X00,0X3F,0XFF,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X7E,0X00,0X00,0X07,0XFF,0XC0,0X00,0X7F,0XFC,0X00,0X00,0X0F,0X80,0X00,
0X00,0X07,0XFF,0XF0,0X00,0X63,0XFF,0XF0,0X01,0XFF,0XF0,0XC0,0X01,0XFF,0XFC,0X00,
0X00,0X3F,0XFF,0XFC,0X01,0XF8,0XFF,0XF8,0X07,0XFF,0XE3,0XF0,0X07,0XF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,0X07,0XFF,0XE0,0X00,0X43,0XFF,0XE0,0X01,0XFF,0XF8,0XC0,0X00,0XFF,0XF8,0X00,
0X00,0X00,0X00,0X00,0X00,0X0F,0XFF,0XC0,0X00,0X7F,0XFC,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X1F,0XFF,0X00,0X00,0X3F,0XFF,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X7F,0XFC,0X30,0X03,0X0F,0XFF,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X01,0XFF,0XF8,0XFC,0X0F,0XC3,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0XFF,0XE1,0XFF,0X3F,0XF1,0XFF,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0X87,0XFF,0XFF,0XF8,0X7F,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFF,0X07,0XFF,0XFF,0XFC,0X1F,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFC,0X01,0XFF,0XFF,0XF0,0X0F,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X1F,0XF8,0X00,0X7F,0XFF,0XC0,0X07,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X1F,0XF8,0X00,0X7F,0XFF,0X80,0X03,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XF8,0X00,0XFF,0XFF,0XE0,0X07,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFC,0X03,0XFF,0XFF,0XF0,0X0F,0XFE,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X0F,0XFF,0X9F,0XFF,0XFF,0XFE,0X7F,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X07,0XFF,0XFF,0XFF,0X3F,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFC,0X0F,0XFF,0XFF,0XF0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0XFF,0XFF,0XF8,0X03,0XFF,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X3F,0XFF,0XE0,0X00,0XFF,0XFF,0X80,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X07,0XFE,0X00,0X00,0X1F,0XFC,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00
};

flash unsigned char tab2[]={
/*--  调入了一幅图像:移动图标 123456.bmp  --*/
/*--  宽度x高度=128x64  --*/
0X00,0X00,0X00,0X00,0X00,0X00,0X0F,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X0F,0XFF,0XFF,0XFF,0XFF,0XF0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X01,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X01,0XFF,0XFF,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F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XE0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X1F,0XFF,0XFF,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X3F,0XFF,0XFF,0XFE,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XCF,0XE6,0X00,0X00,0X00,0X00,0X00,0X00,0X00
};
flash unsigned char tab3[]={
/*--  调入了一幅图像:移动图标 1234.bmp  --*/
/*--  宽度x高度=64x64  --*/
0X00,0X00,0X00,0X3F,0XFE,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XC0,0X00,0X00,
0X00,0X00,0X0F,0XFF,0XFF,0XF8,0X00,0X00,0X00,0X00,0X7F,0XFF,0XFF,0XFE,0X00,0X00,
0X00,0X00,0XFF,0XFF,0XFF,0XFF,0X80,0X00,0X00,0X03,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,
0X00,0X07,0XFF,0XF0,0X07,0XFF,0XF0,0X00,0X00,0X0F,0XFF,0XE0,0X01,0XFF,0XF8,0X00,
0X00,0X1F,0XFF,0X80,0X00,0XFF,0XFC,0X00,0X00,0X7F,0XFF,0X00,0X00,0X7F,0XFE,0X00,
0X00,0X7F,0XFE,0X00,0X00,0X1F,0XFF,0X00,0X00,0XFF,0XFC,0X00,0X78,0X0F,0XFF,0X80,
0X01,0XFF,0XF0,0X01,0XFE,0X07,0XFF,0XC0,0X03,0XFF,0XE0,0X03,0XFF,0X83,0XFF,0XC0,
0X03,0XFF,0XC0,0X0F,0XFF,0XC0,0XFF,0XE0,0X07,0XFF,0X80,0X1F,0XFF,0XE0,0X7F,0XF0,
0X0F,0XFF,0X00,0X3F,0X83,0XF0,0X3F,0XF0,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0XFC,
0X1F,0XF8,0X1F,0X00,0X3F,0X00,0X1F,0XF8,0X0F,0XFC,0X0F,0X80,0X7E,0X00,0X3F,0XF8,
0X0F,0XFE,0X07,0XE1,0XFC,0X00,0XFF,0XF0,0X07,0XFF,0X81,0XFF,0XF8,0X01,0XFF,0XF0,
0X07,0XFF,0XC0,0XFF,0XE0,0X03,0XFF,0XE0,0X03,0XFF,0XE0,0X7F,0XC0,0X07,0XFF,0XE0,
0X01,0XFF,0XF0,0X3F,0X80,0X1F,0XFF,0XC0,0X00,0XFF,0XF8,0X00,0X00,0X3F,0XFF,0X80,
0X00,0XFF,0XFE,0X00,0X00,0X7F,0XFF,0X00,0X00,0X7F,0XFF,0X00,0X00,0XFF,0XFE,0X00,
0X00,0X3F,0XFF,0X80,0X01,0XFF,0XFC,0X00,0X00,0X1F,0XFF,0XC0,0X07,0XFF,0XF8,0X00,
0X00,0X07,0XFF,0XF0,0X0F,0XFF,0XF0,0X00,0X00,0X03,0XFF,0XFC,0X3F,0XFF,0XE0,0X00,
0X00,0X01,0XFF,0XFF,0XFF,0XFF,0X80,0X00,0X00,0X00,0X7F,0XFF,0XFF,0XFE,0X00,0X00,
0X00,0X00,0X1F,0XFF,0XFF,0XFC,0X00,0X00,0X00,0X00,0X03,0XFF,0XFF,0XE0,0X00,0X00,
0X00,0X00,0X00,0X7F,0XFF,0X00,0X00,0X00,0X00,0X00,0X00,0X0B,0XD0,0X00,0X00,0X00
};

flash unsigned char tab4[]={
/*--  调入了一幅图像:联通图标 45678.bmp  --*/
/*--  宽度x高度=64x64  --*/
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00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FC,0X0F,0XFC,0X0F,0XF8,0X3E,0X1F,0X8F,0XFE,0X1F,0XFC,0X1F,0XFC,0X7E,
0X0F,0XFF,0XFF,0X1F,0XFE,0X3F,0XFF,0XFC,0X0F,0XFF,0XBF,0X3F,0X7F,0X3F,0X7F,0XFC,
0X07,0XFF,0X1E,0X7F,0X3F,0X9E,0X3F,0XF8,0X03,0XFE,0X0C,0XFE,0X1F,0XCC,0X1F,0XF0,
0X01,0XFC,0X01,0XFC,0X0F,0XE8,0X0F,0XE0,0X00,0X00,0X03,0XF8,0X07,0XE0,0X00,0X00,
0X00,0X00,0X03,0XF0,0X07,0XF0,0X00,0X00,0X00,0X00,0X07,0XE4,0X13,0XF8,0X00,0X00,
0X00,0X00,0X0F,0XEE,0X39,0XFC,0X00,0X00,0X00,0X00,0X1F,0XCF,0X7C,0XFC,0X00,0X00,
0X00,0X00,0X1F,0X9F,0XFE,0X7E,0X00,0X00,0X00,0X00,0X3F,0X1F,0XFE,0X3E,0X00,0X00,
0X00,0X00,0X3E,0X0F,0XFC,0X3F,0X00,0X00,0X00,0X00,0X3E,0X07,0XF8,0X1F,0X00,0X00,
0X00,0X00,0X3E,0X07,0XF8,0X1F,0X00,0X00,0X00,0X00,0X3E,0X0F,0XFC,0X1F,0X00,0X00,
0X00,0X00,0X3E,0X1F,0XFC,0X3F,0X00,0X00,0X00,0X00,0X3F,0XBF,0XFF,0X7E,0X00,0X00,
0X00,0X00,0X1F,0XFF,0X7F,0XFE,0X00,0X00,0X00,0X00,0X1F,0XFE,0X3F,0XFC,0X00,0X00,
0X00,0X00,0X0F,0XFE,0X1F,0XFC,0X00,0X00,0X00,0X00,0X07,0XFC,0X0F,0XF8,0X00,0X00,
0X00,0X00,0X01,0XF0,0X03,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00
};

void main(void)
{  
  delay_ms(200); 
  PORTB = 0xff;
  DDRB  = 0xff;        // PORTB.7输出,作为运行标志
  init_lcd();          // LCD初始化,并清屏   
  LcdClearTXT();       // 文本区RAM清零
  LcdClearBMP();       // 图形区RAM清零
  run = 0;             // 运行标志亮
  while(1)
  {  
    hz_disp();         // 显示汉字或字母    
    LcdClearTXT();     // 文本区RAM清零
    
    lcdfill(0xff);     // 显示全亮
    delay_ms(1000);
    run = ~run;

    Disp_H_Line();     // 显示横条
    delay_ms(1000); 
    run = ~run;

    lcdfill(0xaa);     // 显示竖条
    delay_ms(1000); 
    run = ~run;

    frame();           // 显示边框
    delay_ms(1000); 
    run = ~run;  
    
    img_disp(tab);     // 显示联通图标128*64
    delay_ms(1000); 
    run = ~run;

    img_disp(tab2);    // 显示移动图标128*64
    delay_ms(1000);
    run = ~run;

    img_disp2(tab3);   // 显示移动图标64*64
    img_disp3(tab4);   // 显示联通图标64*64
    delay_ms(1000); 
    run = ~run;   
    
    LcdClearBMP();     // 图形区RAM清零
    
  }       
}  
/*------------------LCD写数据-----------------*/
void LCD_send_byte(unsigned char a)
{
  unsigned char i;  
  for(i=0;i<8;i++)
  { 
    sclk = 0;
    delay_us(2); 
    if(a&0x80)
      sid = 1;
    else
      sid = 0;
    delay_us(2);
    a = a<<1;
    sclk = 1;
    delay_us(2);  
    sclk = 0;
    delay_us(2); 
  } 

/*-------------------------LCD读数据-------------------------*/  
unsigned char LCD_read_byte(void)
{
  unsigned char i,dat,dat2; 
  dat=dat2=0; 
  DDRD  &= ~(1<   PORTD &= ~(1<   delay_us(2); 
  for(i=0;i<8;i++)          // 读高字节
  {    
    dat = dat<<1;
    sclk = 0;
    delay_us(2); 
    sclk = 1;
    delay_us(2);
    if((PIND&(1<     sclk = 0;
    delay_us(2); 
  }     
  for(i=0;i<8;i++)          // 读低字节
  {    
    dat2 = dat2<<1;
    sclk = 0;
    delay_us(2); 
    sclk = 1;
    delay_us(2);
    if((PIND&(1<     sclk = 0;
    delay_us(2); 
  } 
  dat = (dat&0xf0) + (dat2&0x0f);
  DDRD  |= 1<   delay_us(2);  
  return dat;
}
/*--------------检测LCD忙闲---------------*/
void chk_busy(void)

  unsigned char dat;  
  do 
  {
    cs = 1;
    delay_us(2);
    LCD_send_byte(0xfc);
    dat = LCD_read_byte();
    delay_us(2);
    cs = 0;
    delay_us(2); 
  }while(dat&0x80); 
}
/*------------------LCD初始化-----------------*/
void init_lcd(void)

  PORTD = 0xff;
  DDRD  = 0xff;   // PD输出,提供LCD控制信号   
  sclk = 0;
  cs = 0;
  rst = 0;
  delay_ms(2);
  rst = 1;  
  delay_ms(10);
  psb = 0;       // 串行 
  delay_us(2);
  wr_comm(0x30); // 基本指令,8位数据模式
  wr_comm(0x0C); // 显示开,游标关,反白关
  wr_comm(0x01); // 清除显示,并且设定地址指针为00H
  wr_comm(0x06); // 指定在资料的读取及写入时,设定游标的移动方向及指定显示的移位       
}
/*------------写命令到LCD--------------*/
void wr_comm(unsigned char comm)
{  
  unsigned char temp;  
  chk_busy();
  cs = 1;
  delay_us(2);
  LCD_send_byte(0xf8);   // 写命令
  temp = comm&0xf0;
  LCD_send_byte(temp);  // 写高字节
  temp=(comm&0x0f)<<4;
  LCD_send_byte(temp);  // 写低字节
  delay_us(2);
  cs = 0;
}
/*------------写数据到LCD--------------*/
void wr_data(unsigned char dat)

  unsigned char temp;       
  chk_busy();
  cs = 1;
  delay_us(2);
  LCD_send_byte(0xfa);   // 写数据
  temp = dat&0xf0;
  LCD_send_byte(temp);   // 写高字节
  temp = (dat&0x0f)<<4;
  LCD_send_byte(temp);   // 写低字节
  delay_us(2);         
  cs = 0;
}  
/*-------向LCD写一个字符串,长度64字符之内---------- */
void wr_str(unsigned char flash *s)
{
   while(*s>0)
   {
      wr_data(*s);
      s++;
   }
}
/*------------显示汉字或字母--------------*/
void hz_disp(void)
{  
   wr_comm(0x30); // 基本指令,8位数据模式
   wr_comm(0x01); // 清除显示,并且设定地址指针为00H

   /*-显示4行汉字-*/
   wr_comm(0x80);     // 第 1 行
     wr_str(ex1); 
   wr_comm(0x90);     // 第 2 行
     wr_str(ex2);
   wr_comm(0x88);     // 第 3 行
     wr_str(ex3);
   wr_comm(0x98);     // 第 4 行
     wr_str(ex4);  
   run = ~run;
   delay_ms(3000);    // 延时
   wr_comm(0x01);     // 清除显示
   /*-显示4行汉字-*/
   wr_comm(0x80);
     wr_str(ex5);
   wr_comm(0x90);
     wr_str(ex6);
   wr_comm(0x88);
     wr_str(ex7);
   wr_comm(0x98);
     wr_str(ex8);  
    run = ~run;
   delay_ms(3000);
   wr_comm(0x01);     // 清除显示
   /*-显示2行字母-*/
   wr_comm(0x80);
     wr_str(ex9);  
   wr_comm(0x88);
     wr_str(ex10);
    run = ~run;
   delay_ms(3000);  
   wr_comm(0x01);     // 清除显示
}   
/*--------------------------- 显示图片,128*64 --------------------------- */
void img_disp(unsigned char flash *img)
{
  unsigned char i,x,y;
  unsigned int j=0;
  for(i=0;i<9;i=i+8)       // i=0,控制上半屏,i=8,控制下半屏
  {
    for(y=0;y<32;y++)      // y控制行地址
    {
      for(x=0;x<8;x++)     // x控制列地址
      {
        wr_comm(0x36);     // 功能设置:8位控制界面,扩充指令集,绘图显示开
        wr_comm(0x80+y);   // 行地址
        wr_comm(0x80+x+i); // 列地址  x+i=0~7, 上半屏,x+i=8~15,下半屏
        wr_data(img[j++]); // 高字节
        wr_data(img[j++]); // 低字节
        wr_comm(0x30);     // 功能设置:8位控制界面,基本指令集,绘图显示关
      }
    }
  }
}
/*------------------------ 显示图片,64*64 ------------------------------ */
void img_disp2(unsigned char flash *img)   // 左半屏
{
  unsigned char i,x,y;
  unsigned int j=0;
  for(i=0;i<9;i=i+8)       // i=0,控制上半屏,i=8,控制下半屏
  {
    for(y=0;y<32;y++)      // y控制行地址
    {
      for(x=0;x<4;x++)     // x控制列地址
      {
        wr_comm(0x36);     // 功能设置:8位控制界面,扩充指令集,绘图显示开
        wr_comm(0x80+y);   // 行地址
        wr_comm(0x80+x+i); // 列地址  x+i=0~7, 上半屏,x+i=8~15,下半屏
        wr_data(img[j++]); // 高字节
        wr_data(img[j++]); // 低字节
        wr_comm(0x30);     // 功能设置:8位控制界面,基本指令集,绘图显示关
      }
    }
  }
}
/*------------------------- 显示图片,64*64 ----------------------------- */
void img_disp3(unsigned char flash *img)    //  右半屏
{
  unsigned char i,x,y;
  unsigned int j=0;
  for(i=0;i<9;i=i+8)       // i=0,控制上半屏,i=8,控制下半屏
  {
    for(y=0;y<32;y++)      // y控制行地址
    {
      for(x=4;x<8;x++)     // x控制列地址
      {
        wr_comm(0x36);     // 功能设置:8位控制界面,扩充指令集,绘图显示开
        wr_comm(0x80+y);   // 行地址
        wr_comm(0x80+x+i); // 列地址  x+i=0~7, 上半屏,x+i=8~15,下半屏
        wr_data(img[j++]); // 高字节
        wr_data(img[j++]); // 低字节
        wr_comm(0x30);     // 功能设置:8位控制界面,基本指令集,绘图显示关
      }
    }
  }
}
/*-------  整屏填充,全亮,或者竖条  -------- */
void lcdfill(unsigned char disdata)  
{
  unsigned char x,y;
  for(y=0;y<32;y++)
  {
    for(x=0;x<16;x++)
    {
      wr_comm(0x36);
      wr_comm(y+0x80);     //行地址
      wr_comm(x+0x80);     //列地址
      wr_comm(0x30);
      wr_data(disdata);
      wr_data(disdata);
    }
  }
}
/*--------------- 显示横条 -----------------*/
void Disp_H_Line()
{  unsigned char x,y;
   unsigned char k=0x00;
   for(y=0;y<32;y++)
   { k=~k;
     for(x=0;x<16;x++)
     {
       wr_comm(0x36);
       wr_comm(y+0x80);     //行地址
       wr_comm(x+0x80);     //列地址
       wr_comm(0x30);
       wr_data(k);
       wr_data(k);
     }
   }
}
/*---------------- 显示边框 ----------------*/
void frame()
{
  unsigned char x,y;
  lcdfill(0x00);
  for(x=0;x<9;x+=8)
  {
    for(y=0;y<32;y++)
    {
      wr_comm(0x36);
      wr_comm(y+0x80);      //行地址
      wr_comm(x+0x80);      //列地址
      wr_comm(0x30);
      wr_data(0x80);
      wr_data(0x00);

      wr_comm(0x36);
      wr_comm(y+0x80);      //行地址
      wr_comm(x+0x87);      //列地址
      wr_comm(0x30);
      wr_data(0x00);
      wr_data(0x01);
    }
  }
  for(y=0;y<2;y++)
  {
    for(x=0;x<8;x++)
    {
      wr_comm(0x36);
      wr_comm(y*31+0x80);      //行地址
      wr_comm(x+0x80+8*y);     //列地址
      wr_comm(0x30);
      wr_data(0xff);
      wr_data(0xff);
    }
  }
}   
/*----------------文本区清RAM函数----------------*/
void LcdClearTXT(void)
{
     unsigned char i;
     wr_comm(0x30);      // 8BitMCU,基本指令集合
     wr_comm(0x80);      // AC归起始位
     for(i=0;i<64;i++)
       wr_data(0x20);

/*-----------------图形区清RAM函数-----------------*/
void LcdClearBMP(void)
{
     unsigned char i,j;
     wr_comm(0x34);        // 8Bit扩充指令集,即使是36H也要写两次
     wr_comm(0x36);        // 绘图ON,基本指令集里面36H不能开绘图
     for(i=0;i<32;i++)     // 12864实际为256x32
     {
       wr_comm(0x80|i);    // 行位置
       wr_comm(0x80);      // 列位置
       for(j=0;j<32;j++)   // 256/8=32 byte
         wr_data(0);
     }
}



『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
ARM 汇编的必知必会