单片机彩色液晶屏的使用方法
发布网友
发布时间:2022-04-22 15:36
我来回答
共3个回答
热心网友
时间:2023-06-25 23:49
#include "reg52.h"
sbit LED=P1^0;//LED锁存器
sbit SEG=P1^1;//数码管段选锁存器
sbit DIG=P1^2;//数码管位选锁存器
unsigned char t;
sbit LCDRS=P2^7;//数据指令控制
sbit LCDRW=P2^6;//读写控制
sbit LCDEN=P2^5;//液晶屏使能控制
//**********延时函数,延时n*1ms*********
void delay(unsigned char n)
{
int i,j;
for (i=0; i<n; i++)
for (j=0; j<100; j++)
;
}
//*************写命令***************
void Write_Cmd(unsigned char C)
{
LCDEN=1;//使能端,由高电平跳变成低电平时,液晶屏模块执行命令
LCDRS=0;//指令寄存器选择
P0=C;
delay(5);
LCDEN=0;
}
//**************写数据**************
void Write_Data(unsigned char D)
{
LCDEN=1;//使能端,由高电平跳变成低电平时,液晶屏模块执行命令
LCDRS=1;//选择数据寄存器
P0=D;
delay(5);
LCDEN=0;
}
//**********LCD初始化*****************
void LCD_Init()
{
LCDRS=0;//指令寄存器选择
Write_Cmd(0x01);//清屏
Write_Cmd(0x38);//功能设置8位双行显示5*7点阵
Write_Cmd(0x0F);//开关显示设置
Write_Cmd(0x06);//输入方式设置,光标从左向右移动,内容不移动
}
void main()
{
unsigned char Code1[]="I LOVE MCU!";
unsigned char m;
//LED,数码管锁存器片选设置
LED=0;
DUAN=0;
WEI=0;
LCDRW=0;//写选择
LCD_Init();
Write_Cmd(0x80+0x01);//写入显示缓冲区起始地址为1行2列
for(m=0;m<11;m++)
{
Write_Data(Code1[m]);
delay(3);
}
while (1)
;
}//end of main
热心网友
时间:2023-06-25 23:49
可以选用彩屏模块。。。。联系本人
/*------------------------------------------------------------------------------
DEMO.C
Copyright 1995-1999 Keil Software, Inc.
------------------------------------------------------------------------------*/
#include <REG51.H>
#include <stdio.h>
#define uchar unsigned char
#define RED0XF800
#define GREEN0X07E0
#define BLUE0X000F
#define YELLOW0XFFE0
#define WHITE0XFFFF
#define BLACK0X0000
sbit buzy=P1^7;
#define uchar unsigned char
#define HmiIsBusy (buzy==0)
void DelayMs(unsigned int dly )
{
unsigned int a=30;
while(dly--)
{
a=50;
while (a--);
}
}
/*------------------------------------------------
The main C function. Program execution starts
here after stack initialization.
------------------------------------------------*/
void main (void)
{
unsigned int LcdXsize,LcdYsize;
unsigned int temp;
/*------------------------------------------------
Setup the serial port for 9600 baud at 11.0592MHz.
------------------------------------------------*/
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 253; /* TH1: reload value for 9600 baud @ 11.0592MHz */
TR1 = 1; /* TR1: timer 1 run */
TI = 1; /* TI: set TI to send first char of UART */
DelayMs(500);
printf("CLS %d\n",BLACK);
while(!HmiIsBusy);while(HmiIsBusy);
DelayMs(500);
/*------------------------------------------------
Get HMI resolution
------------------------------------------------*/
LcdXsize=0;
LcdYsize=0;
while( (LcdXsize>480)||(LcdXsize<240)||(LcdYsize>480)||(LcdYsize<240))
{
LcdXsize=0;
LcdYsize=0;
RI=0;
printf("SIZE\n");
while(RI!=1);
RI=0;
while(RI!=1);
RI=0;
while(RI!=1);
RI=0;
while(RI!=1);
RI=0;
while(RI!=1);
RI=0;
LcdXsize+=((SBUF-0X30)*100);
while(RI!=1);
RI=0;
LcdXsize+=((SBUF-0X30)*10);
while(RI!=1);
RI=0;
while(RI!=1);
RI=0;
while(RI!=1);
RI=0;
LcdYsize+=((SBUF-0X30)*100);
while(RI!=1);
RI=0;
LcdYsize+=((SBUF-0X30)*10);
while(RI!=1);
RI=0;
DelayMs(50);
}
while(1)
{
/*------------------------------------------------
Display RED GREEN BLUE
------------------------------------------------*/
printf("CLS %d\n",RED);
while(!HmiIsBusy);while(HmiIsBusy);
DelayMs(1000);
printf("CLS %d\n",GREEN);
while(!HmiIsBusy);while(HmiIsBusy);
DelayMs(1000);
printf("CLS 30\n");
while(!HmiIsBusy);while(HmiIsBusy);
DelayMs(1000);
/*------------------------------------------------
Demo1 CIRCLE
------------------------------------------------*/
printf("CLS 0\n");
while(!HmiIsBusy);while(HmiIsBusy);
printf("STR 0 0 %d Demo1\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 20 %d CIRCLE\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 20 %d \n",LcdXsize/2,LcdYsize/2-15,WHITE);
while(!HmiIsBusy);while(HmiIsBusy);
printf("CIRCLE %d %d 21 %d \n",LcdXsize/2,LcdYsize/2-15,WHITE);
while(!HmiIsBusy);while(HmiIsBusy);
printf("CIRCLE %d %d 20 31 \n",LcdXsize/2-50,LcdYsize/2-15);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 21 31 \n",LcdXsize/2-50,LcdYsize/2-15);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 20 %d \n",LcdXsize/2+50,LcdYsize/2-15,RED);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 21 %d \n",LcdXsize/2+50,LcdYsize/2-15,RED);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 20 %d \n",LcdXsize/2-25,LcdYsize/2+8,YELLOW);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 21 %d \n",LcdXsize/2-25,LcdYsize/2+8,YELLOW);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 20 %d \n",LcdXsize/2+25,LcdYsize/2+8,GREEN);
while(!HmiIsBusy); while(HmiIsBusy);
printf("CIRCLE %d %d 21 %d \n",LcdXsize/2+25,LcdYsize/2+8,GREEN);
while(!HmiIsBusy); while(HmiIsBusy);
/*------------------------------------------------
Demo2 LINE AND RECTANGLE
------------------------------------------------*/
DelayMs(3000);
printf("CLS 0\n");
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 0 %d Demo2\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 20 %d LINE AND RECTANGLE\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("RECT %d %d %d %d 31\n",LcdXsize*2/10,LcdYsize*2/10,LcdXsize*8/10,LcdYsize*8/10);
while(!HmiIsBusy); while(HmiIsBusy);
printf("RECT %d %d %d %d %d\n",LcdXsize*3/10,LcdYsize*3/10,LcdXsize*7/10,LcdYsize*7/10,GREEN);
while(!HmiIsBusy); while(HmiIsBusy);
printf("RECT %d %d %d %d %d\n",LcdXsize*4/10,LcdYsize*4/10,LcdXsize*6/10,LcdYsize*6/10,RED);
while(!HmiIsBusy); while(HmiIsBusy);
printf("LINE %d %d %d %d %d\n",LcdXsize*2/10,LcdYsize*2/10,LcdXsize*8/10,LcdYsize*8/10,YELLOW);
while(!HmiIsBusy); while(HmiIsBusy);
printf("LINE %d %d %d %d %d\n",LcdXsize*8/10,LcdYsize*2/10,LcdXsize*2/10,LcdYsize*8/10,YELLOW);
while(!HmiIsBusy); while(HmiIsBusy);
/*------------------------------------------------
Demo3 DISPLAY PICTURE
------------------------------------------------*/
DelayMs(3000);
printf("CLS 0\n");
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 0 %d Demo3\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 20 %d PICTURE\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("PIC 2 0 40\n");
while(!HmiIsBusy); while(HmiIsBusy);
DelayMs(1000);
printf("PIC 3 0 40\n");
while(!HmiIsBusy); while(HmiIsBusy);
/*------------------------------------------------
Demo4 CUT A SMALL PICTURE FROM BIG PICTURE
------------------------------------------------*/
DelayMs(3000);
printf("CLS 0\n");
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 0 %d Demo4\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 20 %d CUT PICTURE\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
for(temp=0;temp<30;temp++)
{
printf("CUT 4 %d %d %d %d 128 128\n",LcdXsize/2-64,LcdYsize/2-64,temp,temp);
while(!HmiIsBusy); while(HmiIsBusy);
}
for(temp=30;temp>0;temp--)
{
printf("CUT 4 %d %d %d %d 128 128\n",LcdXsize/2-64,LcdYsize/2-64,temp,temp);
while(!HmiIsBusy);while(HmiIsBusy);
}
/*------------------------------------------------
Demo5 MOTION PICTURE
------------------------------------------------*/
DelayMs(3000);
printf("CLS 0\n");
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 0 %d Demo5\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR 0 20 %d MOTION\n",WHITE);
while(!HmiIsBusy); while(HmiIsBusy);
if(((LcdXsize==320)&&(LcdYsize==240))||((LcdXsize==240)&&(LcdYsize==320)))
{
printf("MOT 0 40 10 15 10 \n");
while(!HmiIsBusy); while(HmiIsBusy);
}
if(((LcdXsize==400)&&(LcdYsize==240))||((LcdXsize==240)&&(LcdYsize==400)))
{
printf("MOT 0 40 8 13 10 \n");
while(!HmiIsBusy); while(HmiIsBusy);
}
if(((LcdXsize==320)&&(LcdYsize==480))||((LcdXsize==480)&&(LcdYsize==320)))
{
printf("MOT 0 40 5 10 10 \n");
while(!HmiIsBusy); while(HmiIsBusy);
}
/*------------------------------------------------
END OF DEMO
------------------------------------------------*/
DelayMs(7000);
printf("MOFF\n");
DelayMs(100);
printf("CLS 0\n");
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR %d %d %d Demo Finished!\n",(LcdXsize-14*8)/2,LcdYsize/2-64,RED);
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR %d %d %d Welcom to Use M7-TFT HMI!\n",(LcdXsize-24*8)/2,LcdYsize/2,RED);
while(!HmiIsBusy); while(HmiIsBusy);
printf("STR %d %d 31 Contact us: mcucool@163.com\n",(LcdXsize-27*8)/2,(LcdYsize-20));
while(!HmiIsBusy); while(HmiIsBusy);
DelayMs(8000);
}
while(1);
}
//END
热心网友
时间:2023-06-25 23:50
(武汉谷鑫科技)专业从事单片机驱动彩色液晶显示屏,欢迎到网站上下载资料阅览。各种例程详细。