英锐恩单片机论坛,Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流

 找回密码
 立即注册
搜索
电子烟方案单片机单片机开发深圳单片机开发
单片机方案国产单片机8位单片机电子烟方案开发
查看: 4802|回复: 0
打印 上一主题 下一主题

PIC16F877A与液晶显示器24064(T6963内核)C程序zhuan

[复制链接]
跳转到指定楼层
1#
发表于 2012-8-21 17:06:41 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/****************************************************************************/
//*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<pic.h>
#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<x;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);
}


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|公司首页|Microchip单片机,模拟器件,接口电路,麦肯单片机,单片机应用交流 ( 粤ICP备09008620号 )

GMT+8, 2024-11-24 02:16 , Processed in 0.051991 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表