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

📄 st7565p.c

📁 FFT转换程序
💻 C
字号:
/*!	\file ks0108.c \brief Graphic LCD driver for HD61202/KS0108	displays. */
//*****************************************************************************
//
// File	Name	: 'ks0108.c'
// Title		: Graphic LCD driver for HD61202/KS0108	displays
// Author		: Pascal Stang - Copyright (C) 2001-2003
// Date			: 10/19/2002
// Revised		: 5/5/2003
// Version		: 0.5
// Target MCU	: Atmel	AVR
// Editor Tabs	: 4
//
// NOTE: This code is currently	below version 1.0, and therefore is	considered
// to be lacking in	some functionality or documentation, or	may	not	be fully
// tested.	Nonetheless, you can expect	most functions to work.
//
// This	code is	distributed	under the GNU Public License
//		which can be found at http://www.gnu.org/licenses/gpl.txt
//
//*****************************************************************************

#include "global.h"
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/pgmspace.h>
#include "st7565p.h"


#define NOP asm volatile ("nop")

// global variables
u08	  ContrastLevel;	 //	for	contrast setting level 


/*************************************************************/
/**********************	LOCAL FUNCTIONS	**********************/
/*************************************************************/

void glcdInitHW(void)
{
	// initialize I/O ports
	
	// initialize LCD control lines	levels
	cbi(GLCD_PORT, GLCD_SI);
	cbi(GLCD_PORT, GLCD_SCL);
	cbi(GLCD_PORT, GLCD_A0);
	cbi(GLCD_PORT, GLCD_RESET);
	cbi(GLCD_PORT, GLCD_CS);
	// initialize LCD control port to output
	sbi(GLCD_DDR, GLCD_SI);
	sbi(GLCD_DDR, GLCD_SCL);
	sbi(GLCD_DDR, GLCD_A0);
	sbi(GLCD_DDR, GLCD_RESET);
	sbi(GLCD_DDR, GLCD_CS);

}


void glcdControlWrite(u08 data)
{
	u08	i;
	u08	Series,Temp;
	Series = data;

	sbi(GLCD_PORT, GLCD_SCL);
	NOP;
	cbi(GLCD_PORT, GLCD_A0);
	NOP;
	cbi(GLCD_PORT, GLCD_CS);
	NOP;
	for(i=8;i>0;i--)
	{
		Temp=Series	& 0x80;
		cbi(GLCD_PORT, GLCD_SCL);	//SCL=0
		NOP;
		if(Temp)
		{
			sbi(GLCD_PORT, GLCD_SI);//SI=1
			NOP;
		}
		else 
		{
			cbi(GLCD_PORT, GLCD_SI);//SI=0
			NOP;
		}
		sbi(GLCD_PORT, GLCD_SCL);	//SCL=1
		NOP;
		Series = Series	<< 1;  
	}
	sbi(GLCD_PORT, GLCD_CS);
	NOP;
}


void glcdDataWrite(u08 data)
{
	u08	i;
	u08	Series,Temp;
	Series = data;

	sbi(GLCD_PORT, GLCD_SCL);
	NOP;
	sbi(GLCD_PORT, GLCD_A0);
	NOP;
	cbi(GLCD_PORT, GLCD_CS);
	NOP;
	for(i=8;i>0;i--)
	{
		Temp=Series	& 0x80;
		cbi(GLCD_PORT, GLCD_SCL);	//SCL=0
		NOP;
		if(Temp)
		{
			sbi(GLCD_PORT, GLCD_SI);//SI=1
			NOP;
		}
		else 
		{
			cbi(GLCD_PORT, GLCD_SI);//SI=0
			NOP;
		}
		sbi(GLCD_PORT, GLCD_SCL);	//SCL=1
		NOP;	
		Series = Series	<< 1;  
	}
	sbi(GLCD_PORT, GLCD_CS);
	NOP;
}


void glcdSetXAddress(u08 xAddr)
{
	u08	Temp=xAddr;

	glcdControlWrite(GLCD_SET_COLUMN | (Temp>>4));
	glcdControlWrite(xAddr & 0x0F);
//	glcdControlWrite(GLCD_SET_COLUMN);
//	glcdControlWrite(0x00);
}

void glcdSetYAddress(u08 yAddr)
{

	glcdControlWrite(GLCD_SET_PAGE | yAddr);

}

/*************************************************************/
/********************* PUBLIC FUNCTIONS	**********************/
/*************************************************************/

void glcdInit()
{
	// initialize hardware
	glcdInitHW();
	// bring lcd out of	reset
	sbi(GLCD_PORT, GLCD_RESET);		// hardware	reset LCD module
	cbi(GLCD_PORT, GLCD_RESET);
	_delay_ms(5);
	sbi(GLCD_PORT, GLCD_RESET);
	_delay_ms(5);
	
	ContrastLevel=0x21;				// default Contrast	Level

	glcdControlWrite(0xae);			//set display off
	glcdControlWrite(0xa2);			//lcd bias select  1/9 BIAS
	glcdControlWrite(0xa0);			//ADC  select,NORMAL	  0-->127(a0,a1)
	glcdControlWrite(0xc8);			//com  select,NORMAL	  0-->63(c8,c0)

	glcdControlWrite(0x24);		 	//RESISTOR RATIO
	glcdControlWrite(0x81);			//ELECTRONIC	VOLUME mode	setting	100B 对比度命令
	glcdControlWrite(0x21);			//Set reference voltagel	register	 对比度数值
	glcdControlWrite(0x2f);			//power control(VB,VR,VF=1,1,1)
	_delay_ms(5);
	glcdControlWrite(0xaf);			//set display on
	glcdControlWrite(0xf8);			//set booster ratio
	glcdControlWrite(0x00);

	glcdStartLine(0);

}

void glcdClearScreen(void)
{

	u08	i, j;
	for(i=0;i<GLCD_YPIXELS;i++)
	{
		glcdControlWrite(0xb0 |	i);	// select page 0~7
		glcdControlWrite(0x10);		// start form column 4
		glcdControlWrite(0x00);		// (2byte command)
		for(j=0;j<GLCD_XPIXELS;j++)
		{
			glcdDataWrite(0x00);
		}
	}
}

void glcdStartLine(u08 start)
{
	glcdControlWrite(GLCD_START_LINE | start);
}

void glcdSetAddress(u08	x, u08 yLine)
{
	// set addresses
	glcdSetYAddress(yLine);
	glcdSetXAddress(x);
}

void glcdGotoChar(u08 line,	u08	col)
{
	glcdSetAddress(col*6, line);
}

//-----------------------------------
// Write a Screen
//-----------------------------------
void glcdWriteScreen(u08 *DisplayData)	// DisplayData should be 128x64/8 =	1Kbyte
{
	u08	TempData;
	u08	i, j;
//	glcdSetAddress(0, 0);
	for(i=0;i<GLCD_YPIXELS;i++)
	{
		glcdControlWrite(0xb0 |	i);	// select page 0~7
		glcdControlWrite(0x10);		// start form column 4
		glcdControlWrite(0x00);		// (2byte command)
		for(j=0;j<GLCD_XPIXELS;j++)
		{
			TempData=pgm_read_byte(DisplayData+(i*GLCD_XPIXELS)+j);
			glcdDataWrite(TempData);
		}
	}
}


⌨️ 快捷键说明

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