📄 12864.c
字号:
//ICC-AVR application builder : 2005-7-21 15:31:35
// Target : M32
// Crystal: internal RC:1.0000Mhz
//description:液晶横放显示汉字
#include <iom32v.h>
#include <macros.h>
/* lcd port define: connect to PORTB of MEGA32L */
#define RS 0
#define RW 1
#define E 2
#define CSA 3
#define CSB 4
#define RST 5
/******************************************************************** */
#define SETBIT(x,y) (x|=(1<<y)) //set bit y in byte x
#define CLRBIT(x,y) (x&=(~(1<<y))) //clear bit y in byte x
#define CHKBIT(x,y) (x&(1<<y)) //check bit y in byte x
/******************************************************************** */
void port_init(void)
{
PORTA = 0xFF;
DDRA = 0xFF;
PORTB = 0xFF;
DDRB = 0xFF;
PORTC = 0xFF;
DDRC = 0xFF;
PORTD = 0xFF;
DDRD = 0xFF;
}
//call this routine to initialise all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
port_init();
MCUCR = 0x00;
GICR = 0x00;
TIMSK = 0x00; //timer interrupt sources
SEI(); //re-enable interrupts
//all peripherals are now initialised
}
/*-----------------------------------------------------
状态检查函数,判断是否处于忙状态
-------------------------------------------------------*/
void CheckState()
{
unsigned char dat;
CLRBIT(PORTB,RS); //RS=0
SETBIT(PORTB,RW); //RW=1
DDRA=0x00; // portA as input
do
{
SETBIT(PORTB,E);
CLRBIT(PORTB,E);
}
while (PINA&0x80);
}
/*----------------------------------------------
写显示数据
形参dat:显示数据
-------------------------------------------------*/
void WriteByte(unsigned char dat)
{
CheckState();
SETBIT(PORTB,RS);
CLRBIT(PORTB,RW);
DDRA=0xff; //portA as output
PORTA=dat;
SETBIT(PORTB,E);
CLRBIT(PORTB,E);
}
/*-------------------------------------------------
向LCD发送命令
形参command :命令
--------------------------------------------------*/
void SendCommandToLCD(unsigned char command)
{
CheckState();
PORTB&=0xfc; //RS=0,RW=0
DDRA=0xff; //portA as output
PORTA=command;
SETBIT(PORTB,E);
CLRBIT(PORTB,E);
}
/*-------------------------------------------------*/
//设定行地址(页)--X 0-7
void SetLine(unsigned char line)
{
line=line & 0x07; // 0<=line<=7
line=line|0xb8; //1011 1xxx
SendCommandToLCD(line);
}
//设定列地址--Y 0-63
void SetColumn(unsigned char column)
{
column=column &0x3f; // 0=<column<=63
column=column | 0x40; //01xx xxxx
SendCommandToLCD(column);
}
//设定显示开始行--XX
void SetStartLine(unsigned char startline) //0--63
{
startline=startline & 0x07; //??0x3f
startline=startline|0xc0; //1100 0000
SendCommandToLCD(startline);
}
//开关显示
void SetOnOff(unsigned char onoff)
{
onoff=0x3e | onoff; //0011 111x
SendCommandToLCD(onoff);
}
/*------------------清除内存---------------*/
void Clr_Scr()
{
unsigned char j,k;
PORTB|=0x18; //CSA=1,CSB=1
SetLine(0);
SetColumn(0);
for(k=0;k<8;k++)
{
SetLine(k); //第K页
for(j=0;j<64;j++)
WriteByte(0x00);
}
}
/*------------------初始化LCD屏--------------------------*/
void init_lcd()
{
CLRBIT(PORTB,RST);
SETBIT(PORTB,RST);
PORTB|=0x18; //CSA=1,CSB=1
SetOnOff(0x3e); //关显示
SetLine(0x00); // 设定页
SetStartLine(0x00);
SetColumn(0x00);
SetOnOff(0x3f); //开显示
}
/*----------------------------------------------------------------------
说明:12864液晶横放,汉字按正常方式显示,pag:0~7(从上到下);
row:0~7(从左到右,水平行,一行可显示8个汉字)
功能:指定位置显示汉字16*16
------------------------------------------------------------------------*/
void word_disp(unsigned char pag,unsigned char row, unsigned flash char *hzk)
{
unsigned char j=0,i=0,k=0;
for(j=0;j<2;j++)
{
if (row <4)
{
k=row;
SETBIT(PORTB,CSA); //CSA=1,CSB=0,select leftwindow
CLRBIT(PORTB,CSB);
}
else
{
k = row-4;
CLRBIT(PORTB,CSA); //CSA=0,CSB=1,select rightwindow
SETBIT(PORTB,CSB);
}
SetLine(pag+j);
SetColumn(k*16);
for(i=0;i<16;i++)
{
WriteByte(hzk[16*j+i]);
}
}
}
/*----------------------------------------------------------------------
说明:12864液晶横放,字符按正常方式显示,pag:0~7(从上到下);
row:0~15(从左到右,水平行,一行可显示16个字符)
功能:指定位置显示字符8*16
------------------------------------------------------------------------*/
void byte_disp(unsigned char pag, unsigned char row, unsigned flash char *bytek)
{
unsigned char j=0,i=0,k=0;
for(j=0;j<2;j++)
{
if (row < 8)
{
k=row;
SETBIT(PORTB,CSA); //CSA=1,CSB=0,select leftwindow
CLRBIT(PORTB,CSB);
}
else
{
k=row-8;
CLRBIT(PORTB,CSA); //CSA=0,CSB=1,select rightwindow
SETBIT(PORTB,CSB);
}
SetLine(pag+j);
SetColumn(k*8);
for(i=0;i<8;i++)
{
WriteByte(bytek[8*j+i]);
}
}
}
flash char huan[]={//欢[16*16]下半列排
0x04,0x34,0xC4,0x04,0xC4,0x3C,0x20,0x10,
0x0F,0xE8,0x08,0x08,0x28,0x18,0x00,0x00,
0x10,0x08,0x06,0x01,0x82,0x8C,0x40,0x30,
0x0C,0x03,0x0C,0x10,0x60,0xC0,0x40,0x00};
flash char ying[]={//迎[16*16]下半列排
0x40,0x42,0x44,0xC8,0x00,0xFC,0x04,0x02,
0x82,0xFC,0x04,0x04,0x04,0xFE,0x04,0x00,
0x00,0x40,0x20,0x1F,0x20,0x47,0x42,0x41,
0x40,0x7F,0x40,0x42,0x44,0x63,0x20,0x00};
flash char guang[]={//光[16*16]下半列排
0x40,0x40,0x42,0x44,0x58,0xC0,0x40,0x7F,
0x40,0xC0,0x50,0x48,0x46,0x64,0x40,0x00,
0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,
0x00,0x3F,0x40,0x40,0x40,0x40,0x70,0x00};
flash char lin[]={//临[16*16]下半列排
0x00,0xFC,0x00,0xFF,0x40,0x20,0x10,0x0C,
0x2B,0x48,0xC8,0x08,0x08,0x8C,0x08,0x00,
0x00,0x1F,0x00,0xFF,0x00,0xFF,0x41,0x41,
0x41,0x7F,0x41,0x41,0x41,0xFF,0x01,0x00};
flash char tanhao[]={0x00,0x00,0x00,0xf8,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x33,0x30,0x00,0x00,0x00};
char jinghao[]={0x40,0xc0,0x78,0x40,0xc0,0x78,0x40,0x00,
0x04,0x3f,0x04,0x04,0x3f,0x04,0x04,0x00};
flash char w2[]={0xf8,0x08,0x00,0xf8,0x00,0x08,0xf8,0x00,
0x03,0x3c,0x07,0x00,0x07,0x3c,0x03,0x00};
flash char w[]={0x80,0x80,0x00,0x80,0x00,0x80,0x80,0x80,
0x0f,0x30,0x0c,0x03,0x0c,0x30,0x0f,0x00};
flash char o2[]={0xe0,0x10,0x08,0x08,0x08,0x10,0xe0,0x00,
0x0f,0x10,0x20,0x20,0x20,0x10,0x0f,0x00};
flash char u[]={0x80,0x80,0x00,0x00,0x00,0x80,0x80,0x00,
0x00,0x1f,0x20,0x20,0x20,0x10,0x3f,0x20};
flash char r[]={0x80,0x80,0x80,0x00,0x80,0x80,0x80,0x00,
0x20,0x20,0x3f,0x21,0x20,0x00,0x01,0x00};
flash char o[]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
0x00,0x1f,0x20,0x20,0x20,0x20,0x1f,0x00};
flash char e2[]={0x08,0xf8,0x88,0x88,0xe8,0x08,0x10,0x00,
0x20,0x3f,0x20,0x20,0x23,0x20,0x18,0x00};
flash char a2[]={0x00,0x00,0xc0,0x38,0xe0,0x00,0x00,0x00,
0x20,0x3c,0x23,0x02,0x02,0x27,0x38,0x20};
flash char v[]={0x80,0x80,0x80,0x00,0x00,0x80,0x80,0x80,
0x00,0x01,0x0e,0x30,0x08,0x06,0x01,0x00};
flash char dot[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x00};
flash char a[]={0x00,0x00,0x80,0x80,0x80,0x80,0x00,0x00,
0x00,0x19,0x24,0x22,0x22,0x22,0x3f,0x20};
flash char c[]={0x00,0x00,0x00,0x80,0x80,0x80,0x00,0x00,
0x00,0x0e,0x11,0x20,0x20,0x20,0x11,0x00};
flash char m[]={0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,
0x20,0x3f,0x20,0x00,0x3f,0x20,0x00,0x3f};
void main_window (void)
{ //分三行显示:欢迎光临 OurAvr www.ouravr.com
word_disp(1,2,huan);
word_disp(1,3,ying);
word_disp(1,4,guang);
word_disp(1,5,lin);
byte_disp(3,5,o2);
byte_disp(3,6,u);
byte_disp(3,7,r);
byte_disp(3,8,a2);
byte_disp(3,9,v);
byte_disp(3,10,r);
byte_disp(5,1,w);
byte_disp(5,2,w);
byte_disp(5,3,w);
byte_disp(5,4,dot);
byte_disp(5,5,o);
byte_disp(5,6,u);
byte_disp(5,7,r);
byte_disp(5,8,a);
byte_disp(5,9,v);
byte_disp(5,10,r);
byte_disp(5,11,dot);
byte_disp(5,12,c);
byte_disp(5,13,o);
byte_disp(5,14,m);
}
void main(void)
{
init_devices();
init_lcd();
Clr_Scr();
main_window();
//insert your functional code here...
while (1)
{
;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -