zidaozhou的笔记 https://passport2.21ic.com/?286214 [收藏] [复制] [RSS] 有朋自远方来,不亦乐乎 欢迎各位朋友和我一起学习探讨

日志

T6963内核LCD程序(c)

已有 939 次阅读2008-8-22 13:53 |个人分类:单片机|系统分类:单片机| 单片机程序


/****************************************************************************/
//*Filename:lcd.c               */               */
/*Programmer:资道周                                                         */
/*Creat Time:2006-3-14 11:30                                                */
/*Modify Time:2006-3-14 11:30                                               */
/*Description:This is a test for LCD                                        */
/*   硬件连接关系:                                                      */
/*   MCU(PIC16F877A)            LCD(24064,T6963)                        */
/*   RA0------------------------WR                                      */
/*   RA1------------------------RD                                      */
/*     RA2------------------------CD                                      */
/*     RB0------------------------D0                                      */
/*     RB1------------------------D1                                      */
/*     RB2------------------------D2                                      */
/*     RB3------------------------D3                                      */
/*     RB4------------------------D4                                      */
/*     RB5------------------------D5                                      */
/*     RB6------------------------D6                                      */
/*     RB7------------------------D7                                      */
/*            CE-----------------GND                  */
/*     程序显示内容:在液晶屏坐标(4,2)开始负向显示"THIS IS A TEST!".   */
/*                   在液晶屏坐标(4,3)开始闪烁显示"THIS IS A TEST!".   */
/*                   在液晶屏坐标(19,3)开始负向闪烁显示汉字"资道周"    */
/*                   在液晶屏坐标(19,5)开始正向显示汉字"资道周"        */
/*                                                                          */
/*                                                                          */
/****************************************************************************/



#include
#define  uchar unsigned char
#define  uint unsigned int
const uchar font[]={
   0x41,0x21,0x23,0x14,0xE8,0x41,0x46,0x5F,
0x10,0x11,0x11,0x11,0x12,0x04,0x18,0x60,
0x00,0x00,0xFC,0x58,0x40,0xA0,0x18,0xF6,
0x10,0x10,0x10,0x10,0xC0,0x30,0x1C,0x08,
0x02,0x41,0x2F,0x20,0x01,0x03,0xE2,0x23,
0x22,0x23,0x22,0x23,0x22,0x50,0x8F,0x00,
0x10,0x20,0xFC,0x80,0x00,0xF0,0x10,0xF0,
0x10,0xF0,0x10,0xF0,0x10,0x00,0xFE,0x00,
0x00,0x1F,0x10,0x13,0x10,0x10,0x17,0x10,
0x13,0x12,0x12,0x13,0x22,0x20,0x40,0x80,
0x00,0xFC,0x84,0xE4,0x84,0x84,0xF4,0x04,
0xE4,0x24,0x24,0xE4,0x24,0x04,0x14,0x08
};

uchar read_data(void){
uchar i;
TRISC="0x00";
TRISB="0xff";
PORTC|=0x04;    //set CD
PORTC&=0xfd;    //clear RD
i="PORTB";
PORTC|=0x02;    //set RD
return(i);
}
void write_data(uchar data_d){
TRISC="0x00";
TRISB="0x00";
PORTC&=0xfb;    //clear CD
PORTB="data"_d;
PORTC&=0xfe;   //clear WR
PORTC|=0x01;    //set WR
}
void write_contr(uchar data_c){
TRISC="0x00";
TRISB="0x00";
PORTC|=0x04;   //clear CD
PORTB="data"_c;
PORTC&=0xfe;  //clear WR
PORTC|=0x01;   //set WR
}



void lcd_double_operator(uchar data1,uchar data2,uchar com){
uchar i;
i="0";
while(i!=0x02)
{
  i="read"_data();
  i="i"&0x02;
}
write_data(data1);    /*参数1*/
i="0";
while(i!=0x02)
{
  i="read"_data();
  i="i"&0x02;
}
write_data(data2);         /*参数2*/
i="0";
while(i!=0x01)
{
  i="read"_data();
  i="i"&0x01;
}
write_contr(com);       /*指令*/
}



void lcd_single_operator(uchar data1,uchar com){
uchar i;
i="0";
while(i!=0x02)
{
  i="read"_data();
  i="i"&0x02;
}
write_data(data1);     /*参数1*/
  i="0";
while(i!=0x01)
{
  i="read"_data();
  i="i"&0x01;
}
write_contr(com);        /*指令*/
}



void lcd_none_operator(uchar com){
uchar i;
i="0";
while(i!=0x01)
{
  i="read"_data();
  i="i"&0x01;
}
write_contr(com);         /*指令*/
}

void lcd_ini(){
lcd_double_operator(0x00,0x00,0x40);
lcd_double_operator(0x1e,0x00,0x41);
   lcd_double_operator(0x00,0x0c,0x42);
lcd_double_operator(0x1e,0x00,0x43);
lcd_none_operator(0xa0);
lcd_none_operator(0x84);
lcd_none_operator(0x9f);
}

