这个屏幕资料不是很多,这是自己写的,给各位新手参考,
单片机源程序如下:
- #include "st7565p.h"
- //#include "charcode.h"
- // 类似8080接口
- extern struct CharCodeTypedef{
- unsigned char CharWord;
- unsigned char Ecode[16];
- };
- extern struct CNCodeTypedef
- {
- unsigned char HZ[2];
- unsigned char HZcode[32];
- };
- extern struct CharCodeTypedef code letter[74];
- extern struct CNCodeTypedef code hanzi[3];
- void Init_st7565p(void)
- {
- unsigned int i;
- LCD_PZ12864_CS = 0;
- LCD_PZ12864_RSET = 0;
- for (i=0; i<2000; i++);
- LCD_PZ12864_RSET = 1;
-
- WriteCmd_st7565(0xe2); // (14) Internal reset
- for (i=0; i<100; i++); //延时一下
-
- WriteCmd_st7565(0xa0); // (8) ADC select : normal , 0xa0: normal, 0xa1: reverse
-
- WriteCmd_st7565(0xc8); // (15) Common output mode select : normal, 0xc8:reverse direction, 0xc7: normal direction
-
- WriteCmd_st7565(0xa6); // (9) Display normal, 0xa6: normal, 0xa7: reverse
-
- WriteCmd_st7565(0xa4); // (10) 0xa5: all points on, 0xa4: all points off
-
- WriteCmd_st7565(0xa2); // (11) bias set : 1/7 , 0xa2:1/9, 0xa3:1/7 区别不大。。
-
- WriteCmd_st7565(0xf8); // (20)
- WriteCmd_st7565(0x01);
-
- WriteCmd_st7565(0x81); // (18)
- WriteCmd_st7565(0x23);
-
- WriteCmd_st7565(0x25); // (17) Select internal resistor ratio(Rb/Ra) mode
-
- WriteCmd_st7565(0x2f); // (16) Select internal power supply operating mode
- for (i=0; i<100; i++);
-
- WriteCmd_st7565(0x40); // (2) Set the display RAM display start line address 0x40 + (0-63)
-
- WriteCmd_st7565(0xaf); // (1) display on/off , 0xaf: on, 0xae: off
- for (i=0; i<100; i++);
- }
- void ClearScreen(void)
- {
- unsigned char i,j;
- for(i = 0; i < 8; i++)
- {
- WriteCmd_st7565(0xb0 + i); //y
-
- WriteCmd_st7565(0x10);
- WriteCmd_st7565(0x00);
- for(j = 0; j < 128; j++)
- {
- WriteData_st7565(0x00);
- }
- }
- }
- void WriteCmd_st7565(unsigned char cmd)
- {
- LCD_PZ12864_CS = 0;
- LCD_PZ12864_WR = 0;
- LCD_PZ12864_RD = 1; //disable read
- LCD_PZ12864_RS = 0; // command
- _nop_();
- _nop_();
- DATA_PORT = cmd;
- _nop_();
- _nop_();
- LCD_PZ12864_WR = 1;
- }
- void WriteData_st7565(unsigned char dat)
- {
- LCD_PZ12864_CS = 0;
- LCD_PZ12864_WR = 0;
- LCD_PZ12864_RD = 1; //disable read
- LCD_PZ12864_RS = 1; // data
- _nop_();
- _nop_();
- DATA_PORT = dat;
- _nop_();
- _nop_();
- LCD_PZ12864_WR = 1;
- }
- void XY_WriteCmd(unsigned char x, unsigned char y)
- {
- unsigned char xl,xh;
- xh = (x >> 4) & 0x0f;
- xl = x & 0x0f;
- // 八页0-7,一页四位
- WriteCmd_st7565(0xb0 + y); //y
- // 横坐标127个 0-127,比如第5个 5 - 1 =0x04 ,则高四位为0,第四位为4,即0x10+0,0x00+4
- WriteCmd_st7565(0x10 + xh); //x
- WriteCmd_st7565(0x00 + xl); //x
- }
- void XY_Write816Data(unsigned char x,unsigned char y, unsigned char *CH)
- {
- unsigned char i;
- XY_WriteCmd(x,y);
- for(i = 0; i < 16; i ++)
- {
- if(i == 8)
- XY_WriteCmd(x,y+1);
-
- WriteData_st7565(*(CH+i));
- }
- }
- void XY_Write1616Data(unsigned char x,unsigned char y, unsigned char *CH)
- {
- unsigned char i;
- XY_WriteCmd(x,y);
- for(i = 0; i < 32; i ++)
- {
- if(i == 16)
- XY_WriteCmd(x,y+1);
-
- WriteData_st7565(*(CH+i));
- }
- }
- void XY_WriteString(unsigned char x, unsigned char y, unsigned char *str)
- {
- unsigned char i;
- while(*str != '\0')
- {
- for(i = 0; i < 74; i ++) //字库字符数量
- {
- if(*str == letter[i].CharWord)
- {
- XY_Write816Data(x, y, letter[i].Ecode);
- x += 8;
- }
- }
- str += 1;
- }
- }
- void XY_WriteCN(unsigned char x, unsigned char y, unsigned char *str)
- {
- unsigned char i;
- while(*str != '\0')
- {
- for(i = 0; i < 3; i ++)//字库汉字数量
- {
- if((*str == hanzi[i].HZ[0]) && (*(str + 1) == hanzi[i].HZ[1]))
- {
- XY_Write1616Data(x, y, hanzi[i].HZcode);
- x += 16;
- }
- }
- str += 2;
- }
- }
复制代码
所有资料51hei提供下载:
普中12864带背景点阵屏.rar
(2.75 MB, 下载次数: 41)
|