CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PIC16F877A CODE LCD

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ewerebellatok



Joined: 14 Dec 2008
Posts: 1

View user's profile Send private message

PIC16F877A CODE LCD
PostPosted: Sun Dec 14, 2008 11:13 am     Reply with quote

Hello experts,
I have problem to config this program. I used mplab to write this c code
and used CCS to compile the code. But how can I set the high speed
oscillator so that I can use external oscillator for pic16f877a. I can
simulate this code and it works fine but when I burn to PIC, lcd not display anything.
Code:

#define CRYSTAL_FREQ    16000000

#include <16F877A.h>

/* Include this file by inserting the line "#include <jonsinc.h>" at
the beginning of the C source code.  Or, if you prefer, you can embed it's
contents at the end of each of your 12C509H, 16F84H, 16F874.H, etc. files.*/

#case

#ifndef TRUE
#define TRUE 1
#endif

#ifndef FALSE
#define FALSE 0
#endif

#ifndef YES
#define YES 1
#endif

#ifndef NO
#define NO 0
#endif

#ifndef HIGH
#define HIGH 1
#endif

#ifndef LOW
#define LOW 0
#endif

#ifndef ON
#define ON 1
#endif

#ifndef OFF
#define OFF 0
#endif

#ifndef UP
#define UP 1
#endif

#ifndef DOWN
#define DOWN 0
#endif

#ifndef UCHAR
#define UCHAR char
#endif

#ifndef UINT
#define UINT long
#endif

#ifndef BIT
#define BIT short
#endif

#ifndef SCHAR
#define SCHAR signed int
#endif

#ifndef SINT
#define SINT signed long
#endif

#ifndef FLOAT
#define FLOAT float
#endif


// The six bus pins are defined here.
// this example happens to use PIC port B3, B4, B5, B6 for LCD data
// and port B5 for LCD ENABLE and port B6 for LCD RS.
#define LCD_D4          PIN_B1
#define LCD_D5          PIN_B2
#define LCD_D6          PIN_B3
#define LCD_D7          PIN_B4
#define LCD_EN          PIN_B5
#define LCD_RS          PIN_B6


// misc display defines
#define LINE_1          0x00
#define LINE_2          0x40
#define CLEAR_DISP      0x01

// prototype statements
#separate void LCD_Init ( void );
#separate void LCD_SetPosition ( unsigned int cX );
#separate void LCD_PutChar ( unsigned int cX );
#separate void LCD_PutCmd ( unsigned int cX );
#separate void LCD_PulseEnable ( void );
#separate void LCD_SetData ( unsigned int cX );
#separate void Delay5mS ( char cCnt );

// whatever pins you assign to the display
// MUST be in a bus that is a CCS type "standard_io".
#use standard_io ( A )
#use standard_io ( B )
#use standard_io ( C )
#use delay ( clock = CRYSTAL_FREQ )
static char cButtonPressed, cSkip, cButtonCount;

// code start here
void main ( void )
    {
    char cX;

    cX = 1;                      // set number
    LCD_Init();                // set up LCD for 4-wire bus, etc.
    LCD_PutCmd ( CLEAR_DISP );      // clear screen
    LCD_SetPosition ( LINE_1 + 0 );    // set line and offset on line
    printf ( LCD_PutChar, "ewere ");   // display message
    LCD_SetPosition ( LINE_2 + 5 );   // set line and offset on line
    printf ( LCD_PutChar, "haha" );    // display message

    while ( 1 );                  // stop
    }

/* SIX LCD-SPECIFIC FUNCTIONS ARE BELOW============================== */

#separate 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 & scroll left */
    }

#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 */
    if ( !cSkip )
        {
        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 );
        }
    }

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

#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 );
    }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 14, 2008 1:30 pm     Reply with quote

Add #fuses and #use delay() statements. Example:
Code:
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=16000000)


Put the statements in the order as shown above. The #include statement
is first, then the #fuses and #use delay() go after it.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group