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

📄 3510i.c

📁 ARM7 + DS18B20的驱动程序
💻 C
字号:
#include "..\inc\44b.h"
#include "..\inc\44blib.h"
#include "..\inc\common.h"
#include "..\inc\3510i.h"
#include "..\inc\aschz.h"
#include <stdlib.h>
#include <math.h>


unsigned int BGColor;
unsigned int PenColor;
unsigned char  InterfacePixelFormat;
void LCD_Delay(void)
{
	unsigned int i;
	for(i = 0; i < 32768; i ++)
		Delayus(1);
}

void LCD_Reset(void)
{
	bitclr(LCD_RST_PORT, LCD_RST);		//set RST = L
	LCD_Delay();
	bitset(LCD_RST_PORT, LCD_RST);		//set RST = H
	LCD_Delay();
}

void LCD_SendCommand(unsigned char cmd)
{
//	bitset(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 1
	bitclr(LCD_CS_PORT, LCD_CS);		//set CS = L
	bitclr(LCD_SCL_PORT, LCD_SCL);		//set SCK = L
	bitclr(LCD_SIO_PORT, LCD_SIO);		//send 0, for command
	bitset(LCD_SCL_PORT, LCD_SCL);		//set SCK = H, latch data
//Bit 0(MSB)
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x80)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 1
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x40)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 2
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x20)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 3
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x10)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 4
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x08)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 5
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x04)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 6
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x02)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 7(LSB)
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(cmd & 0x01)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//done
}

void LCD_SendData(unsigned char data)
{
//	bitset(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 1
	bitclr(LCD_CS_PORT, LCD_CS);		//set CS = L
	bitclr(LCD_SCL_PORT, LCD_SCL);		//set SCK = L
	bitset(LCD_SIO_PORT, LCD_SIO);		//send 1, for command
	bitset(LCD_SCL_PORT, LCD_SCL);		//set SCK = H, latch data
//Bit 0(MSB)
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x80)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 1
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x40)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 2
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x20)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 3
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x10)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 4
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x08)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 5
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x04)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 6
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x02)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//Bit 7(LSB)
	bitclr(LCD_SCL_PORT, LCD_SCL);
	if(data & 0x01)
		bitset(LCD_SIO_PORT, LCD_SIO);
	else
		bitclr(LCD_SIO_PORT, LCD_SIO);
	bitset(LCD_SCL_PORT, LCD_SCL);
