/***************************************************************** * 函数库说明:ATMEGA8 NOKIA 5110LCD 驱动 * 版本: v1.0 * 修改: 庞辉 芜湖联大飞思卡尔工作室 * 修改日期: 2011年08月03日 * * 说明: 无 * * 版本更新: * ****************************************************************** *注意:
*******************************************************************/ #include "includes.h" int main(void) { LCD_INIT(); LCD_Write_Chinese_String(10,0,12,4,Chinese_Font,0,5); LCD_Write_Chinese_String(10,2,12,4,Chinese_Font,4,5); LCD_Write_Chinese_String(15,4,12,3,Chinese_Font,8,5); while(1); return 0; }
//5110.c
#include "includes.h" uint8 ASSIC_Font[][6] = { { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // sp { 0x00, 0x00, 0x00, 0x2f, 0x00, 0x00 }, // ! { 0x00, 0x00, 0x07, 0x00, 0x07, 0x00 }, // " { 0x00, 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // # { 0x00, 0x24, 0x2a, 0x7f, 0x2a, 0x12 }, // $ { 0x00, 0x62, 0x64, 0x08, 0x13, 0x23 }, // % { 0x00, 0x36, 0x49, 0x55, 0x22, 0x50 }, // & { 0x00, 0x00, 0x05, 0x03, 0x00, 0x00 }, // ' { 0x00, 0x00, 0x1c, 0x22, 0x41, 0x00 }, // ( { 0x00, 0x00, 0x41, 0x22, 0x1c, 0x00 }, // ) { 0x00, 0x14, 0x08, 0x3E, 0x08, 0x14 }, // * { 0x00, 0x08, 0x08, 0x3E, 0x08, 0x08 }, // + { 0x00, 0x00, 0x00, 0xA0, 0x60, 0x00 }, // , { 0x00, 0x08, 0x08, 0x08, 0x08, 0x08 }, // - { 0x00, 0x00, 0x60, 0x60, 0x00, 0x00 }, // . { 0x00, 0x20, 0x10, 0x08, 0x04, 0x02 }, // / { 0x00, 0x3E, 0x51, 0x49, 0x45, 0x3E }, // 0 { 0x00, 0x00, 0x42, 0x7F, 0x40, 0x00 }, // 1 { 0x00, 0x42, 0x61, 0x51, 0x49, 0x46 }, // 2 { 0x00, 0x21, 0x41, 0x45, 0x4B, 0x31 }, // 3 { 0x00, 0x18, 0x14, 0x12, 0x7F, 0x10 }, // 4 { 0x00, 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5 { 0x00, 0x3C, 0x4A, 0x49, 0x49, 0x30 }, // 6 { 0x00, 0x01, 0x71, 0x09, 0x05, 0x03 }, // 7 { 0x00, 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8 { 0x00, 0x06, 0x49, 0x49, 0x29, 0x1E }, // 9 { 0x00, 0x00, 0x36, 0x36, 0x00, 0x00 }, // : { 0x00, 0x00, 0x56, 0x36, 0x00, 0x00 }, // ; { 0x00, 0x08, 0x14, 0x22, 0x41, 0x00 }, // < { 0x00, 0x14, 0x14, 0x14, 0x14, 0x14 }, // = { 0x00, 0x00, 0x41, 0x22, 0x14, 0x08 }, // > { 0x00, 0x02, 0x01, 0x51, 0x09, 0x06 }, // ? { 0x00, 0x32, 0x49, 0x59, 0x51, 0x3E }, // @ { 0x00, 0x7C, 0x12, 0x11, 0x12, 0x7C }, // A { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x36 }, // B { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x22 }, // C { 0x00, 0x7F, 0x41, 0x41, 0x22, 0x1C }, // D { 0x00, 0x7F, 0x49, 0x49, 0x49, 0x41 }, // E { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x01 }, // F { 0x00, 0x3E, 0x41, 0x49, 0x49, 0x7A }, // G { 0x00, 0x7F, 0x08, 0x08, 0x08, 0x7F }, // H { 0x00, 0x00, 0x41, 0x7F, 0x41, 0x00 }, // I { 0x00, 0x20, 0x40, 0x41, 0x3F, 0x01 }, // J { 0x00, 0x7F, 0x08, 0x14, 0x22, 0x41 }, // K { 0x00, 0x7F, 0x40, 0x40, 0x40, 0x40 }, // L { 0x00, 0x7F, 0x02, 0x0C, 0x02, 0x7F }, // M { 0x00, 0x7F, 0x04, 0x08, 0x10, 0x7F }, // N { 0x00, 0x3E, 0x41, 0x41, 0x41, 0x3E }, // O { 0x00, 0x7F, 0x09, 0x09, 0x09, 0x06 }, // P { 0x00, 0x3E, 0x41, 0x51, 0x21, 0x5E }, // Q { 0x00, 0x7F, 0x09, 0x19, 0x29, 0x46 }, // R { 0x00, 0x46, 0x49, 0x49, 0x49, 0x31 }, // S { 0x00, 0x01, 0x01, 0x7F, 0x01, 0x01 }, // T { 0x00, 0x3F, 0x40, 0x40, 0x40, 0x3F }, // U { 0x00, 0x1F, 0x20, 0x40, 0x20, 0x1F }, // V { 0x00, 0x3F, 0x40, 0x38, 0x40, 0x3F }, // W { 0x00, 0x63, 0x14, 0x08, 0x14, 0x63 }, // X { 0x00, 0x07, 0x08, 0x70, 0x08, 0x07 }, // Y { 0x00, 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z { 0x00, 0x00, 0x7F, 0x41, 0x41, 0x00 }, // [ { 0x00, 0x55, 0x2A, 0x55, 0x2A, 0x55 }, // 55 { 0x00, 0x00, 0x41, 0x41, 0x7F, 0x00 }, // ] { 0x00, 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^ { 0x00, 0x40, 0x40, 0x40, 0x40, 0x40 }, // _ { 0x00, 0x00, 0x01, 0x02, 0x04, 0x00 }, // ' { 0x00, 0x20, 0x54, 0x54, 0x54, 0x78 }, // a { 0x00, 0x7F, 0x48, 0x44, 0x44, 0x38 }, // b { 0x00, 0x38, 0x44, 0x44, 0x44, 0x20 }, // c { 0x00, 0x38, 0x44, 0x44, 0x48, 0x7F }, // d { 0x00, 0x38, 0x54, 0x54, 0x54, 0x18 }, // e { 0x00, 0x08, 0x7E, 0x09, 0x01, 0x02 }, // f { 0x00, 0x18, 0xA4, 0xA4, 0xA4, 0x7C }, // g { 0x00, 0x7F, 0x08, 0x04, 0x04, 0x78 }, // h { 0x00, 0x00, 0x44, 0x7D, 0x40, 0x00 }, // i { 0x00, 0x40, 0x80, 0x84, 0x7D, 0x00 }, // j { 0x00, 0x7F, 0x10, 0x28, 0x44, 0x00 }, // k { 0x00, 0x00, 0x41, 0x7F, 0x40, 0x00 }, // l { 0x00, 0x7C, 0x04, 0x18, 0x04, 0x78 }, // m { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x78 }, // n { 0x00, 0x38, 0x44, 0x44, 0x44, 0x38 }, // o { 0x00, 0xFC, 0x24, 0x24, 0x24, 0x18 }, // p { 0x00, 0x18, 0x24, 0x24, 0x18, 0xFC }, // q { 0x00, 0x7C, 0x08, 0x04, 0x04, 0x08 }, // r { 0x00, 0x48, 0x54, 0x54, 0x54, 0x20 }, // s { 0x00, 0x04, 0x3F, 0x44, 0x40, 0x20 }, // t { 0x00, 0x3C, 0x40, 0x40, 0x20, 0x7C }, // u { 0x00, 0x1C, 0x20, 0x40, 0x20, 0x1C }, // v { 0x00, 0x3C, 0x40, 0x30, 0x40, 0x3C }, // w { 0x00, 0x44, 0x28, 0x10, 0x28, 0x44 }, // x { 0x00, 0x1C, 0xA0, 0xA0, 0xA0, 0x7C }, // y { 0x00, 0x44, 0x64, 0x54, 0x4C, 0x44 }, // z { 0x14, 0x14, 0x14, 0x14, 0x14, 0x14 } // horiz lines }; uint8 Chinese_Font[][25] = { /*-- 文字: 芜 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x00,0x48,0x48,0xDE,0xFE,0xF4,0xFE,0x76,0x24,0x04,0x04,0x00,0x00,0x02,0x03,0x03, 0x01,0x03,0x03,0x02,0x02,0x02,0x03,0x00 }, /*-- 文字: 湖 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x10,0x94,0xD4,0xD4,0xF8,0xFF,0xCE,0xFC,0xFC,0xFC,0xFC,0x00,0x01,0x03,0x03,0x01, 0x01,0x07,0x07,0x03,0x02,0x07,0x07,0x00 }, /*-- 文字: 联 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x04,0xFC,0xFC,0xFC,0xFC,0xD4,0xF4,0xF4,0xFE,0x56,0x42,0x00,0x01,0x01,0x01,0x07, 0x07,0x06,0x03,0x01,0x01,0x03,0x02,0x00 }, /*-- 文字: 大 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x00,0x00,0x20,0x20,0xE2,0xFE,0xFE,0x90,0x10,0x10,0x00,0x00,0x00,0x04,0x06,0x07, 0x03,0x01,0x01,0x03,0x03,0x06,0x04,0x00 }, /*-- 文字: 飞 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x04,0x04,0x04,0x04,0x04,0x7E,0xFE,0xBE,0x3C,0x2C,0x84,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x01,0x03,0x02,0x02,0x03,0x00 }, /*-- 文字: 思 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x00,0x80,0xCC,0x3C,0x3C,0x7E,0xFE,0xBE,0x5E,0x46,0x40,0x00,0x00,0x01,0x01,0x01, 0x03,0x02,0x02,0x02,0x03,0x03,0x02,0x00 }, /*-- 文字: 卡 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x00,0x20,0x20,0x30,0x11,0xFF,0xFF,0xD4,0xD4,0x90,0x10,0x00,0x00,0x00,0x00,0x00, 0x00,0x07,0x07,0x00,0x00,0x00,0x00,0x00 }, /*-- 文字: 尔 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x00,0x20,0xB0,0xF8,0x1F,0xFF,0xFA,0x48,0xD8,0x98,0x88,0x00,0x00,0x00,0x01,0x01, 0x02,0x07,0x07,0x00,0x00,0x01,0x01,0x00 }, /*-- 文字: 工 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x00,0x00,0x08,0x08,0x08,0xFC,0xFC,0x04,0x04,0x04,0x00,0x00,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00 }, /*-- 文字: 作 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x40,0x70,0x38,0xFE,0xF6,0x38,0xFF,0xFF,0xFA,0xA8,0xA8,0x00,0x00,0x00,0x03,0x03, 0x01,0x00,0x07,0x07,0x03,0x00,0x00,0x00 }, /*-- 文字: 室 --*/ /*-- 楷体9; 此字体下对应的点阵为:宽x高=12x12 --*/ /*-- 高度不是8的倍数,现调整为:宽度x高度=12x16 --*/ { 0x00,0x18,0x1C,0x4C,0x7C,0xFE,0xFE,0x7C,0x4C,0x0C,0x0C,0x00,0x00,0x04,0x04,0x05, 0x05,0x07,0x07,0x07,0x03,0x06,0x04,0x00 }, }; /*------------------------------------------------ 函 数 名:void LCD_Write_Byte(uint8 dat, uint8 command) 功 能:写入数据或者命令 输入参数:dat 写入的数据,command 数据或者命令选择 输出参数:无 函数类型:内部函数 特殊声明:上升沿触发,从高位读写 ------------------------------------------------*/ void LCD_Write_Byte(uint8 dat, uint8 command) { uint8 i = 0; /*打开芯片使能端*/ //LCD_CE = 0; Clr_CE; /*判断写入数据还是命令*/ if (command == 0) { //LCD_DC = 0; Clr_DC; } else { //LCD_DC = 1; Set_DC; } for (i = 0;i < 8;i++) { /*从高位写起*/ if(dat & 0x80) { //LCD_SDIN = 1; Set_SDIN; } else { //LCD_SDIN = 0; Clr_SDIN; } /*(上升沿触发)*/ //LCD_SCLK = 0; Clr_SCLK; dat = dat << 1; //LCD_SCLK = 1; Set_SCLK; } /*关使能端*/ //LCD_CE = 1; Set_CE; } /*------------------------------------------------ 函 数 名:void LCD_Set_XY(uint8 X, uint8 Y) 功 能:设置坐标 输入参数:X,Y 代表设置的坐标 输出参数:无 函数类型:内部函数 ------------------------------------------------*/ void LCD_Set_XY(uint8 X, uint8 Y) { LCD_Write_Byte(0x40 | Y, 0); LCD_Write_Byte(0x80 | X, 0); } /*------------------------------------------------ 函 数 名:void LCD_Clear(void) 功 能:清屏 输入参数:无 输出参数:无 函数类型:外部函数 ------------------------------------------------*/ void LCD_Clear(void) { uint16 i = 0; /*使用基本指令集*/ //LCD_Write_Byte(0x0c, 0); /*设置初始地址从0开始*/ LCD_Set_XY(0,0); /*将每一位都写0用于清屏,0是灭,1是亮*/ for (i = 0; i < 504; i++) { LCD_Write_Byte(0, 1); } } /*------------------------------------------------ 函 数 名:void LCD_Init(void) 功 能:初始化芯片 输入参数:无 输出参数:无 函数类型:外部函数 ------------------------------------------------*/ /*------------------------------------------------ 芯片初始化时,LCD驱动有以下状态: 1:电源节省模式为 芯片处于掉电模式 2:水平寻址 3:使用基本指令集 ------------------------------------------------*/ void LCD_INIT(void) { Set_DDR_CE; Set_DDR_RST; Set_DDR_DC; Set_DDR_SDIN; Set_DDR_SCLK; /*用一个低电平复位*/ //LCD_RST = 0; Clr_RST; //Delay_Nus(1); asm("nop"); /*复位后及时拉高*/ //LCD_RST = 1; Set_RST; //LCD_CE = 0; Clr_CE; //Delay_Nus(1); asm("nop"); //LCD_CE = 1; Set_CE; //Delay_Nus(1); asm("nop"); /*使用扩张指令集*/ LCD_Write_Byte(0x21, 0); /*设置偏置电压*/ LCD_Write_Byte(0xd0, 0); /*温度校正*/ //LCD_Write_Byte(0x06, 0); /*1:48*/ //LCD_Write_Byte(0x13, 0); /*使用基本指令集*/ LCD_Write_Byte(0x20, 0); /*设置正常显示模式*/ LCD_Write_Byte(0x0c, 0); /*清屏*/ LCD_Clear(); //LCD_CE = 0; Clr_CE; //Delay_Nus(1); asm("nop"); } /*------------------------------------------------ 函 数 名:void LCD_Write_Char(uint8 c) 功 能:写一个字符 输入参数:c 要写入的字符 输出参数:无 函数类型:内部函数 ------------------------------------------------*/ void LCD_Write_Char(uint8 c) { uint8 line = 0; c -= 32; for (line=0; line<6; line++) { LCD_Write_Byte(ASSIC_Font[c][line], 1); } } /*------------------------------------------------ 函 数 名:void LCD_Write_English_String(uint8 X,uint8 Y,char *s) 功 能:向指定位置写入一串字符 输入参数:X,Y代表地址 s代表要输入的字符串 输出参数:无 函数类型:外部函数 特别说明:使用数组时,要留出最后一位,或者直接加‘\0’!! ------------------------------------------------*/ void LCD_Write_English_String(uint8 X,uint8 Y,char *s) { LCD_Set_XY(X,Y); while (*s) { LCD_Write_Char(*s); s++; } } /*------------------------------------------------ 函 数 名:void LCD_Write_Chinese_String(uint8 X, uint8 Y, uint8 ch_with, uint8 num,uint8 line,uint8 row) 功 能:向指定坐标写入中文句子 输入参数:X,Y 设置的坐标,ch_with 汉字的宽度,num 汉字的数量 line 从第几行开始,字与字间的宽度 输出参数:无 函数类型:外部函数 ------------------------------------------------*/ void LCD_Write_Chinese_String(uint8 X, uint8 Y,uint8 ch_with, uint8 num,uint8 *s,uint8 line,uint8 row) { uint8 i = 0; uint8 n = 0; uint8 (*catch)[25] = s; 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(catch[line + i][n],1); } i++; LCD_Set_XY((X + (ch_with + row) * i),Y); } }
//5110.h
/*********************************************************************** * 5110模块 ************************************************************************/ //IO数据口定义 #define uint8 unsigned char #define uint16 unsigned int #define uint32 unsigned long #define sint8 signed char #define sint16 signed int #define sint32 signed long #define PORTX PORTB #define CE PB0 #define RST PB1 #define DC PB2 #define SDIN PB3 #define SCLK PB4 //LCD_CE 使能端(低电平有效) #define Set_CE PORTX |= (1 << CE) #define Clr_CE PORTX &= ~(1 << CE) //LCD_RST 复位(低电平有效) #define Set_RST PORTX |= (1 << RST) #define Clr_RST PORTX &= ~(1 << RST) //LCD_DC 选择命令/地址或输入数据 #define Set_DC PORTX |= (1 << DC) #define Clr_DC PORTX &= ~(1 << DC) //LCD_SDIN 数据线 #define Set_SDIN PORTX |= (1 << SDIN) #define Clr_SDIN PORTX &= ~(1 << SDIN) //LCD_SCLK 时钟线(上升沿触发) #define Set_SCLK PORTX |= (1 << SCLK) #define Clr_SCLK PORTX &= ~(1 << SCLK) //IO数据方向定义 #define DDRX DDRB #define Set_DDR_CE DDRX |= (1 << DDB0) #define Set_DDR_RST DDRX |= (1 << DDB1) #define Set_DDR_DC DDRX |= (1 << DDB2) #define Set_DDR_SDIN DDRX |= (1 << DDB3) #define Set_DDR_SCLK DDRX |= (1 << DDB4) //函数声明 void LCD_INIT(void); //初始化屏幕 void LCD_Clear(void); //清屏 void LCD_Write_Char(uint8 c); //写一个字符 void LCD_Set_XY(uint8 X, uint8 Y); //设置坐标 void LCD_Write_Byte(uint8 dat, uint8 command);//写一个字节 void LCD_Write_English_String(uint8 X,uint8 Y,char *s); //指定位置写英文字符串 void LCD_Write_Chinese_String(uint8 X, uint8 Y, uint8 ch_with,uint8 num,uint8 *s,uint8 line,uint8 row);//指定位置写汉字串 extern uint8 Chinese_Font[][25];