PIC Vietnam

Go Back   PIC Vietnam > Microchip PIC > Cơ bản về vi điều khiển và 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

Cơ bản về vi điều khiển và PIC Những bài hướng dẫn cơ bản nhất để làm quen với vi điều khiển PIC

 
 
Ðiều Chỉnh Xếp Bài
Prev Previous Post   Next Post Next
Old 14-08-2009, 11:46 PM   #1
nhanthienthan
Nhập môn đệ tử
 
Tham gia ngày: Jul 2009
Bài gửi: 6
:
Hỏi về cái error trong LCD ?

Chương trình viết chữ XIN CHAO đơn giản như thế này
Code:
#include <16f877A.h>
#fuses HS, NOLVP, NOWDT, NOPROTECT
#use   delay (clock=4000000) //Use built-in function: delay_ms() & delay_us()
#include "LCD_LIB_4BIT.c" 


VOID MAIN()

{
   LCD_INIT();
   LCD_PUTCHAR('X');
   DELAY_MS(1000);
   LCD_PUTCHAR('I');
   DELAY_MS(1000);
   LCD_PUTCHAR('N');
   DELAY_MS(1000);
   LCD_PUTCHAR(' ');
   DELAY_MS(1000);
   LCD_PUTCHAR('C');
   DELAY_MS(1000);
   LCD_PUTCHAR('H');
   DELAY_MS(1000);
   LCD_PUTCHAR('A');
   DELAY_MS(1000);
   LCD_PUTCHAR('O');
}

Còn đây là file LCD_LIB_4BIT.c

#include <stddef.h>
#define LCD_RS          PIN_B2
#define LCD_EN          PIN_B3
#define LCD_D4          PIN_B4
#define LCD_D5          PIN_B5
#define LCD_D6          PIN_B6
#define LCD_D7          PIN_B7
#define Line_1          0x80
#define Line_2          0xC0
#define Clear_Scr       0x01
#separate void LCD_Init ();// ham khoi tao LCD
#separate void LCD_SetPosition ( unsigned int cX );//Thiet lap vi tri con tro
#separate void LCD_PutChar ( unsigned int cX );// Ham viet1kitu/1chuoi len LCD
#separate void LCD_PutCmd ( unsigned int cX) ;// Ham gui lenh len LCD
#separate void LCD_PulseEnable ( void );// Xung kich hoat
#separate void LCD_SetData ( unsigned int cX );// Dat du lieu len chan Data

//khoi tao LCD**********************************************
#separate void LCD_Init ()
    {
    LCD_SetData ( 0x00 );
    delay_ms(20);       /*Cho cho lcd khoi tao */
    output_low ( LCD_RS );// che do gui lenh
    LCD_SetData ( 0x03 );   /* khoi tao che do 4 bit */
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_SetData ( 0x02 );   /* tao giao dien 4 bit */
    LCD_PulseEnable();      /* send dual nibbles hereafter, MSN first */
    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 */

    // Init for BarGraph

    }

#separate void LCD_SetPosition ( unsigned int cX )
    {
    /* this subroutine works specifically for 4-bit Port A */
    LCD_SetData ( swap ( cX ) | 0x08 );
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );
    LCD_PulseEnable();
    }

#separate void LCD_PutChar ( unsigned int cX )
    {
    /* this subroutine works specifically for 4-bit Port A */
        output_high ( LCD_RS );
        LCD_PutCmd( cX );
        output_low ( LCD_RS );
    }
#separate void LCD_PutCmd ( unsigned int cX )
    {
    LCD_SetData ( swap ( cX ) );     /* send high nibble */
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     /* send low nibble */
    LCD_PulseEnable();
    }
#separate void LCD_PulseEnable ( void )
    {
    output_high ( LCD_EN );
    delay_us ( 3 );         // was 10
    output_low ( LCD_EN );
    delay_ms ( 3 );         // was 5
    }
#separate void LCD_SetData ( unsigned int CX )
    {
    output_bit ( LCD_D4, CX & 0x01 );
    output_bit ( LCD_D5, CX & 0x02 );
    output_bit ( LCD_D6, CX & 0x04 );
    output_bit ( LCD_D7, CX & 0x08 );
    }
Viết trong CCS nhưng khi em nhấn f9 thì nó hiện lỗi này là sao ạ

***Eroor 128"LCD_LIB_4BIT.c"Line12(2,10): A#DEVICE require before this line

Mong các bro giúp đỡ, em mới học Pic nên chưa thành thạo lăm

thay đổi nội dung bởi: phamminhtuan, 15-08-2009 lúc 09:36 AM. Lý do: Định dạng code
nhanthienthan 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


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


Đượ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