Em tìm mãi mà không rõ lỗi ở đâu ? mà ko thấy hiển thị.
Nhờ các bác chỉ giùm
Em xin cám ơn
Mô phỏng : LCD-PIC.zip
Connections:
-------------------------------------
LCD | PIC |
-------------------------------------
Register Select -->RB2 |
Enable -->RB1 |
-------------------------------------
D4 -->RD0 |
D5 -->RD1 |
D6 -->RD2 |
D7 -->RD3 |
-------------------------------------
CLOCK: 20MHz crystal oscillator
Also, any other frequency <20MHz could be used. But we need to edit the below line:
?
1
#define _XTAL_FREQ 20e6
Code:
#include<pic.h>
#define _XTAL_FREQ 20e6
__CONFIG(0x3F3A);
#define RS RB2
#define EN RB1
#define databits PORTD
/*----------------PIC INITIALIZATION------------*/
void pic_init()
{
TRISB2 = 0;
TRISB1 = 0;
TRISD = 0;
}
/*-------------LCD FUNCTIONS BEGIN--------------*/
void LCD_STROBE(void)
{
EN = 1;
__delay_us(1);
EN = 0;
}
void data(unsigned char c)
{
RS = 1;
__delay_us(50);
databits = (c >> 4);
LCD_STROBE();
databits = (c);
LCD_STROBE();
}
void cmd(unsigned char c)
{
RS = 0;
__delay_us(50);
databits = (c >> 4);
LCD_STROBE();
databits = (c);
LCD_STROBE();
}
void clear(void)
{
cmd(0x01);
__delay_ms(2);
}
void lcd_init()
{
__delay_ms(15);
cmd(0x38);
__delay_ms(1);
cmd(0x38);
__delay_us(100);
cmd(0x38);
cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x0c); // Make cursorinvisible
clear(); // Clear screen
cmd(0x6); // Set entry Mode(auto increment of cursor)
}
void string(const char *q)
{
while (*q) {
data(*q++);
}
}
/*-------------LCD END--------------------*/
main()
{
__delay_ms(50);
pic_init();
lcd_init();
TRISC = 0;
while (1) {
cmd(0x80);
string("HELLO DTVN");
cmd(0xc0);
string("IT IS DTVN:-)");
}
}
#define _XTAL_FREQ 20e6
__CONFIG(0x3F3A);
#define RS RB2
#define EN RB1
#define databits PORTD
/*----------------PIC INITIALIZATION------------*/
void pic_init()
{
TRISB2 = 0;
TRISB1 = 0;
TRISD = 0;
}
/*-------------LCD FUNCTIONS BEGIN--------------*/
void LCD_STROBE(void)
{
EN = 1;
__delay_us(1);
EN = 0;
}
void data(unsigned char c)
{
RS = 1;
__delay_us(50);
databits = (c >> 4);
LCD_STROBE();
databits = (c);
LCD_STROBE();
}
void cmd(unsigned char c)
{
RS = 0;
__delay_us(50);
databits = (c >> 4);
LCD_STROBE();
databits = (c);
LCD_STROBE();
}
void clear(void)
{
cmd(0x01);
__delay_ms(2);
}
void lcd_init()
{
__delay_ms(15);
cmd(0x38);
__delay_ms(1);
cmd(0x38);
__delay_us(100);
cmd(0x38);
cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x28); // Function set (4-bit interface, 2 lines, 5*7Pixels)
cmd(0x0c); // Make cursorinvisible
clear(); // Clear screen
cmd(0x6); // Set entry Mode(auto increment of cursor)
}
void string(const char *q)
{
while (*q) {
data(*q++);
}
}
/*-------------LCD END--------------------*/
main()
{
__delay_ms(50);
pic_init();
lcd_init();
TRISC = 0;
while (1) {
cmd(0x80);
string("HELLO DTVN");
cmd(0xc0);
string("IT IS DTVN:-)");
}
}
Comment