//done
}
/*
void LCD_ReadDummy(void)
{
	//bitclr(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 0
	bitset(LCD_SIO_PORT, LCD_SIO);	
	bitclr(LCD_CS_PORT, LCD_CS);		//set CS = L
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
}

unsigned char LCD_ReadData(void)
{
	unsigned char r = 0;
	//bitclr(LCD_SIO_DDR, LCD_SIO);		//set SDI.DDR = 0
	bitset(LCD_SIO_PORT, LCD_SIO);	
	bitclr(LCD_CS_PORT, LCD_CS);		//set CS = L
//Bit 0(MSB)
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x80;
	else
		r &= ~0x80;
//Bit 1
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x40;
	else
		r &= ~0x40;
//Bit 2
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x20;
	else
		r &= ~0x20;
//Bit 3
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x10;
	else
		r &= ~0x10;
//Bit 4
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x08;
	else
		r &= ~0x08;
//Bit 5
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x04;
	else
		r &= ~0x04;
//Bit 6
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x02;
	else
		r &= ~0x02;
//Bit 7(LSB)
	bitclr(LCD_SCL_PORT, LCD_SCL);
	bitset(LCD_SCL_PORT, LCD_SCL);
	if(bit_is_set(LCD_SIO_PIN, LCD_SIO))
		r |= 0x01;
	else
		r &= ~0x01;
//done
	return r;
}
*/
void LCD_Initialize(void)
{
	unsigned char i;

	bitset(LCD_RST_PORT, LCD_RST);		//set RST = H
	//bitset(LCD_RST_DDR, LCD_RST);	//set RST.DDR = 1
	bitset(LCD_CS_PORT, LCD_CS);		//set CS = H
//	bitset(LCD_CS_DDR, LCD_CS);	//set CS.DDR = 1
	bitclr(LCD_SIO_PORT, LCD_SIO);		//set SDI = L
	//bitclr(LCD_SIO_DDR, LCD_SIO);	//set SDI.DDR = 0
	bitset(LCD_SCL_PORT, LCD_SCL);		//set SCK = H
	//bitset(LCD_SCL_DDR, LCD_SCL);	//set SCK.DDR = 1

	LCD_Reset();

	LCD_SendCommand(0x01);		//software reset
	LCD_DataOver();
	LCD_Delay();

	LCD_SendCommand(0xc6);		//initial escape
	LCD_DataOver();

	LCD_SendCommand(0xb9);		//refresh set
	LCD_SendData(0x00);
	LCD_DataOver();

	LCD_SendCommand(0xb6);		//display control
	LCD_SendData(0x80);
	LCD_SendData(0x7f);
	LCD_SendData(0x14);
	LCD_SendData(84);
	LCD_SendData(69);
	LCD_SendData(82);
	LCD_SendData(67);
	LCD_DataOver();

	LCD_SendCommand(0xb3);		//gray scale position set
	LCD_SendData(1);
	LCD_SendData(2);
	LCD_SendData(4);
	LCD_SendData(8);
	LCD_SendData(16);
	LCD_SendData(30);
	LCD_SendData(40);
	LCD_SendData(50);
	LCD_SendData(60);
	LCD_SendData(70);
	LCD_SendData(80);
	LCD_SendData(90);
	LCD_SendData(100);
	LCD_SendData(110);
	LCD_SendData(127);
	LCD_DataOver();

	LCD_SendCommand(0xb5);		//gamma curve set
	LCD_SendData(0x01);
	LCD_DataOver();

	LCD_SendCommand(0xbd);		//common driver output select
	LCD_SendData(0x00);
	LCD_DataOver();

	LCD_SendCommand(0xbe);		//power control
	LCD_SendData(0x04);
	LCD_DataOver();

	LCD_SendCommand(0x11);		//sleep out
	LCD_DataOver();
	
	LCD_SendCommand(0xba);		//voltage control
	LCD_SendData(127);
	LCD_SendData(3);
	LCD_DataOver();

	LCD_SendCommand(0xb7);		//temperature gradient set
	for(i = 0; i < 14; i ++)
		LCD_SendData(0x00);
	LCD_DataOver();

	LCD_SendCommand(0x29);		//display ON
	LCD_DataOver();

	LCD_SendCommand(0x03);		//booster voltage ON
	LCD_DataOver();
	LCD_Delay();

	LCD_SendCommand(0x20);		//display inversion OFF
	LCD_DataOver();
	
	LCD_SendCommand(0x3a);		//interface pixel format
	LCD_SendData(0x02);
	LCD_DataOver();
	InterfacePixelFormat = 0;
	LCD_SendCommand(0x2d);		//colour set
//red
	LCD_SendData(0x00);
	LCD_SendData(0x02);
	LCD_SendData(0x03);
	LCD_SendData(0x04);
	LCD_SendData(0x05);
	LCD_SendData(0x06);
	LCD_SendData(0x08);
//green
	LCD_SendData(0x0f);
	LCD_SendData(0x00);
	LCD_SendData(0x02);
	LCD_SendData(0x03);
	LCD_SendData(0x04);
	LCD_SendData(0x05);
	LCD_SendData(0x06);
	LCD_SendData(0x08);
	LCD_SendData(0x0f);
//blue
	LCD_SendData(0x00);
	LCD_SendData(0x03);
	LCD_SendData(0x06);
	LCD_SendData(0x0f);
	LCD_DataOver();

	LCD_SendCommand(0x25);		//write contrast
	LCD_SendData(71);
	LCD_DataOver();
	
	BGColor = 0x00;
	PenColor = 0xff;
}