void creat_cgram(uchar count){
uint i,x;
x="count"*4;
x="x"*8;
lcd_double_operator(0x03,0x00,0x22);
lcd_double_operator(0x00,0x1c,0x24);
for (i=0;i lcd_single_operator(font,0xc0);
  }
}

void lcd_clear(){
uint i;
lcd_double_operator(0x00,0x00,0x24);    //首地址
for(i=0;i<0x1000;i++){
  lcd_single_operator(0x00,0xc0);     
  }
}

void write_english(uchar cursor_x,uchar cursor_y,uchar c_code,uchar attr){
uint x;
x="cursor"_y*30;
x="x"+cursor_x;                  /*y=cursor_y*30+cursor_x*/
  lcd_double_operator((x&0x00ff),(x/256),0x24);
lcd_single_operator(c_code,0xc4);
lcd_double_operator((x&0x00ff),(x/256)+0x0c,0x24);
lcd_single_operator(attr,0xc4);  
}
 
void write_chinese(uchar cursor_x,uchar cursor_y,uchar ct_code,uchar attr){
  uint x;
x="cursor"_y*30;
x="x"+cursor_x;                            //y=cursor_y*30+cursor_x
  lcd_double_operator((x&0x00ff),(x/256),0x24);
lcd_single_operator(ct_code,0xc4);
lcd_double_operator((x&0x00ff),(x/256)+0x0c,0x24);
lcd_single_operator(attr,0xc4);
lcd_double_operator(((x&0x00ff)+1),(x/256),0x24);
lcd_single_operator(ct_code+2,0xc4);
lcd_double_operator(((x&0x00ff)+1),(x/256)+0x0c,0x24);
lcd_single_operator(attr,0xc4);
x+=30;
lcd_double_operator((x&0x00ff),(x/256),0x24);
lcd_single_operator(ct_code+1,0xc4);
lcd_double_operator((x&0x00ff),(x/256)+0x0c,0x24);
lcd_single_operator(attr,0xc4);
lcd_double_operator(((x&0x00ff)+1),(x/256),0x24);
lcd_single_operator(ct_code+3,0xc4);
lcd_double_operator(((x&0x00ff)+1),(x/256)+0x0c,0x24);
lcd_single_operator(attr,0xc4);
}



void main(void)
{

lcd_ini();
lcd_clear();
creat_cgram(0x03);
lcd_double_operator(0x08,0x00,0x21);
write_english(0x04,0x02,'t'-0x20,0x05);
write_english(0x05,0x02,'h'-0x20,0x05);
write_english(0x06,0x02,'i'-0x20,0x05);
write_english(0x07,0x02,'s'-0x20,0x05);
write_english(0x08,0x02,' '-0x20,0x05);
write_english(0x09,0x02,'i'-0x20,0x05);
write_english(0x0a,0x02,'s'-0x20,0x05);
write_english(0x0b,0x02,' '-0x20,0x05);
write_english(0x0c,0x02,'a'-0x20,0x05);
write_english(0x0d,0x02,' '-0x20,0x05);
write_english(0x0e,0x02,'t'-0x20,0x05);
write_english(0x0f,0x02,'e'-0x20,0x05);
write_english(0x10,0x02,'s'-0x20,0x05);
write_english(0x11,0x02,'t'-0x20,0x05);
write_english(0x12,0x02,'!'-0x20,0x05);
write_english(0x04,0x03,'t'-0x20,0x08);
write_english(0x05,0x03,'h'-0x20,0x08);
write_english(0x06,0x03,'i'-0x20,0x08);
write_english(0x07,0x03,'s'-0x20,0x08);
write_english(0x08,0x03,' '-0x20,0x08);
write_english(0x09,0x03,'i'-0x20,0x08);
write_english(0x0a,0x03,'s'-0x20,0x08);
write_english(0x0b,0x03,' '-0x20,0x08);
write_english(0x0c,0x03,'a'-0x20,0x08);
write_english(0x0d,0x03,' '-0x20,0x08);
write_english(0x0e,0x03,'t'-0x20,0x08);
write_english(0x0f,0x03,'e'-0x20,0x08);
write_english(0x10,0x03,'s'-0x20,0x08);
write_english(0x11,0x03,'t'-0x20,0x08);
write_english(0x12,0x03,'!'-0x20,0x08);
write_chinese(0x13,0x04,0x80,0x0d);
write_chinese(0x15,0x04,0x84,0x0d);
write_chinese(0x17,0x04,0x88,0x0d);
write_chinese(0x13,0x06,0x80,0x00);
write_chinese(0x15,0x06,0x84,0x00);
write_chinese(0x17,0x06,0x88,0x00);
   while(1);
}


路过

鸡蛋

鲜花

握手

雷人

评论 (0 个评论)