⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 12232f.c

📁 sm1628控制lcd显示屏以及按键的程序,
💻 C
字号:
/*
*****************************************************************************
*					Mountain View Silicon Tech. Inc.
*	Copyright 2007, Mountain View Silicon Tech. Inc., ShangHai, China
*					All rights reserved.
*
* Filename:			12232f.c
* Description:		lcd 12232f operation c file
*
* Change History:
*			Grey	- 3/xx/2006 - V0.1
*					- created
*			Jack	- 8/xx/2007 - V0.2
*					- change code layout
******************************************************************************
*/
/*
**********************************************************
*					INCLUDE
**********************************************************
*/

#include <reg51.h>										//include public header files
#include <string.h>
#include <intrins.h>
#include <stdio.h>

#include "type.h"										//include project header files
#include "utility.h"
#include ".\Config\syscfg.h"
#include "12232f.h"
#include "sysctrl.h"

#include ".\addon\addon_cfg.h"

sbit SDAT =	P1^3;
sbit SCLK =	P1^2;
sbit STB =	P1^0;

BYTE keydat[5];
BYTE DispBuf[6];
BYTE KeyLightTime = 0;

BYTE LEDDATA[] = {
	0x3f,	// 0
	0x06,	// 1
	0x5b,	// 2
	0x4f,	// 3
	0x66,	// 4
	0x6d,	// 5
	0x7d,	// 6
	0x07,	// 7
	0x7f,	// 8
	0x6f,	// 9
	0x39,	// C	10
	0x71,	// F	11
	0x77,	// R	12
	0x6d,	//0x3e,	// U	13
	0x40,	// -	14
	0x00,	// blank	15
};



void Write8Bit(BYTE data1)
{

	BYTE i;
	for(i = 0; i<8; i++)
	{
		SCLK = 0;
		WaitUs(0);
		if(data1 & 0x01)		//b0 first
			SDAT = 1;
		else 
			SDAT = 0;
		data1 >>= 1;
		WaitUs(0);
		SCLK = 1;
		WaitUs(0);		
	}

}
BYTE Read8Bit(void)
{
	BYTE i,rbyte = 0;
	for(i = 0; i< 8; i++)
	{
		WaitUs(1);
		SDAT = 1;
		SCLK = 0;	//read
		rbyte >>= 1;
		if(1 == SDAT)
			rbyte |= 0x80;
		WaitUs(0);
		SCLK = 1;
	}
	return(rbyte);
}
void DispOn(void)
{
	STB = 0;
	WaitUs(0);
	Write8Bit(0x8a);	//dison
	STB = 1;

}
void SetMode(void)
{
	STB = 0;
	WaitUs(0);
	Write8Bit(0x00);	// 4bit ,13seg
	STB = 1;

}
void Writecmd(void)
{
	STB = 0;
	WaitUs(0);
	Write8Bit(0x44);	// write
	STB = 1;
}
void Readcmd(void)
{
	STB = 0;
	WaitUs(0);
	Write8Bit(0x46);	// write
//	STB = 1;
}
void WriteAddr(BYTE addr1)
{
	STB = 0;
	WaitUs(0);
	Write8Bit(0xc0|(addr1&0x0f));	// addr
//	STB = 1;
}

void ReadData(void)
{
	Readcmd();
	keydat[0] = Read8Bit();
	keydat[1] = Read8Bit();
	keydat[2] = Read8Bit();
	keydat[3] = Read8Bit();
	keydat[4] = Read8Bit();
	STB = 1;
	Writecmd();
	DispOn();
}
BYTE WriteData(BYTE addr,BYTE dat)
{
	Writecmd();
	WriteAddr(addr);
	Write8Bit(dat);
	STB = 1;
}
void ClearLed(void)
{
	BYTE  i;
	for(i = 0; i<6; i++)DispBuf[i] = 0;
	for(i=0; i<14; i++)
	{
//		DispBuf[i] = 0;
		WriteData(i, 0);
	}
	DispOn();
}

