lcd.c

来自「主要介绍了24c16的读写,mcu为89s52,lcd为TC2002A,完成功能」· C语言 代码 · 共 77 行

C
77
字号

#include<reg52.h>
#include"port.h"
#include"main.h"
#include"lcd.h"
#include"delay.h"
#include<intrins.h>

void SHIFT(uChar dispdata)
{         
	uChar i,j;
	DISSP = 0;                    //define variable
	j = dispdata;
	for(i=0; i<8; i++)               //write 8 bit
	{
		if((j & 0x80) == 0)
		{
			SOUT = 0;        
		}		                //get the highest bit   
		else
		{		
			SOUT = 1;	
		}
		SCK = 0;
		SCK = 1;
		SCK = 0;
		j <<= 1;                   //move left wrTemp one bit 
	}
	DISSP = 1;
}

void LCD_WCOM(uChar dispdata)   
{   

	SHIFT(dispdata);
	LCD_RS = 0 ;
	LCD_E = 1;    
	LCD_E = 0;
	DELAY(40);
}

void LCD_WDATA(uChar dispdata)
{   

	SHIFT(dispdata);
	LCD_RS = 1;
	LCD_E = 1;    
	LCD_E = 0; 
	DELAY(1);
}

void LCD_INIT(void)
{
    DELAY(40);
	
	LCD_WCOM(0x38); //0x01
	LCD_WCOM(0x38);//0x30 8位 
	LCD_WCOM(0x38); 
	LCD_WCOM(0x38);
	LCD_WCOM(0x06);//0x0c
	LCD_WCOM(0x0c);
	LCD_WCOM(0x01);
}
uChar LCD_DISP(uChar *ptr_Char, uChar postion, uChar num) //num From 0 ~1 post from 0~7
{
	uChar i;
	if ((postion >= 101) && ( postion <= 120))         //第一行  自定义101~120    100 < post < 121 
	{	
		LCD_WCOM(0x80 + postion -101); 
	}
	else if((postion >= 201) && (postion <= 220))	   //第二行 自定义201~220         200 < post < 221
		{
			LCD_WCOM(0xc0 + postion -201) ;
		}
		else if(postion != 0)
		{
			return ERROR;                                  //不在范围

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?