View Single Post
Old 19-03-2009, 04:22 PM   #20
Vinh3i
Đệ tử 1 túi
 
Tham gia ngày: Jan 2007
Bài gửi: 25
:
tôi viết code để test lcd như sau:
Code:
#include <16F877A.h>


#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOPUT                    //No Power Up Timer
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD                    //No EE protection
#FUSES NOWRT                    //Program memory not write protected

#use delay(clock=10000000)

/* LCD STUFF */
#define LCD_D0  PIN_B1
#define LCD_D1  PIN_B2
#define LCD_D2  PIN_B3
#define LCD_D3  PIN_B4

#define LCD_EN  PIN_A1
#define LCD_RS  PIN_A2

#define FIRST_LINE  0x00
#define SECOND_LINE 0x40
#define CLEAR_DISP  0x01

#int_EXT
void  EXT_isr(void) 
{

}

#int_TBE
void  TBE_isr(void) 
{

}

#int_RDA
void  RDA_isr(void) 
{

}


void LCD_Init ( void );
void LCD_SetPosition ( unsigned int cX );
void LCD_PutChar ( unsigned int cX );
void LCD_PutCmd ( unsigned int cX );
void LCD_PulseEnable ( void );
void LCD_SetData ( unsigned int cX );


void main()
{
Output_high(PIN_B5);
Output_high(PIN_B5);
LCD_Init();
LCD_PutChar("O");
LCD_PutChar("K");

}
/******************************************************************************/

void LCD_Init ( void )
    {
    LCD_SetData ( 0x00 );
    delay_ms ( 200 );       /* wait enough time after Vdd rise */
    output_low ( LCD_RS );
    LCD_SetData ( 0x03 );   /* init with specific nibbles to start 4-bit mode */
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_PulseEnable();
    LCD_SetData ( 0x02 );   /* set 4-bit interface */
    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 ( 0x01 );    /* clear display */
    LCD_PutCmd ( 0x06 );    /* entry mode set, increment */
    }

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();
    }

void LCD_PutChar ( unsigned int cX )
    {
    /* this subroutine works specifically for 4-bit Port A */
    output_high ( LCD_RS );
    LCD_SetData ( swap ( cX ) );     /* send high nibble */
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     /* send low nibble */
    LCD_PulseEnable();
    output_low ( LCD_RS );
    }

void LCD_PutCmd ( unsigned int cX )
    {
    /* this subroutine works specifically for 4-bit Port A */
    LCD_SetData ( swap ( cX ) );     /* send high nibble */
    LCD_PulseEnable();
    LCD_SetData ( swap ( cX ) );     /* send low nibble */
    LCD_PulseEnable();
    }

void LCD_PulseEnable ( void )
    {
    output_high ( LCD_EN );
    delay_us ( 10 );
    output_low ( LCD_EN );
    delay_ms ( 5 );
    }

void LCD_SetData ( unsigned int cX )
    {
    output_bit ( LCD_D0, cX & 0x01 );
    output_bit ( LCD_D1, cX & 0x02 );
    output_bit ( LCD_D2, cX & 0x04 );
    output_bit ( LCD_D3, cX & 0x08 );
    }
dùng CCS để build và nạp vào PIC trên
Tuy nhiên, mô phỏng với proteus thì chạy tốtt, còn nạp lên mạch thì LCD chỉ hiện một dòng đen xì.
(với code trên, tôi đã nối châm RW của LCD với đất)
kiểm tra điện áp trên lcd thì có
Trích:
D0,1,2,3,4,5,7 = 5v
D6 = 0V
rs,e,rw = 0v
chỉnh điện áp chân VEE vẫn thấy thay đổi đậm nhạt của dòng đen xì trên
Help me!!!!

thay đổi nội dung bởi: Vinh3i, 19-03-2009 lúc 04:30 PM.
Vinh3i vẫn chưa có mặt trong diễn đàn   Trả Lời Với Trích Dẫn