void LightVolAdd(BYTE on)
{
	if(on)
	{
		KeyLightTime = 2;
		DispBuf[5] |= 0x02;
	}	
	else
		DispBuf[5] &= ~0x02;

	WriteData(5, DispBuf[5]);
	DispOn();
}
void LightVolSub(BYTE on)
{
	if(on)
	{
		KeyLightTime = 2;
		DispBuf[5] |= 0x01;
	}
	else
		DispBuf[5] &= ~0x01;
	WriteData(5, DispBuf[5]);
	DispOn();	
}
void LightLast(BYTE on)
{
	if(on)
	{
		KeyLightTime = 2;
		DispBuf[4] |= 0x40;
	}
	else
		DispBuf[4] &= ~0x40;
	WriteData(4, DispBuf[4]);
	DispOn();	
}
void LightNext(BYTE on)
{
	if(on)
	{
		KeyLightTime = 2;
		DispBuf[4] |= 0x80;
	}	
	else
		DispBuf[4] &= ~0x80;
	WriteData(4, DispBuf[4]);
	DispOn();	
}
void LightPlayPause(BYTE on)
{
	if(on)
	{
		KeyLightTime = 2;
		DispBuf[4] |= 0x20;
	}	
	else
		DispBuf[4] &= ~0x20;
	WriteData(4, DispBuf[4]);
	DispOn();	
}
void LightAllClose(void)
{
	LightPlayPause(0);

	LightLast(0);
	LightNext(0);
	LightVolAdd(0);
	LightVolSub(0);

}

void Light2or5(BYTE on)
{
	if(on)
		DispBuf[4] |= 0x10;
	else
		DispBuf[4] &= ~0x10;
	WriteData(4, DispBuf[4]);
	DispOn();	
}
void LightUSB(BYTE on)
{
	if(on)
		DispBuf[4] |= 0x08;
	else
		DispBuf[4] &= ~0x08;
	WriteData(4, DispBuf[4]);
	DispOn();	
}
void LightCD(BYTE on)
{
	if(on)
		DispBuf[4] |= 0x04;
	else
		DispBuf[4] &= ~0x04;
	WriteData(4, DispBuf[4]);
	DispOn();	
}
void LightDVD(BYTE on)
{
	if(on)
		DispBuf[4] |= 0x02;
	else
		DispBuf[4] &= ~0x02;
	WriteData(4, DispBuf[4]);
	DispOn();	
}
void LightStdby(BYTE on)
{
	if(on)
		DispBuf[4] |= 0x01;
	else
		DispBuf[4] &= ~0x01;
	WriteData(4, DispBuf[4]);
	DispOn();	
}

void DispLed(BYTE led1, BYTE led2)
{
	DispBuf[2] = LEDDATA[led1];
	DispBuf[0] = LEDDATA[led2];
	WriteData(0, DispBuf[0]);
	WriteData(2, DispBuf[2]);
	DispOn();
}

void DispMainVol(BYTE vol)	//vol(0~60)
{
	BYTE temp,temp1;
	temp = vol/10;
	temp1 = vol%10;
	if(temp == 0)temp = 15;
	DispLed(temp,temp1);
	
}
void DispStandby(void)
{
	DispLed(14,14);
}
void DispOtherVol(BYTE vol)	//vol(0~10)
{
	if(vol>=5)DispLed(15,vol-5);
	else DispLed(14,5-vol);
}
void DispVolType(BYTE typ)
{
	if(typ == 0)	//main vol
	{
		DispMainVol(VolMain);
	}
	else if(typ == 1)	//front
	{
		DispLed(15,11);
	}
	else if(typ == 2)	//rear
	{
		DispLed(15,12);
	}
	else if(typ == 3)	//cen
	{
		DispLed(15,10);
	}
	else if(typ == 4)	//sub
	{
		DispLed(15,13);
	}	

}

void InitLCD( void )
{
	BYTE  i;
	SetMode();
	ClearLed();
}


⌨️ 快捷键说明

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