📄 lcd_595.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 <pic16f946.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(5);
}
//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(15);
lcd_writecom(0x38); // 8 bit mode, 1/16 duty, 5x8 font lcd_writecom(0x0c); // display on, blink curson off
lcd_writecom(0x06); // entry mode}
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 datahh; unsigned char datal; unsigned char datah,datam; datahh = data / 1000 + 0x30; data = data % 1000; datah = data / 100 + 0x30; datam=(data%100)/10 + 0x30; datal = (data % 100) % 10 + 0x30; lcd_writedata(datahh); lcd_writedata(datah); lcd_writedata(datam); lcd_writedata(datal);} void lcd_putsf(unsigned char *ptr){ while(*ptr)
lcd_writedata(*ptr++);}
void lcd_putchar(unsigned char lcdchar) { lcd_writedata(lcdchar);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -