请高手用Keil C编写一段能在液晶屏(protel已画好单片机,用Proteus电路仿真)上显示(比如"NBA")的程序!

2024-12-27 00:49:06
推荐回答(6个)
回答1:

我来试着回答一下 不过液晶屏的型号我不保证我们用的是一样儿的
具体程序如下:(我仿真了一下,还可以)
#include
#include
typedef unsigned char uchar;
typedef unsigned int uint;
sbit L_DI = P2^0;
sbit L_RW = P2^1;
sbit L_E = P2^4;
sbit L_CS1 = P2^6;
sbit L_CS2 = P2^7;
sbit L_SET = P2^3;
sbit TEST = P3^5;
float abc;

uchar code X1[] ={0x08,0x08,0xF8,0x18,0x30,0x60,0xC0,0x80,0x00,0x00,0x08,0x08,0xF8,0x08,0x08,0x00,
0x20,0x20,0x3F,0x20,0x20,0x00,0x00,0x01,0x03,0x06,0x0C,0x18,0x3F,0x00,0x00,0x00};/*"N",0*/
uchar code X2[] = {0x00,0x08,0x08,0xF8,0xF8,0x88,0x88,0x88,0x88,0x88,0x88,0x58,0x78,0x30,0x00,0x00,
0x00,0x20,0x20,0x3F,0x3F,0x20,0x20,0x20,0x20,0x20,0x20,0x21,0x11,0x1F,0x0E,0x00};/*"B",1*/
uchar code X3[] = {0x00,0x00,0x00,0x00,0x80,0x60,0x18,0x18,0x78,0xE0,0x80,0x00,0x00,0x00,0x00,0x00,
0x20,0x20,0x38,0x26,0x23,0x02,0x02,0x02,0x02,0x03,0x2F,0x3E,0x38,0x20,0x20,0x00};/*"A",2*/
#pragma REGISTERBANK(0)
void initcomm(void)
{
PCON = 0x80;TMOD = 0X21; SCON = 0X50;
TH1 = 0XFa;TL1 = 0XFa; TR1 = 1;ES = 1;
TH0 = 0;TL0 = 0;TR0 = 1; ET0 = 1;
EA =0;
}

void delay(void)
{
uchar i,j;
abc = 0.1*5;
for (i = 0;i != 0xff;i++)
for (j = 0;j != 0xff;j++) ;
}

void LCD_C_D(bit flag,uchar ldata) /*flag=1 con flag=0 data*/
{
uchar data i;
L_DI = !flag; L_E = 0; L_RW = 0; P0 = ldata;
_nop_();
L_E = 1;
_nop_(); _nop_();
L_E = 0; L_RW = 1; L_DI = 1;
for ( i = 0; i < 10 ;i++) ;
}
void dis_one_zi(uchar x_add,uchar y_add,uchar code *po)
{
uchar i,j,w;
j = x_add*2+0xb8;
w = (y_add < 4 ? y_add : y_add-4)*16+0x40;
L_CS1 = (y_add < 4);
L_CS2 = !(y_add < 4);
LCD_C_D(1,j);
LCD_C_D(1,w);
for (i = 0; i < 32;i++)
{
if (i == 16)
{
LCD_C_D(1,j+1);
LCD_C_D(1,w);
}
LCD_C_D(0,*po++);
}
L_CS1 = L_CS2 = 0;
}

void CLRLCD(uchar number)
{
uchar data i,j;
L_CS1 = L_CS2 = 1;
for (i = 0xb8; i < 0xc0;i++)
{
LCD_C_D(1,i);
LCD_C_D(1,0X40);
for (j = 0; j < 0x40; j++)
LCD_C_D(0,number);
}
L_CS1 = L_CS2 = 0;
}

void main(void) using 0
{
uchar data i,j,number;
uchar code *p;
initcomm();
L_SET = 0;
for ( j = 0; j != 0xff; j++);
L_SET = 1;
for ( j = 0; j != 0xff; j++);
LCD_C_D(1,0X3E); /**/
LCD_C_D(1,0XC0); /**/
LCD_C_D(1,0X3F); /**/
CLRLCD(0);
while(1)
{
CLRLCD(0);
LCD_C_D(1,0X3E);
/*欢迎使用*/
p=X1; dis_one_zi(1,1,p);
p=X2; dis_one_zi(1,2,p);
p=X3; dis_one_zi(1,3,p);
LCD_C_D(1,0X3F);
delay(); delay();
CLRLCD(0);
LCD_C_D(1,0X3E);
}
}

回答2:

这程序我写过
不过我用的是LCD1602
单片机是51系列
#include
#include
#include"intrins.h"

/**********************LCD变量部分*********************/
#define LCD_OUT P1 //LCD输出端口
sbit LCD_BUSY=P1^7; //LCD忙标志,为1时忙碌
sbit RS=P3^0; //LCD控制引脚
sbit RW=P3^1; //LCD控制引脚
sbit E=P3^2; //LCD控制引脚
unsigned char LCD_ADR[10]={0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39};//0~9在LCD中对应的码地址

/*-----------------------------------------------------------------*/
/* */
/* 液晶显示模块程序 */
/* */
/*-----------------------------------------------------------------*/
void LCD_delay() //由于液晶是慢显示装置,确定液晶是否处于忙碌状态
{
loop:LCD_OUT=0xff;
RS=0;
RW=1;
E=0;
_nop_();
E=1;
if(LCD_BUSY==1) goto loop;
}

void enable() //延时,是液晶指令执行是液晶处于非忙碌状态
{
RS=0;
RW=0;
E=0;
LCD_delay();
E=1;
}

void LCD_initialize() // 液晶显示的初始化程序
{
LCD_OUT=0x01;
enable();
LCD_OUT=0x3C;
enable();
LCD_OUT=0x0f;
enable();
LCD_OUT=0x06;
enable();
LCD_OUT=0x80;
enable();
}

void LCD_display(char X,char Y,char x[]) //显示程序
{
unsigned char LCD_add,i;
if(Y==0) LCD_add=0X80+X;
if(Y==1) LCD_add=0XC0+X;
for(i=0;x[i]!='\0';i++)
{
LCD_OUT=LCD_add;
enable();
LCD_OUT=x[i];
RS=1;
RW=0;
E=1;
_nop_();
E=0;
LCD_delay();
E=1;
LCD_add++;
}
}
main()
{
LCD_initialize();
LCD_display(0,0,"NBA");
while(1);
}

回答3:

我这里有很多proteus的仿真文件,液晶屏显示的也有!需要我可以发给你!

我已经发到你邮箱去去了,注意查收!

回答4:

就这点分就想知道这么不好解决的问题啊?
你用的是什么单片机?

回答5:

我不嫌分少,至少人家勤学好问!我来告诉你:其实我不知道,读书那会C没学好~~``

回答6:

yuty