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

📄 lcd_595.c

📁 模拟串口通讯
💻 C
字号:
////////////////////////////////////////////////////////////////////////////
////                         LCD1602_595.C                		        ////
////            Driver for common 2x16 LCD modules                      ////
////                                                                    ////
////  lcd_init()   Must be called before any other function.            ////
////                                                                    ////
////  lcd_putchar(c)  Will display c on the next position of the LCD.   ////
////                    												////
////  lcd_gotoxy(x,y) Set write position on LCD (upper left is 0,0)     ////
////                                                                    ////
////  lcd_clear()	Will clear the display and make the cursion home    ////
////  																	////
////  lcd_putsf(str)	Will display a string on LCD                    ////
//// 																	////
////  lcd_dispdata(data) Will display data on the next position of LCD  ////
////																	////
////////////////////////////////////////////////////////////////////////////
////   MODIFY BY :	PARKENING 											////
////   TIME		 :	2007.08.24                                          ////
////////////////////////////////////////////////////////////////////////////

//// As defined in the following structure the pin connection is as follows:
//// 	RF5		SRCLK
////	RF6		RCLK
////	RF7		SER
/////////////////////////////////////////////////////////////////////////////


#include <pic.h>
#include "delay.h"
#include "lcd_595.h"



//Send lcd data and lcd command to HC595
void SEND_TO_HC595(unsigned char data,unsigned char console)
{
	unsigned char tmp;
	unsigned char i;
	
	SHCLK_DIR = 0;
	STCLK_DIR = 0;
	DS_DIR = 0;
	SHCLK = 1;
	STCLK = 1;
	DS = 1;
	
	tmp = console;
	for(i=0;i<8;++i)
	{
		if((tmp&0x80)==0x80)
		{
			DS = 1;
		}
		else
		{
			DS = 0;
		}
		SHCLK = 0;
		SHCLK = 1;
		tmp = tmp << 1;
	}

	tmp = data;
	for(i=0;i<8;++i)
	{
		if((tmp&0x80)==0x80)
		{
			DS = 1;
		}
		else
		{
			DS = 0;
		}
		SHCLK = 0;
		SHCLK = 1;
		tmp = tmp << 1;
	}
	
	STCLK = 0;
	STCLK = 1;
	SHCLK = 1;
	DS = 1;
}


//Take a delay insteading of checkbusy
void lcd_checkbusy(void)
{
//	DelayMs(1);
	DelayUs(50);
}


//Write command byte to LCD
void lcd_writecom(unsigned char combyte)
{
	unsigned char lcd_com;
	unsigned char lcd_console;
	lcd_checkbusy();
	lcd_com = combyte;
	lcd_console = 0x00;	//	RS	RW	EN
						//	0	0	0

	SEND_TO_HC595(lcd_com,lcd_console);
	lcd_console = 0x02;	//	RS	RW	EN
						//	0	0	1

	SEND_TO_HC595(lcd_com,lcd_console);
	lcd_console = 0x00;	//	RS	RW	EN
						//	0	0	0

	SEND_TO_HC595(lcd_com,lcd_console);
}


//Write data to LCD
void lcd_writedata(unsigned char data)
{
	unsigned char lcd_data;
	unsigned char lcd_console;
	lcd_checkbusy();
	lcd_data = data;
	lcd_console = 0x08;	//	RS	RW	EN
						//	1	0	0

	SEND_TO_HC595(lcd_data,lcd_console);
	lcd_console = 0x0A;	//	RS	RW	EN
						//	1	0	1

	SEND_TO_HC595(lcd_data,lcd_console);
	lcd_console = 0x08;	//	RS	RW	EN
						//	1	0	0

	SEND_TO_HC595(lcd_data,lcd_console);
}


//Initialize the LCD module
void lcd_initial(void){ 
	DelayMs(20);
	lcd_writecom(0x38);	// 8 bit mode, 1/16 duty, 5x8 font	lcd_writecom(0x0c); // display on, blink curson off
	lcd_writecom(0x06);	// entry mode
	BL_DIR = 0;			// Backlight port initialize
	BL = 1;				// Turn on Backlight}  



void lcd_clear(void){ 
	lcd_writecom(0x01);	//display clear
	DelayMs(2);	lcd_writecom(0x02);	//cursion home
	DelayMs(2);}void lcd_gotoxy(unsigned char x, unsigned char y){   unsigned char base_y[2]={0x80, 0xc0};     lcd_checkbusy();    lcd_writecom(base_y[y] + x); }void lcd_dispdata(unsigned int data) {
   unsigned char datahhh;   unsigned char datahh;   unsigned char datal;   unsigned char datah,datam;
   datahhh = data / 10000 + 0x30;
   data = data%10000;   datahh = data / 1000 + 0x30;   data = data % 1000;   datah = data / 100 + 0x30;   datam=(data%100)/10 + 0x30;   datal = (data % 100) % 10 + 0x30;
   lcd_writedata(datahhh);   lcd_writedata(datahh);   lcd_writedata(datah);   lcd_writedata(datam);   lcd_writedata(datal);} 


/*void lcd_displongdata(unsigned long data)
{
	unsigned char bit0;
	unsigned char bit1;
	unsigned char bit2;
	unsigned char bit3;
	unsigned char bit4; 
	unsigned char bit5;
	unsigned char bit6;
	unsigned char bit7;
	unsigned char bit8;
	unsigned char bit9;

	bit9 = data/1000000000 + 0x30;
	data %= 1000000000;
	bit8 = data/100000000 + 0x30;
	data %= 100000000;
	bit7 = data/10000000 + 0x30;
	data %= 10000000;
	bit6 = data/1000000 + 0x30;
	data %= 1000000;
	bit5 = data/100000 + 0x30;
	data %= 100000;
	bit4 = data/10000 + 0x30;
	data %= 10000;
	bit3 = data/1000 + 0x30;
	data %= 1000;
	bit2 = data/100 + 0x30;
	data %= 100;
	bit1 = data/10 + 0x30;
	bit0 = data%10 + 0x30;
	lcd_writedata(bit9);
	lcd_writedata(bit8);
	lcd_writedata(bit7);
	lcd_writedata(bit6);
	lcd_writedata(bit5);
	lcd_writedata(bit4);
	lcd_writedata(bit3);
	lcd_writedata(bit2);
	lcd_writedata(bit1);
	lcd_writedata(bit0);
}*/void lcd_putstr(const unsigned char *ptr){ 	while(*ptr)
		lcd_writedata(*ptr++);}


void lcd_putchar(unsigned char lcdchar) {	lcd_writedata(lcdchar);}  
/*
void lcd_puts(unsigned char str[])
{ 
  unsigned char i; 
  for (i=0; i<strlen(str); i++)
    {
      lcd_writedata(str[i]);
    }  
}*/

void lcd_disphex(unsigned char data) 
{
	unsigned char datal,datam;
	datam=data/0x10+0x30;
	datal=data%0x10+0x30;
	if(datam>0x39)
	{
		datam+=0x07;
	}
	if(datal>0x39)
	{
		datal+=0x07;
	}
	lcd_putchar(datam);
	lcd_putchar(datal);
}  


void lcd_dispdd(unsigned char data)
{
	unsigned char datah,datal;
	datah=data/10+0x30;
	datal=data%10+0x30;
	lcd_writedata(datah);
	lcd_writedata(datal);
}


⌨️ 快捷键说明

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