void LCD_InterfacePixelFormat(unsigned char color)   //interface pixel format
{
  	LCD_SendCommand(0x3a);
  	if(color)		
	{
		LCD_SendData(0x03);   //4096color
		InterfacePixelFormat = 1;
	}
	else
	{
		LCD_SendData(0x02);   //256color
		InterfacePixelFormat = 0;	
	}
	LCD_DataOver();
}

void LCD_ClearScreen(unsigned char color)
{
	unsigned char x, y;
	if (color == 1 && InterfacePixelFormat == 0)
	{
		LCD_InterfacePixelFormat(1);
	}
	else
	{
		if (color == 0 && InterfacePixelFormat == 1)
		{
			LCD_InterfacePixelFormat(0);
		}
	}
	LCD_SendCommand(0x2a);		//column address set
	LCD_SendData(0);
	LCD_SendData(97);
	LCD_DataOver();

	LCD_SendCommand(0x2b);		//page address set
	LCD_SendData(0);
	LCD_SendData(66);
	LCD_DataOver();
	
	LCD_SendCommand(0x2c);		//memory write
	if (color)
	{
		for(y = 0; y < 67; y ++)
		{
			for(x = 0; x < 98; x += 2)
			{
				LCD_SendData(BGColor >> 4);
				LCD_SendData(((BGColor & 0x00f) << 4) | (BGColor >> 8));
				LCD_SendData(BGColor & 0x0ff);
			}
		}
	}	
	else
	{
		for(y = 0; y < 67; y ++)
		{
			for(x = 0; x < 98; x ++)
			{
				LCD_SendData(BGColor);
			}
		}
	}
	LCD_DataOver();
}
/*
void LCD_ReadPixel(unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, unsigned char *b)
{
	unsigned char x, y;
	LCD_SendCommand(0x2a);		//column address set
	LCD_SendData(x1);
	LCD_SendData(x2);
	LCD_DataOver();

	LCD_SendCommand(0x2b);		//page address set
	LCD_SendData(y1);
	LCD_SendData(y2);
	LCD_DataOver();
	
	LCD_SendCommand(0x2e);		//RAM data read
	
	for(y = y1; y <= y2; y ++)
		for(x = x1; x <= x2; x ++)
		{
			LCD_ReadDummy();
			*(b ++) = LCD_ReadData();
		}
	LCD_DataOver();

	LCD_SendCommand(0x00);		//NOP
	LCD_SendData(0x00);
	LCD_DataOver();
}*/
void LCD_WriteString(unsigned char x, unsigned char y,unsigned char *n,unsigned char len,unsigned char backcolor,unsigned char stringcolor)
{
	unsigned char ListLength;
	unsigned char ii,i,dd,kk,aa;

	ListLength=len;
	for (kk=0; kk<ListLength; kk++)
	{
		LCD_SendCommand(0x2a);//column address set
	    if((x + 7) > 97)
	    {
	    	x = 0;
	   	}
	    LCD_SendData(x);
		LCD_SendData(x+7);
		
	 	LCD_DataOver(); 

	    LCD_SendCommand(0x2B);//page address set
	    
	    LCD_SendData(y);
		LCD_SendData(y+15);
	 	LCD_DataOver(); 	
		
		LCD_SendCommand(0x2C);		//memory write

		for (i=0;i<16;i++)
		{
	    	aa=n[kk];
	    	dd=asc[i + (n[kk] - 32) * 16];
        	for(ii=0;ii<8;ii++)
            {
                if(dd & 0x80)
                {
                	LCD_SendData(stringcolor);
               	}   
             	else
				{
					LCD_SendData(backcolor);
				}
            	dd = dd << 1;
			}
		}	
		x=x+8;
	}
	LCD_DataOver();
}

