|
5110LCD邮购回来了,经过一个晚上的研究算是可以点亮了,但是我用的16f84a,程序存储器不是非常大,但是我想显示大一些的字符,没办法只好自己研究了,经过好几个夜晚的调试修改终于可以正常显示了,今天过来显摆下。呵呵!
大家注意第一行的三个大数字其实和下面的小字符所使用的字库是一样大小的
本程序通过对字库点阵信息进行放大处理实现了小字库,大字符的显示节约宝贵的程序存储器
-
-
- #include
- //#include "zk"
- //---------------------------------------------
- #define uchar unsigned char
- #define uint unsigned int
- //---------------------------------------------
- #define LCD_SCE RB2
- #define LCD_RST RB3
- #define LCD_DC RB4//0=command,1=data
- #define LCD_SDI RB5
- #define LCD_SCL RB6
- #define LCD_ON RB0
- #define LCD_LED RB7
- #define DATA 1
- #define CMD 0
- __CONFIG(XT&WDTDIS);
- //-----------------------------------------------
- void Delay_ms(uint t);
- void LCD_init(void);
- void LCD_send_data(uchar Data ,uchar CMD_DATA);
- void LCD_clear(void);
- void LCD_set_xy(uchar X,uchar Y);
- void LCD_send_char(uchar x,uchar y,uchar indx,uchar type);//0-8*16/1-16*16
- const unsigned char zk_asc[][16]=
- {
- // 0(0) 1(1) 2(2) 3(3) 4(4) 5(5) 6(6) 7(7) 8(8) 9(9)
- {0x00,0xF0,0x08,0x04,0x04,0x04,0x08,0xF0,0x00,0x0F,0x10,0x20,0x20,0x20,0x10,0x0F},//00
- {0x00,0x00,0x08,0x08,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0x00,0x00,0x00},//11
- {0x00,0x18,0x04,0x04,0x04,0x84,0x78,0x00,0x00,0x38,0x24,0x22,0x21,0x20,0x20,0x00},//22
- {0x00,0x18,0x84,0x84,0x84,0x84,0x78,0x00,0x00,0x18,0x20,0x20,0x20,0x20,0x1F,0x00},//33
- {0x00,0x00,0x00,0xC0,0x30,0x0C,0xFC,0x00,0x00,0x04,0x07,0x04,0x04,0x04,0x3F,0x04},//44
- {0x00,0xFC,0x44,0x44,0x44,0x44,0x84,0x00,0x00,0x18,0x20,0x20,0x20,0x20,0x1F,0x00},//55
- {0x00,0xF8,0x84,0x84,0x84,0x84,0x18,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},//66
- {0x00,0x04,0x04,0x04,0xC4,0x34,0x0C,0x00,0x00,0x00,0x00,0x3E,0x01,0x00,0x00,0x00},//77
- {0x00,0x78,0x84,0x84,0x84,0x84,0x78,0x00,0x00,0x1F,0x20,0x20,0x20,0x20,0x1F,0x00},//88
- {0x00,0xF8,0x04,0x04,0x04,0x04,0xF8,0x00,0x00,0x18,0x21,0x21,0x21,0x21,0x1F,0x00},//99
-
- {0x00,0xFC,0x80,0x40,0x20,0x10,0x08,0x04,0x00,0x3F,0x01,0x02,0x04,0x08,0x10,0x20},//K10
- {0x00,0xFC,0x80,0x80,0x80,0x80,0x80,0xFC,0x00,0x3F,0x00,0x00,0x00,0x00,0x00,0x3F},//H11
- {0x00,0x40,0x40,0x40,0x40,0x40,0xC0,0x00,0x00,0x30,0x28,0x24,0x22,0x21,0x20,0x00},//z12
- {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00,0x20,0x3F,0x20,0x00,0x3F,0x20,0x00,0x3F},//m13
- {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x04,0x00,0x60,0x18,0x06,0x01,0x00,0x00,0x00},///14
- {0x08,0xF8,0x00,0x80,0x80,0x80,0x00,0x00,0x20,0x3F,0x21,0x00,0x00,0x20,0x3F,0x20},//h15
- };
- //-----------------------------------------------
- void Delay_ms(uint t)
- {
- uint i;
- while(--t)
- {
- for(i=0;i<500;i++){}
- }
- }
- void LCD_init(void)
- {
- LCD_SCE=1;
- LCD_RST=1;
- Delay_ms(1);
- LCD_RST=0;
- Delay_ms(1);
- LCD_RST=1;
- LCD_send_data(0x21,CMD); //扩展指令
- LCD_send_data(0xc5,CMD); //设置偏压
- LCD_send_data(0x20,CMD); //标准指令
- LCD_send_data(0x0c,CMD); //标准显示模式
- }
- void LCD_clear(void)
- {
- uint i;
- LCD_set_xy(0,0); //set the addr as 0x00
- for(i=0;i<504;i++)
- {
- LCD_send_data(0x00,DATA);
- }
- }
- void LCD_set_xy(uchar X,uchar Y){
- if(Y<6 && X<84)
- {
- LCD_send_data(0x80|X,CMD);
- LCD_send_data(0x40|Y,CMD);
- }
- }
- void LCD_send_data(uchar Data ,uchar CMD_DATA)
- {
- uchar i;
- LCD_SCE=0;
- LCD_DC=CMD_DATA>0;
- if(CMD_DATA==3) Data<<=4;
- for(i=0;i<8;i++)
- {
- LCD_SCL=0;
- if(Data & 0x80) //MSB first
- LCD_SDI=1;
- else
- LCD_SDI=0;
- LCD_SCL=1;
- if(CMD_DATA>1)
- {
- LCD_SCL=0;
- LCD_SCL=1;
- i++;
- }
- Data<<=1;
- }
- //LCD_SCL=0;
- LCD_SCE=1;
- }
- void LCD_send_char(uchar x,uchar y,uchar indx,uchar type)
- {
- uchar i,j,k,l,m;
- if(type%2==0) {k=16;l=8;}
- if(type%2==1) {k=16;l=16;}
- j=0;
- LCD_set_xy(x,y);
- for(i=0;i
- {
- if(j==l)
- {
- j=0;
- y++;
- if(type>1) y++;
- LCD_set_xy(x,y);
- }
- if(type>1)
- {
- LCD_set_xy(x+j*2,y);
- for(m=0;m<2;m++)
- LCD_send_data(zk_asc[indx][i],3);
- //LCD_send_data(zk_asc[indx][i],3);
- LCD_set_xy(x+j*2,y+1);
- for(m=0;m<2;m++)
- LCD_send_data(zk_asc[indx][i],2);
- //LCD_send_data(zk_asc[indx][i],2);
- }
- else
- LCD_send_data(zk_asc[indx][i],DATA);
- j++;
- }
- }
- //------------------------------------------------
- void main(void)
- {
- uchar i;
- OPTION=0x81;
- TRISA=0B00001110;
- TRISB=0B00000000;
- PORTA=0;
- PORTB=0;
- LCD_ON=1;
- //LCD_LED=1;
- LCD_init();
- LCD_clear();
- LCD_send_char(24,4,10,0);
- LCD_send_char(32,4,13,0);
- LCD_send_char(40,4,14,0);
- LCD_send_char(48,4,15,0);
- // LCD_send_data(0x0d,CMD); //反显
- while(1)
- {
- LCD_send_char(16,0,i/100,2);
- LCD_send_char(32,0,i/10%10,2);
- LCD_send_char(48,0,i%10,2);
- i++;
- Delay_ms(100);
- }
- }
-
复制代码
转自:http://pic16.com/bbs/dispbbs.asp?BoardID=8&ID=48275&replyID=&skin=1
|
|