中国安防论坛

 找回密码
 注册
查看: 2610|回复: 0

HD44780 液晶显示板的c语言驱动程序

[复制链接]

安防中学生

Rank: 2

积分
147
发表于 2004-11-1 23:14:24 | 显示全部楼层 |阅读模式
#define _LCD44780_C#include #include "main.h"#include "lcd44780.h"#include "1306spi.h"#include "delays.h"#include "serial.h"#include "25cxxspi.h"#include "e2data.h"void lcd_send_byte(unsigned char address, unsigned char chr) {unsigned char rVal;LCDPORTDIR = LCD_READ; // set data/con port directionslcd_select_reg(CMD_REG); ); // select command registerlcd_select_dir(READ_DIR); ); // set lcd to readdo { // wait until lcd is readylcd_set_clk_hi(); (); // toggle data clockrVal = lcd_get_data(); (); // read high nibble from data buslcd_set_clk_lo();delay_500ns();lcd_toggle_clk(); (); // toggle data clock} while(!!(rVal & (HINIBBLE(LCD_BUSY))));LCDPORTDIR = LCD_WRITE; // set data/con port directionslcd_select_reg(address); ); // select desired registerlcd_select_dir(WRITE_DIR); ); // set to writelcd_set_data(HINIBBLE(chr)); )); // send the high nibblelcd_toggle_clk(); (); // toggle data clocklcd_set_data(chr); ); // send the low nibblelcd_toggle_clk(); (); // toggle data clock}// Procedure to initialise the lcd for 4 bit operation.// This procedure implements the "Initialisation by instruction" as described for// Philips PCF2116Xvoid init_lcd() {unsigned char n;LCDPORTDIR = LCD_WRITE; // set data/con & enable port dir’nslcd_set_clk_lo(); (); // set data clock low (enable pin)lcd_select_reg(CMD_REG); ); // select command registerlcd_select_dir(WRITE_DIR); ); // set to writedelay_ms(15); ); // wait > 15ms Vdd rises above Vporlcd_set_data(HINIBBLE(LCD_FNSET | LCD_8BIT)); )); // put nibble on data busfor (n = 0; n < 3; ++n) { ) // set mode to 8 bit data 3 timeslcd_toggle_clk(); (); // toggle data clockdelay_ms(5); ); // 5ms delay}#ifdef LCD1LINES && (LCDNCHARS > 16)lcd_set_data(HINIBBLE(LCD_FNSET)); )); // set mode to 4 bit data and 1 linelcd_toggle_clk(); (); // toggle data clocklcd_send_byte(LCD_COMMAND, LCD_FNSET);#else#ifdef LCD4LINESlcd_set_data(HINIBBLE(LCD_FNSET | LCD_4LINE)); )); // set mode to 4 bit data and 4 lineslcd_toggle_clk(); (); // toggle data clocklcd_send_byte(LCD_COMMAND, LCD_FNSET | LCD_4LINE);#elselcd_set_data(HINIBBLE(LCD_FNSET | LCD_2LINE)); )); // set mode to 4 bit data and 2 lineslcd_toggle_clk(); (); // toggle data clocklcd_send_byte(LCD_COMMAND, LCD_FNSET | LCD_2LINE); ); // (applies to 16x1 also - odd one!!)#endif#endiflcd_send_byte(LCD_COMMAND, LCD_DISPON | LCD_DISP_ALL); ); // display onlcd_send_byte(LCD_COMMAND, LCD_CLR); ); // clear the displaylcd_send_byte(LCD_COMMAND, LCD_EMSET | LCD_EM_INC); ); // entry mode to incrementLCDPORTDIR = LCD_READ; // set data/con port dir’nslinenum = 0; // set line number to first linedisp_blank = false; // flag display as visiblecursor_on = false; // flag the cursor as off}// Moves the cursor to posline. The first character position is 0 and the first line is 0// If the cursor bit is set then a blinking cursor location is shown else the blinking// is removed. The procedure returns the old cursor status.// Definition of posline : bits 0..4 = character position in line (left = 0)// bits 5..6 = line number (top = 0)// bit 7 = cursor status (on = 1)// In the case of single line displays the lower 6 bits are the character position.unsigned char lcd_gotoxy(unsigned char posline) {unsigned char address, cstat;cstat = cursor_on;if(c_status.prt_to_lcd) {#ifdef LCD1LINES // this method is faster than using thelinenum = 0; // modulus operator but more verboseaddress = posline & 0x3f;#elselinepos = posline & 0x1f; // save the line char positionlinenum = (posline >> 5) & 3; // save the line number#ifdef LCD2LINESif(linenum > 1) linenum = 0; // 2 line display ?#elseif(linenum > 3) linenum = 0; // 4 line display ?#endif // LCD2LINESaddress = linepos;if(linenum == 1) address += STRT_LINE2; // set ram address to (pos,line)else if(linenum == 2) address += STRT_LINE3;else if(linenum == 3) address += STRT_LINE4;#endif // LCD1LINESlcd_send_byte(LCD_COMMAND, LCD_DD_SET | address);if(!!(posline & 0x80) != cursor_on) { ) // has the cursor status changed ?cursor_on = !!(p
不在競爭中變坏,就在沉默中變態
您需要登录后才可以回帖 登录 | 注册

本版积分规则

安豆网|Archiver|手机版|中国安防论坛 ( 粤ICP备09063021号 )

GMT+8, 2024-11-14 14:46 , Processed in 0.265042 second(s), 18 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表