void LCD_WritePixel(unsigned char color, unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2, const unsigned char *b)
{
	unsigned char x, y;
	if ((color == 1) && (InterfacePixelFormat == 0))
	{
		LCD_InterfacePixelFormat(1);
	}
	else
	{
		if ((color == 0) && (InterfacePixelFormat == 1))
		{
			LCD_InterfacePixelFormat(0);
		}
	}
	LCD_SendCommand(0x2a);		//column address set
	LCD_SendData(x1);
	LCD_SendData(x2);
	LCD_DataOver();

	LCD_SendCommand(0x2b);		//page address set
	LCD_SendData(y1);
	LCD_SendData(y2);
	LCD_DataOver();
	
	LCD_SendCommand(0x2c);		//memory write
	if(color)
	{
		for(y = y1; y <= y2; y ++)
		{
			for(x = x1; x <= x2; x +=2)
			{
				LCD_SendData(*(b ++));
				LCD_SendData(*(b ++));
				LCD_SendData(*(b ++));
			}
		}
	}
	else
	{
		for(y = y1; y <= y2; y ++)
		for(x = x1; x <= x2; x ++)
			LCD_SendData(*(b ++));
	}
	LCD_DataOver();
}

void LCD_DrawPoint(unsigned char color, unsigned char x, unsigned char y)
{
	if ((color == 1) && (InterfacePixelFormat == 0))
	{
		LCD_InterfacePixelFormat(1);
	}
	else
	{
		if ((color == 0) && (InterfacePixelFormat == 1))
		{
			LCD_InterfacePixelFormat(0);
		}
	}
	LCD_SendCommand(0x2a);		//column address set
	LCD_SendData(x);
	LCD_SendData(x);
	LCD_DataOver();

	LCD_SendCommand(0x2b);		//page address set
	LCD_SendData(y);
	LCD_SendData(y);
	LCD_DataOver();
	
	LCD_SendCommand(0x2c);		//memory write
	if(color)
	{
		LCD_SendData(PenColor >> 4);
		LCD_SendData(((PenColor & 0x00f) << 4) | (PenColor >> 8));
		LCD_SendData(PenColor & 0x0ff);
	}
	else
	{
		LCD_SendData(PenColor);
	}
	LCD_DataOver();
}

void LCD_DrawLine(unsigned char color, unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
{
	unsigned char x, y, t;
	if((x1 == x2) && (y1 == y2))
		LCD_DrawPoint(color, x1, y1);
	else if(abs(y2 - y1) > abs(x2 - x1))
	{
		if(y1 > y2)
		{
			t = y1;
			y1 = y2;
			y2 = t;
			t = x1;
			x1 = x2;
			x2 = t;
		}
		for(y = y1; y <= y2; y ++)
		{
			x = (y - y1) * (x2 - x1) / (y2 - y1) + x1;
			LCD_DrawPoint(color, x, y);
		}
	}
	else
	{
		if(x1 > x2)
		{
			t = y1;
			y1 = y2;
			y2 = t;
			t = x1;
			x1 = x2;
			x2 = t;
		}
		for(x = x1; x <= x2; x ++)
		{
			y = (x - x1) * (y2 - y1) / (x2 - x1) + y1;
			LCD_DrawPoint(color, x, y);
		}
	}
}

void LCD_DrawRectangle(unsigned char color, unsigned char x1, unsigned char y1, unsigned char x2, unsigned char y2)
{
	LCD_DrawLine(color, x1, y1, x2, y1);
	LCD_DrawLine(color, x2, y1, x2, y2);
	LCD_DrawLine(color, x2, y2, x1, y2);
	LCD_DrawLine(color, x1, y2, x1, y1);
}

void LCD_DrawImage(unsigned char color,const unsigned char *p)
{ 
	LCD_WritePixel(color, 0, 0, 97, 66, p);
}

⌨️ 快捷键说明

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