This repository has been archived on 2024-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
justhomework/MCU/MCU_7 _LCD12864/display.c

175 lines
2.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <reg52.h>
#include "display.h"
#include "delay.h"
// DB P1
// CTL P3
sbit RS = P3 ^ 0;
sbit RW = P3 ^ 1;
sbit E = P3 ^ 2;
sbit CSA = P3 ^ 4;
sbit CSB = P3 ^ 5;
const unsigned char Z[] =
{
/*-- 文字: 江 --*/
/*-- 宋体12; 此字体下对应的点阵为宽x高=16x16 --*/
0x10, 0x60, 0x02, 0x0C, 0xC0, 0x04, 0x04, 0x04, 0x04, 0xFC, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00,
/*-- 文字: 一 --*/
/*-- 宋体12; 此字体下对应的点阵为宽x高=16x16 --*/
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00,
/*-- 文字: 和 --*/
/*-- 宋体12; 此字体下对应的点阵为宽x高=16x16 --*/
0x20, 0x24, 0x24, 0xA4, 0xFE, 0x23, 0x22, 0x20, 0x00, 0xF8, 0x08, 0x08, 0x08, 0xF8, 0x00, 0x00,
};
const unsigned char Z2[] =
{
0x04, 0x04, 0x7C, 0x03, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3F, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x10, 0x08, 0x06, 0x01, 0xFF, 0x01, 0x06, 0x00, 0x00, 0x3F, 0x10, 0x10, 0x10, 0x3F, 0x00, 0x00
};
void selA()
{
CSA = 1;
CSB = 0;
}
void selB()
{
CSA = 0;
CSB = 1;
}
void writeData(unsigned char d)
{
RS = 1;
RW = 0;
P1 = d;
E = 0;
E = 1;
delay(3);
E = 0;
}
void writeCommand(unsigned char d)
{
RS = 0;
RW = 0;
P1 = d;
E = 0;
E = 1;
delay(3);
E = 0;
}
void lcdInit()
{
selA();
writeCommand(0x3f);
selB();
writeCommand(0x3f);
selA();
}
void setPage(unsigned char p)
{
writeCommand(0xb8 + p);
}
void setLine(unsigned char p)
{
writeCommand(0xc0 + p);
}
void setY(unsigned char p)
{
writeCommand(0x40 + p);
}
void name(unsigned int i)
{
unsigned int line = 0;
while(line < 48)
{
setPage(0);
setY(i);
writeData(Z[line]);
setPage(1);
setY(i);
writeData(Z2[line++]);
}
}
void write()
{
RW = 0;
E = 0;
E = 1;
delay(2);
E = 0;
}
void clear()
{
unsigned int i, j;
CSA = 1;
CSB = 0;
for(i = 0; i < 8; i++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + i;
write();
P1 = 0X40;
write();
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = 0x00;;
write();
}
}
CSA = 0;
CSB = 1;
for(i = 0; i < 8; i++)
{
RS = 0;
RW = 0;
P1 = 0xb8 + i;
write();
P1 = 0X40;
write();
for(j = 0; j < 64; j++)
{
RS = 1;
RW = 0;
P1 = 0x00;;
write();
}
}
}
void init()
{
E = 0;
RS = 1;
CSA = 1;
CSB = 0;
RS = 0;
P1 = 0X3F;
write();
CSA = 0;
CSB = 1;
RS = 0;
P1 = 0XFF;
write();
}