/*========================================================================= ** 函数名: LCD_draw_pixel ** 函数功能简介: 将一个二维图像矩阵在nokia5110中显示 ** 输入参数: image :要显示图像矩阵的首地址(指针)(可以是数组名); line :图像行数(像素点); row : 图像列数(像素点); threshold: 二值化阀值(如果是二值化以后的图像,阀值为0); X :开始显示的X坐标; Y :开始显示的Y坐标(0-5); ** 返回参数: 无 ** 作 者: 张盛平 ** 编写日期: 2013-6-29 ** 修改历史: 2013-6-29 ** 添加日期: 2013-07-04 ===========================================================================*/ void LCD_draw_pixel(void *image, unsigned char line, unsigned char row, unsigned char threshold,unsigned char X, unsigned char Y) { unsigned char *p_image, i, j, k, temp,n; p_image = image; // if(line > 0) n=line/8; for(i=0;i<n;i++) { LCD_set_XY(0+X,i+Y); for(j=0;j<row;j++) { for(k=0;k<8;k++) { ((*(p_image+(i*8+k)*row+j))>threshold) ? (temp &= ~(1<<k)):(temp |= 1<<k) ; } LCD_write_byte(temp,1); } } if(line%8) { for(j=0;j<row;j++) { for(k=0;k<line%8;k++) { ((*(p_image+(i*8+k)*row+j))>threshold) ? (temp &= ~(1<<k)) : (temp |= 1<<k); } LCD_write_byte(temp,1); } } }
void LCD4884::LCD_clear(void) { unsigned int i; LCD_write_byte(0x0c, 0); LCD_write_byte(0x80, 0); for (i = 0; i < 504; i++) LCD_write_byte(0, 1); }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : LCD_write_char * Returned Value : void * Comments : * This function write a char to LCD * *END*----------------------------------------------------------------------*/ void LCD_write_char(unsigned char c,unsigned char invert) { unsigned char line; c-= 32; for (line=0; line<6; line++){ if(invert == 0) LCD_write_byte(font6x8[c][line], 1); else if(invert == 1) LCD_write_byte(~font6x8[c][line], 1); } }
/*----------------------------------------------------------------------- LCD_clear : LCD清屏函数,并且将XY坐标清零 编写日期 :2004-8-10 最后修改日期 :2004-8-10 -----------------------------------------------------------------------*/ void LCD_clear(void) { unsigned int i; LCD_write_byte(0x0c, 0); LCD_write_byte(0x80, 0); for (i=0; i<504; i++) LCD_write_byte(0, 1); LCD_set_XY(0,0); //将XY坐标清零 }
//--------------------------------------- //名称: 5110LCD初始化函数 //作者:cby //网站:宁波单片机开发网 //网址:www.nbdpj.com //邮箱:[email protected] //日期:20081111 //----------------------------------------- void LCD_init(void) { sce1; res1; delay_ms(10); res0; delay_ms(100); res1; delay_ms(10); LCD_write_byte(0x21,0); LCD_write_byte(0xd0,0); LCD_write_byte(0x20,0); LCD_write_byte(0x0C,0); sce1; }
/* * write char in big font */ void LCD4884::LCD_write_char_big (unsigned char X,unsigned char Y, unsigned char ch, char mode) { unsigned char i, j; unsigned char *pFont; unsigned char ch_dat; pFont = (unsigned char *) big_number; if (ch == '.') ch = 10; else if (ch == '+') ch = 11; else if (ch == '-') ch = 12; else ch = ch & 0x0f; for (i=0; i<3; i++) { LCD_set_XY(X, Y + i); for (j=0; j<16; j++) { ch_dat = pgm_read_byte(pFont+ch*48 + i*16 +j); if (mode != MENU_NORMAL) ch_dat ^= 0xff; LCD_write_byte(ch_dat, 1); } } }
void Move1602(uchar step,uchar dirction,uint time){//屏幕字符移动 uchar i; uint j; for(i=0;i<step;i++){ LCD_write_byte(1,dirction);//字符移动方向 for(j=0;j<time;j++) _delay_ms(1);//控制移动时间 } }
/********************接口函数********************/ void InitScreen1602(){//初始化显示屏 //液晶使用的I/O口初始化 LCD_DATA_PORT = 0X00; LCD_DATA_DDR |= LCD_DATA_BITS; LCD_CONTROL_DDR |= RS|EN; //液晶初始化 _delay_ms(50); LCD_write_byte(1,0x28);//4Bit显示模式设置 _delay_ms(1); LCD_write_byte(1,_CMD_SETSCREEN1_1602);//不显示光标/光标不闪烁/显示关 _delay_ms(1); LCD_write_byte(1,_CMD_CLEARSCREEN_1602);//清屏 _delay_ms(1); LCD_write_byte(1,_CMD_SETMODE3_1602);//设定光标,光标右移AC自加 _delay_ms(1); LCD_write_byte(1,_CMD_SETSCREEN5_1602);//不显示光标/光标不闪烁/显示开 _delay_ms(10); }
/*----------------------------------------------------------------------- LCD_write_char : 显示英文字符 输入参数:c :显示的字符; 编写日期 :2004-8-10 最后修改日期 :2004-8-10 -----------------------------------------------------------------------*/ void LCD_write_char(unsigned char c) { unsigned char line; c -= 32; for (line=0; line<6; line++) LCD_write_byte(font6x8[c][line], 1); }
/*********************************************************** 函数功能:显示英文字符 ***********************************************************/ void LCD_write_char(uint8 c) { uint8 line; uint16 cout ; cout = c ; if((cout < 32)||((cout > 126))) cout = 0; cout -= 32; //数组的行号 cout = cout*5 ; for (line=0; line<5; line++) { LCD_write_byte(font5x8[cout], 1); cout ++ ; } LCD_write_byte(0, 1); }
void LCD_write_line(BYTE nr, unsigned char *line) { BYTE i; LCD_goto_xy(1, nr); for (i = 0; (i < 16) && line[i]; i++) { LCD_write_byte(1, line[i]); } }
void LCD4884::LCD_write_char(byte c, char mode) { byte line; byte ch; c -= 0x20; for (line = 0; line < 6; line++) { //ch = pgm_read_byte(pFont+c*6+line); ch = font6_8[c][line]; LCD_write_byte((mode == LCD_NORMAL) ? ch : (ch ^ 0xff), 1); } }
/*LCD写入一个字符*/ void LCD_write_ch(unsigned char x, unsigned char y, unsigned char ch) { if(!y) //确定行,0为第一行 { LCD_write_cmd(0x80 + x); //重置地址指针 } else { LCD_write_cmd(0xC0 + x); } LCD_write_byte(ch); //写入一个字符 }
void LCD_draw_whole(unsigned char * map) { int i; LCD_clear(); for(i=0;i<504;i++) { LCD_write_byte(*map++,1); } }
void LCD4884::LCD_init(void) { CTick to; for (int i = 0; i < 6; i++) { lcd[i].output(NOT_OPEN); // set lcd I/F as output pins if ( i==SPI_SCK ) { lcd[i] = HIGH; } else { lcd[i] = LOW; } } lcd[LCD_RST] = LOW; to.delay(2); lcd[LCD_RST] = HIGH; lcd[SPI_CS] = LOW; to.delay(2); lcd[SPI_CS] = HIGH; to.delay(2); lcd[LCD_BL] = HIGH; LCD_write_byte(0x21, 0); LCD_write_byte(0xc0, 0); LCD_write_byte(0x06, 0); LCD_write_byte(0x13, 0); LCD_write_byte(0x20, 0); LCD_clear(); LCD_write_byte(0x0c, 0); // lcd[SPI_CS] = HIGH; }
void LCD4884::LCD_init(void) { // LCD_RST = 0; DDRD |= (1 << SPI_CS) | (1 << LCD_DC) | (1 << LCD_RST) | (1 << SPI_MOSI) | (1 << SPI_SCK) | (1 << LCD_BL); PORTD &= ~(1 << LCD_RST); delayMicroseconds(1); PORTD |= (1 << LCD_RST); PORTD &= ~(1 << SPI_CS); delayMicroseconds(1); PORTD |= (1 << SPI_CS); delayMicroseconds(1); PORTD |= (1 << LCD_BL); // turn on backlight LCD_write_byte(0x21, 0); LCD_write_byte(0xc0, 0); LCD_write_byte(0x06, 0); LCD_write_byte(0x13, 0); LCD_write_byte(0x20, 0); LCD_clear(); LCD_write_byte(0x0c, 0); PORTD &= ~(1<<SPI_CS); }
void LCD4884::LCD_init(void) { for(int i = 2; i < 8; i++) { pinMode(i,OUTPUT); digitalWrite(i,LOW); } digitalWrite(LCD_RST,LOW); delayMicroseconds(1); digitalWrite(LCD_RST,HIGH); digitalWrite(SPI_CS,LOW); delayMicroseconds(1); digitalWrite(SPI_CS,HIGH); delayMicroseconds(1); digitalWrite(LCD_BL,HIGH); LCD_write_byte(0x21, 0); LCD_write_byte(0xc0, 0); LCD_write_byte(0x06, 0); LCD_write_byte(0x13, 0); LCD_write_byte(0x20, 0); LCD_clear(); LCD_write_byte(0x0c, 0); digitalWrite(SPI_CS,LOW); }
void LCD_init(void) { // 产生一个让LCD复位的低电平脉冲 LCD_pin_config(); LCD_RST = 0; // delay_1us(); LCD_RST = 1; // 关闭LCD LCD_CE = 0; // delay_1us(); // 使能LCD LCD_CE = 1; delay_1us(); LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式 LCD_write_byte(0xc0, 0); // 设置偏置电压 供电电压高时该值调小 LCD_write_byte(0x07, 0); // 温度校正 LCD_write_byte(0x13, 0); // 1:48 LCD_write_byte(0x20, 0); // 使用基本命令 LCD_clear(); // 清屏 LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示 // 关闭LCD LCD_CE = 0; }
void LCD_init(void) { LCDGPIO_init();//所需io初始化 LCD_RST_L; // 产生一个让LCD复位的低电平脉冲 delay_1us(); // DELAY_MS(1) ; LCD_RST_H; LCD_CE_L; // 关闭LCD delay_1us(); // DELAY_MS(1) ; LCD_CE_H; // 使能LCD delay_1us(); // DELAY_MS(1) ; LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式 LCD_write_byte(0xc8, 0); // 设置液晶偏置电压 LCD_write_byte(0x06, 0); // 温度校正 LCD_write_byte(0x13, 0); // 1:48 LCD_write_byte(0x20, 0); // 使用基本命令,V=0,水平寻址 LCD_clear(); // 清屏 LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示 LCD_CE_L; // 关闭LCD }
void LCD_init(void) { GPIO_WriteBit(GPIOC,GPIO_Pin_7,Bit_SET);//LCD_RST = 0; // 产生一个让LCD复位的低电平脉冲 GPIO_WriteBit(GPIO_LCD_RST_PORT,GPIO_LCD_RST,Bit_RESET);//LCD_RST = 0; delay_1us(); GPIO_WriteBit(GPIO_LCD_RST_PORT,GPIO_LCD_RST,Bit_SET);//LCD_RST = 1; // 关闭LCD GPIO_WriteBit(GPIO_LCD_CE_PORT,GPIO_LCD_CE,Bit_RESET);//LCD_CE = 0; delay_1us(); // 使能LCD GPIO_WriteBit(GPIO_LCD_CE_PORT,GPIO_LCD_CE,Bit_SET);//LCD_CE = 1; delay_1us(); LCD_write_byte(0x21, 0); // 使用扩展命令设置LCD模式 LCD_write_byte(0xc8, 0); // 设置偏置电压 LCD_write_byte(0x06, 0); // 温度校正 LCD_write_byte(0x13, 0); // 1:48 LCD_write_byte(0x20, 0); // 使用基本命令 LCD_clear(); // 清屏 LCD_write_byte(0x0c, 0); // 设定显示模式,正常显示 // 关闭LCD GPIO_WriteBit(GPIO_LCD_CE_PORT,GPIO_LCD_CE,Bit_RESET);//LCD_CE = 0; }
void LCD4884::LCD_write_char(unsigned char c, char mode) { unsigned char line; unsigned char *pFont; byte ch; pFont = (unsigned char *)font6_8; c -= 32; for (line=0; line<6; line++){ ch = pgm_read_byte(pFont+c*6+line); LCD_write_byte( (mode==MENU_NORMAL)? ch: (ch^ 0xff) , 1); } }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : LCD_clear * Returned Value : void * Comments : * This function clear LCD * *END*----------------------------------------------------------------------*/ void LCD_clear(void) { unsigned char t; unsigned char k; LCD_set_XY(0,0); for(t=0;t<6;t++) { for(k=0;k<84;k++) { LCD_write_byte(0x0,1); } } sce1; }
void LCD_cursor(unsigned char row) { unsigned char t; unsigned char k; LCD_set_XY(0,0); for(t=0;t< row;t++) { for(k=0;k<84;k++) { LCD_write_byte(0xff,1); } } sce1; }
/*==============图像显示函数(智能车不常用,数组的一字节写nokia5110的8个点)======== LCD_draw_picture : 将一个二维图像矩阵在nokia5110中显示 输入参数:start_x :显示图像的开始的行号; start_y :显示图像的开始的列号; map : 图像数组; line : 行数; row :列数(0-5); 编写日期 :2013-6-29 最后修改日期 :2013-6-29 加入日期 :2013-07-04 ================================================================================*/ void LCD_draw_picture(unsigned char start_x, unsigned char start_y, unsigned char *map, unsigned char line, unsigned row) { unsigned char *p; unsigned i,j; p= map; for(i=0;i<line;i++) { LCD_set_XY(start_x,start_y+i); for(j=0;j<row;j++) { LCD_write_byte(*p++,1); } } }
/*LCD写入一个字符串*/ void LCD_write_string(unsigned char x, unsigned char y, unsigned char *string) { if(!y) { LCD_write_cmd(0x80 + x); } else { LCD_write_cmd(0xC0 + x); } while(*string) { LCD_write_byte(*string); string++; } }
void LCD4884::LCD_draw_bmp_pixel(byte X, byte Y, const byte *map, byte Pix_x, byte Pix_y) { unsigned int i, n; byte row; if (Pix_y % 8 == 0) row = Pix_y / 8; else row = Pix_y / 8 + 1; for (n = 0; n < row; n++) { LCD_set_XY(X, Y); for (i = 0; i < Pix_x; i++) { LCD_write_byte(map[i + n * Pix_x], 1); } Y++; } }
void LCD4884::LCD_draw_bmp_pixel(unsigned char X,unsigned char Y,unsigned char *map, unsigned char Pix_x,unsigned char Pix_y) { unsigned int i,n; unsigned char row; if (Pix_y %8 == 0) row = Pix_y / 8; else row = Pix_y / 8 + 1; for (n=0; n<row; n++) { LCD_set_XY(X, Y); for (i=0; i<Pix_x; i++) { LCD_write_byte(map[i + n*Pix_x], 1); } Y++; } }
void LCD4884::LCD_write_chinese(byte X, byte Y, const byte *c, byte ch_with, byte num, byte line, byte row) { byte i, n; LCD_set_XY(X, Y); for (i = 0; i < num;) { for (n = 0; n < ch_with * 2; n++) { if (n == ch_with) { if (i == 0) LCD_set_XY(X, Y + 1); else { LCD_set_XY((X + (ch_with + row) * i), Y + 1); } } LCD_write_byte(c[(i * ch_with * 2) + n], 1); } i++; LCD_set_XY((X + (ch_with + row) * i), Y); } }
void LCD4884::LCD_write_chinese(unsigned char X, unsigned char Y,unsigned char *c,unsigned char ch_with,unsigned char num,unsigned char line,unsigned char row) { unsigned char i,n; LCD_set_XY(X,Y); for (i=0;i<num;) { for (n=0; n<ch_with*2; n++) { if (n==ch_with) { if (i==0) LCD_set_XY(X,Y+1); else { LCD_set_XY((X+(ch_with+row)*i),Y+1); } } LCD_write_byte(c[(i*ch_with*2) + n], 1); } i++; LCD_set_XY((X+(ch_with+row)*i),Y); } }
/*----------------------------------------------------------------------- LCD_write_chinese_string: 在LCD上显示汉字 输入参数:X、Y :显示汉字的起始X、Y坐标; ch_with :汉字点阵的宽度 num :显示汉字的个数; line :汉字点阵数组中的起始行数 row :汉字显示的行间距 编写日期 :2004-8-11 最后修改日期 :2004-8-12 测试: LCD_write_chi(0,0,12,7,0,0); LCD_write_chi(0,2,12,7,0,0); LCD_write_chi(0,4,12,7,0,0); -----------------------------------------------------------------------*/ void LCD_write_chinese_string(unsigned char X, unsigned char Y, unsigned char ch_with,unsigned char num, unsigned char line,unsigned char row) { unsigned char i,n; LCD_set_XY(X,Y); //设置初始位置 for (i=0;i<num;) { for (n=0; n<ch_with*2; n++) //写一个汉字 { if (n==ch_with) //写汉字的下半部分 { if (i==0) LCD_set_XY(X,Y+1); else LCD_set_XY((X+(ch_with+row)*i),Y+1); } LCD_write_byte(write_chinese[line+i][n],1); } i++; LCD_set_XY((X+(ch_with+row)*i),Y); } }