新聞中心

PIC16F877A例程---LCD1602

作者: 時(shí)間:2016-11-24 來源:網(wǎng)絡(luò) 收藏
#include //調(diào)用頭文件

#include

本文引用地址:http://m.butianyuan.cn/article/201611/321023.htm

__CONFIG(0x3F32); //芯片配置字

//__CONFIG(HS&UNPROTECT&PWRTEN&BORDIS&WDTDIS);//芯片配置字

//__CONFIG(0x3FFD&0x3FFF&0x3FF7&0x3FBF&0x3FFB);//芯片配置字

#define uchar unsigned char

#define uint unsigned int

#define ulint unsigned long int

#define LCD_DATA_PORT PORTD //定義LCD的D0-D7所在端口

#define LCD_DATA_POUT TRISD=0x00 //定義LCD數(shù)據(jù)端口為輸出

#define LCD_DATA_PIN TRISD=0xFF //定義LCD數(shù)據(jù)端口為輸入(在讀LCD狀態(tài)時(shí)用到)

#define LCD_Control_IN TRISB|=0XFF

#define LCD_Control_OUT TRISB&=0X00

#define LCD_EN_1 RB0=1

#define LCD_EN_0 RB0=0

//LCD讀寫控制引腳

#define LCD_RW_1 RB1=1

#define LCD_RW_0 RB1=0

//LCD指令或數(shù)據(jù)選擇引腳

#define LCD_RS_1 RB2=1

#define LCD_RS_0 RB2=0

void nus_delay(uint nus);

void nms_delay(uint nms);

void mcu_io_init(void);

void lcd_init(void);

void LCD_en_write(void);

void wait_LCD_Ready(void);

void set_LCD_xy(uchar x, uchar y );

void LCD_write_onechar(uchar COMM,uchar DAT);

void LCD_write_string(uchar X,uchar Y,uchar *string);

void main(void)

{

uchar START_DISPLAY1[]={"mcu.2000"};

uchar START_DISPLAY2[]={"TEL: 12345678901"};

mcu_io_init();

lcd_init();

nms_delay(10);

LCD_write_string(0,0,START_DISPLAY1);

LCD_write_string(0,1,START_DISPLAY2);

while(1);

}

void mcu_io_init(void)

{

LCD_DATA_PORT=0xff;

LCD_DATA_POUT; //LCD數(shù)據(jù)口設(shè)為輸出

LCD_EN_1;

LCD_RW_1;

LCD_RS_1;

LCD_Control_IN;

}

void lcd_init(void)

{

nms_delay(15);

LCD_DATA_POUT;

LCD_Control_OUT;

LCD_write_onechar(0x38,0);

nms_delay(1);

LCD_write_onechar(0x38,0);

nms_delay(1);

LCD_write_onechar(0x38,0);

nms_delay(1);

LCD_write_onechar(0x38,0);

LCD_write_onechar(0x08,0);

LCD_write_onechar(0x01,0);

LCD_write_onechar(0x06,0);

nms_delay(1);;

LCD_write_onechar(0x0C,0);

}

void LCD_en_write(void)

{

LCD_EN_1;

nus_delay(150); //E脈沖周期最小150ns

LCD_EN_0;

}


上一頁 1 2 下一頁

關(guān)鍵詞: PIC16F877ALCD160

評(píng)論


技術(shù)專區(qū)

關(guān)閉