PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Các ngôn ngữ lập trình khác (CCS C, HT PIC,...)

Tài trợ cho PIC Vietnam
Trang chủ Đăng Kí Hỏi/Ðáp Thành Viên Lịch Bài Trong Ngày Vi điều khiển

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 16-12-2007, 11:54 PM   #11
Mr.Bi
Đệ tử 7 túi
 
Tham gia ngày: Jul 2007
Nơi Cư Ngụ: Đà Nẵng
Bài gửi: 188
:
Đây là code LCD4bit , mình chỉnh lại từ code của anh Linh
Code:
#define E            PIN_D0
#define RS          PIN_D1
#define RW          PIN_D2
#define LCD_D4      PIN_D4
#define LCD_D5      PIN_D5
#define LCD_D6      PIN_D6
#define LCD_D7      PIN_D7

void LCD_Init ( void );                    // ham khoi tao LCD
void LCD_SetPosition ( unsigned int data );//Thiet lap vi tri con tro
void LCD_PutChar ( unsigned int data );    // Ham viet1kitu/1chuoi len LCD
void LCD_PutCmd ( unsigned int data ) ;    // Ham gui lenh len LCD
void send_to_LCD( unsigned int data); 

void LCD_Init ( void )
{
    delay_ms(200); // thoi gian de LCD khoi dong

    output_low(RW);        // RW = 0
    output_low(RS);        // che do gui lenh

    send_to_LCD( 0x00 );
    output_high ( E ); output_low ( E ); delay_ms ( 10 );


    send_to_LCD( 0x03 );  /* init with specific nibbles to start 4-bit mode */
    output_high ( E ); output_low ( E ); delay_ms ( 3 ); // tao xung tren chan E
    output_high ( E ); output_low ( E ); delay_ms ( 3 );
    output_high ( E ); output_low ( E ); delay_ms ( 3 );

    send_to_LCD( 0x02 );  /* set 4-bit interface */
    output_high ( E ); output_low ( E ); delay_ms ( 3 ); // tao xung tren chan E


    LCD_PutCmd ( 0x2C );    /* function set (all lines, 5x7 characters) */
    LCD_PutCmd ( 0x0C);    /* display ON, cursor off, no blink */
    LCD_PutCmd ( 0x06 );    /* entry mode set, increment & scroll left */
    LCD_PutCmd ( 0x01 );    /* clear display */
}

void LCD_SetPosition ( unsigned int data )
{

    send_to_LCD( swap ( data ) | 0x08 );
    output_high ( E ); output_low ( E ); delay_ms ( 3 ); // tao xung tren chan E

    send_to_LCD( swap ( data ) );
    output_high ( E ); output_low ( E ); delay_ms ( 3 ); // tao xung tren chan E

}

void LCD_PutChar ( unsigned int data )
{
    output_high( RS ); //RS = 1
    output_low ( RW ); //RW = 0

    send_to_LCD( swap ( data ) );                        // gui 4 bit cao
    output_high ( E ); output_low ( E ); delay_ms ( 3 ); // tao xung tren chan E

    send_to_LCD( swap ( data ) );                        //gui 4 bit thap
    output_high ( E ); output_low ( E ); delay_ms ( 3 ); // tao xung tren chan E

}

void LCD_PutCmd ( unsigned int data )
{
    output_low(RS); // RS = 0
    output_low(RW); // RW = 0

    send_to_LCD( swap(data) );    // gui 4 bit cao
    output_high (E); output_low (E); delay_ms (3);

    send_to_LCD( swap(data) );    // gui 4 bit thap
    output_high (E); output_low (E); delay_ms ( 3 );
}


void send_to_LCD( unsigned int data )
{
    output_bit ( LCD_D4, data & 0x01 );
    output_bit ( LCD_D5, data & 0x02 );
    output_bit ( LCD_D6, data & 0x04 );
    output_bit ( LCD_D7, data & 0x08 );
}
bạn thick xuất PORT nào thì cứ thế mà chỉnh lại
Mr.Bi vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn
 


Quyền Sử Dụng Ở Diễn Ðàn
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is Mở
Smilies đang Mở
[IMG] đang Mở
HTML đang Tắt

Chuyển đến

Similar Threads
Ðề tài Người gửi Chuyên mục Trả lời Bài mới
dsPIC Tutorial 3-Đọc ngõ vào và giao tiếp LCD namqn dsPIC - Bộ điều khiển tín hiệu số 16-bit 92 19-02-2017 11:15 PM
dsPIC Tutorial 2-Các kỹ thuật cơ bản namqn dsPIC - Bộ điều khiển tín hiệu số 16-bit 33 17-10-2013 11:09 PM
dsPIC Tutorial 4-Module UART và I2C namqn dsPIC - Bộ điều khiển tín hiệu số 16-bit 76 09-05-2012 10:55 AM
Tutorial LCD cua Nigel??????? spirit Cơ bản về vi điều khiển và PIC 16 16-03-2009 05:32 PM
tutorial hay cho newbie FUD84 Cơ bản về vi điều khiển và PIC 2 04-12-2005 02:29 AM


Múi giờ GMT. Hiện tại là 11:16 AM.


Được sáng lập bởi Đoàn Hiệp
Powered by vBulletin®
Page copy protected against web site content infringement by Copyscape
Copyright © PIC Vietnam