:wow:سلام. این برنامه رو خودم نوشتم و در اختیار شما گذاشتم. این برنامه رو با برد خودم تست کردم و 100% جواب داد بدون مشکلی.
اول فایل lcd4bit.h:
ifndef _LCD4BIT_H
#define _LCD4BIT_H
void lcd_init();//function for frist setting lcd
void lcd_clear();//function for clear lcd
void lcd_gotoxy(unsigned char,unsigned char);//function for change position on lcd
void lcd_print(char *);//function for write data on lcd
void wrcmd(char str);//function for command
void wrdata(char str);//function for set data on lcd
void wr4bit(char str);//function for set command on lcd
#endif
دوم فایل lcd4bit.c:
#include "delay.h"
#include "lcd4bit.h"
//Control of pin's
#define e (1UL<<24)
#define rw (1UL<<25)
#define rs (1UL<<26)
#define pins_control (e|rw|rs)
//Data of pin's
#define db4 (1UL<<4)
#define db5 (1UL<<5)
#define db6 (1UL<<6)
#define db7 (1UL<<7)
#define out_data (db4|db5|db6|db7)
void lcd_init()
{
SCS=1;//for fast PORT0 and PORT1
FIO2DIR|=0x000000f0;//out pin0.4 until pin0.7 for lcd.
FIO0DIR|=pins_control;
/************Start program for configuration lcd 4 bit mode**********/
delay(15);//delay 15ms
wr4bit(0x03);//set interface 4 bit
delay(3);//delay 5ms
wr4bit(0x03);
delay(1);
wr4bit(0x03);
wr4bit(0x02);
wr4bit(0x02);
wr4bit(0x08);
wr4bit(0x28);//set font 5*8 matris
wr4bit(0x0c);//display on and crusor off
wr4bit(0x06);//finish configuration lcd 4 bit mode
}
/************************************************** ****************************/
void lcd_clear()
{
wr4bit(0x01);//clear display
wr4bit(0x80+0);//move crusor to home
}
/************************************************** ****************************/
void lcd_gotoxy(unsigned char x,unsigned char y)
{
switch(y)
{
case 0: wr4bit(0x80+x);break;//Change position 1-line
case 1: wr4bit(0xC0+x);break;//Change position 2-line
}
}
/************************************************** ****************************/
void wr4bit(char str)
{
wrcmd(str>>4);
wrcmd(str);
}
/************************************************** ****************************/
void lcd_print(char *s)
{
while(*s!=0)
{
wrdata(*s++);
}
}
/************************************************** ****************************/
void wrcmd(char str)
{
FIO0CLR|=rw;
FIO0CLR|=rs;
FIO2SET|=(str&0x0f)<<4;//4 shift for set for pin0.4 until p0.7
FIO0SET|=e;
delay(1);
FIO0CLR|=e;
delay(3);
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
}
/************************************************** ****************************/
void wrdata(char str)
{
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
FIO0SET|=rs;
FIO0SET|=e;
FIO2SET|=((str>>4)&0x0f)<<4;//4 shift for set for pin0.4 until p0.7
delay(1);
FIO0CLR|=e;
delay(3);
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
FIO0SET|=rs;
FIO2SET|=((str)&0x0f)<<4;//4 shift for set for pin0.4 until p0.7
FIO0SET|=e;
delay(1);
FIO0CLR|=e;
delay(3);
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
}
/*EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEEEEEEEEEEEEEEEEE*/
هر سوالی داشتید و یا جایی رو متوجه نشدید بگید. نظر هم بدید لطفاً :job:
اول فایل lcd4bit.h:
ifndef _LCD4BIT_H
#define _LCD4BIT_H
void lcd_init();//function for frist setting lcd
void lcd_clear();//function for clear lcd
void lcd_gotoxy(unsigned char,unsigned char);//function for change position on lcd
void lcd_print(char *);//function for write data on lcd
void wrcmd(char str);//function for command
void wrdata(char str);//function for set data on lcd
void wr4bit(char str);//function for set command on lcd
#endif
دوم فایل lcd4bit.c:
#include "delay.h"
#include "lcd4bit.h"
//Control of pin's
#define e (1UL<<24)
#define rw (1UL<<25)
#define rs (1UL<<26)
#define pins_control (e|rw|rs)
//Data of pin's
#define db4 (1UL<<4)
#define db5 (1UL<<5)
#define db6 (1UL<<6)
#define db7 (1UL<<7)
#define out_data (db4|db5|db6|db7)
void lcd_init()
{
SCS=1;//for fast PORT0 and PORT1
FIO2DIR|=0x000000f0;//out pin0.4 until pin0.7 for lcd.
FIO0DIR|=pins_control;
/************Start program for configuration lcd 4 bit mode**********/
delay(15);//delay 15ms
wr4bit(0x03);//set interface 4 bit
delay(3);//delay 5ms
wr4bit(0x03);
delay(1);
wr4bit(0x03);
wr4bit(0x02);
wr4bit(0x02);
wr4bit(0x08);
wr4bit(0x28);//set font 5*8 matris
wr4bit(0x0c);//display on and crusor off
wr4bit(0x06);//finish configuration lcd 4 bit mode
}
/************************************************** ****************************/
void lcd_clear()
{
wr4bit(0x01);//clear display
wr4bit(0x80+0);//move crusor to home
}
/************************************************** ****************************/
void lcd_gotoxy(unsigned char x,unsigned char y)
{
switch(y)
{
case 0: wr4bit(0x80+x);break;//Change position 1-line
case 1: wr4bit(0xC0+x);break;//Change position 2-line
}
}
/************************************************** ****************************/
void wr4bit(char str)
{
wrcmd(str>>4);
wrcmd(str);
}
/************************************************** ****************************/
void lcd_print(char *s)
{
while(*s!=0)
{
wrdata(*s++);
}
}
/************************************************** ****************************/
void wrcmd(char str)
{
FIO0CLR|=rw;
FIO0CLR|=rs;
FIO2SET|=(str&0x0f)<<4;//4 shift for set for pin0.4 until p0.7
FIO0SET|=e;
delay(1);
FIO0CLR|=e;
delay(3);
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
}
/************************************************** ****************************/
void wrdata(char str)
{
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
FIO0SET|=rs;
FIO0SET|=e;
FIO2SET|=((str>>4)&0x0f)<<4;//4 shift for set for pin0.4 until p0.7
delay(1);
FIO0CLR|=e;
delay(3);
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
FIO0SET|=rs;
FIO2SET|=((str)&0x0f)<<4;//4 shift for set for pin0.4 until p0.7
FIO0SET|=e;
delay(1);
FIO0CLR|=e;
delay(3);
FIO2CLR|=out_data;//clear pin0.0 until p0.7(data pin)
}
/*EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE EEEEEEEEEEEEEEEEEEEEEEEEEEE*/
هر سوالی داشتید و یا جایی رو متوجه نشدید بگید. نظر هم بدید لطفاً :job:
دیدگاه