|
【玩转C2000 Launchpad】NOKIA 5110液晶显示
[复制链接]
花了一个早上写了一个NOKIA5110液晶显示程序!
祝大家元旦快乐!
附上工程:
5110-C2000LAUNCHPAD.zip
(248.07 KB, 下载次数: 130, 售价: 1 分芯积分)
- /*--------------------------------------------
- LCD_write_byte: 使用SPI接口写数据到LCD
- 输入参数:dt:写入的数据;
- command :写数据/命令选择;
- ----------------------------------------------*/
- void LCD_write_byte(unsigned char dt, unsigned char command)
- {
- unsigned char i;
- sce=0;
- dc=command;
- for(i=0;i<8;i++)
- {
- if(dt&0x80)
- sdin=1;
- else
- sdin=0;
- dt=dt<<1;
- sclk=0;
- sclk=1;
- }
- dc=1;
- sce=1;
- sdin=1;
- }
- /*---------------------------------------
- LCD_init: 3310LCD初始化
- ----------------------------------------- */
- void LCD_init(void)
- {
- res=0;
- delayms(10);
- res=1;
- LCD_write_byte(0x21,0);//初始化Lcd,功能设定使用扩充指令
- LCD_write_byte(0xC6,0);//设定液晶偏置电压
- LCD_write_byte(0x06,0);//温度校正
- LCD_write_byte(0x13,0); //1:48
- LCD_write_byte(0x20,0);//使用基本指令
- LCD_write_byte(0x0C,0);//设定显示模式,正常显示
- }
- /*-----------------------------------------------------------------------
- LCD_set_XY : 设置LCD坐标函数
- 输入参数:X :0-83
- Y :0-5
- -----------------------------------------------------------------------*/
- void LCD_set_XY(unsigned char X, unsigned char Y)
- {
- LCD_write_byte(0x40 | Y, 0); // column
- LCD_write_byte(0x80 | X, 0); // row
- }
- /*-----------------------------------------------------------------------
- LCD_clear : LCD清屏函数
- -----------------------------------------------------------------------*/
- 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_write_char : 显示英文字符
- 输入参数:c :显示的字符;
- -----------------------------------------------------------------------*/
- 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);
- }
- /*-----------------------------------------------------------------------
- LCD_write_english_String : 英文字符串显示函数
- 输入参数:*s :英文字符串指针;
- X、Y : 显示字符串的位置,x 0-83 ,y 0-5
- -----------------------------------------------------------------------*/
- void LCD_write_english_string(unsigned char X,unsigned char Y,char *s)
- {
- LCD_set_XY(X,Y);
- while (*s)
- {
- LCD_write_char(*s);
- s++;
- }
- }
- /*-----------------------------------------------------------------------
- LCD_write_chinese_string: 在LCD上显示汉字
- 输入参数:X、Y :显示汉字的起始X、Y坐标;
- ch_with :汉字点阵的宽度
- num :显示汉字的个数;
- line :汉字点阵数组中的起始行数
- row :汉字显示的行间距
- 测试:
- 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
- {
- for (n=0; 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(chinese[line+i][n],1);
- }
- i++;
- LCD_set_XY((X+(ch_with+row)*i),Y);
- }
- }
- /*----------------------------------------------
- LCD_draw_map : 位图绘制函数
- 输入参数:X、Y :位图绘制的起始X、Y坐标;
- *map :位图点阵数据;
- Pix_x :位图像素(长)
- Pix_y :位图像素(宽)
- -----------------------------------------------*/
- void 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
- {
- LCD_set_XY(X,Y);
- for(i=0; i
- {
- LCD_write_byte(map[i+n*Pix_x], 1);
- }
- Y++; //换行
- }
- }
复制代码
[ 本帖最后由 IC爬虫 于 2013-1-1 14:00 编辑 ]
|
|