- CODE: SELECT_ALL_CODE
//=============================================================================
// Filename: Example_xlcd1.c
//-----------------------------------------------------------------------------
// Compiled using MPLAB-C18 v3.34 student edition
//=============================================================================
// Company : Cytron Technologies, Malaysia
// Revision : 1.00
// Date : 28 Dec 2009
//=============================================================================
#include <p18f4520.h>
#include "xlcd.h"
#include "delays.h"
//=============================================================================
// Configuration Bits
//=============================================================================
#pragma config OSC = HS // HS oscillator
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor disabled
#pragma config IESO = OFF // Oscillator Switchover mode disabled
#pragma config PWRT = OFF // PWRT disabled
#pragma config BOREN = OFF // Brown-out Reset disabled in hardware and software
#pragma config WDT = OFF // WDT disabled (control is placed on the SWDTEN bit)
#pragma config MCLRE = ON // MCLR pin enabled; RE3 input pin disabled
#pragma config PBADEN = OFF // PORTB<4:0> pins are configured as digital I/O on Reset
#pragma config CCP2MX = PORTC // CCP2 input/output is multiplexed with RC1
#pragma config LVP = OFF // Single-Supply ICSP disabled
#pragma config XINST = OFF // Extended Instruction Set
//=============================================================================
// Define Pins
//=============================================================================
#define led1 LATBbits.LATB6 //active High
#define led2 LATBbits.LATB7
#define sw1 PORTBbits.RB0
#define sw2 PORTBbits.RB1
//=============================================================================
// Function Prototypes
//=============================================================================
void Delay_1msX (unsigned int miliseconds);
void Delay_100msX (unsigned int msec);
//=============================================================================
// Global Variables
//=============================================================================
unsigned int i, t;
//=============================================================================
// Main Program
//=============================================================================
void main ()
{
//set I/O input output
TRISB = 0b00000011; //Configure PORTB I/O direction
TRISD = 0b00000000; //Configure PORTD I/O direction
PORTB = 0;
PORTD = 0;
//-------------------------------------------------------------------------
// Configure External LCD
//-------------------------------------------------------------------------
OpenXLCD( EIGHT_BIT & LINES_5X7 );
ClearXLCD(); //Clear display
//-------------------------------------------------------------------------
// User-defined Graphics
//-------------------------------------------------------------------------
SetCGRamAddr(0x40); //Goto CGRAM address #1
// 90 Degree Rotated 'RH'
putcXLCD(0b11111);
putcXLCD(0b00100);
putcXLCD(0b11111);
putcXLCD(0b00000);
putcXLCD(0b01001);
putcXLCD(0b10101);
putcXLCD(0b10110);
putcXLCD(0b11111);
// 90 Degree Rotated '2T'
putcXLCD(0b10000);
putcXLCD(0b11111);
putcXLCD(0b10000);
putcXLCD(0b00000);
putcXLCD(0b01001);
putcXLCD(0b10101);
putcXLCD(0b10011);
putcXLCD(0b01001);
// Battery 1
putcXLCD(0b01110);
putcXLCD(0b11011);
putcXLCD(0b10001);
putcXLCD(0b10001);
putcXLCD(0b10001);
putcXLCD(0b10011);
putcXLCD(0b10111);
putcXLCD(0b11111);
// Battery 2
putcXLCD(0b01110);
putcXLCD(0b11011);
putcXLCD(0b10001);
putcXLCD(0b10001);
putcXLCD(0b10011);
putcXLCD(0b10111);
putcXLCD(0b11111);
putcXLCD(0b11111);
// Battery 3
putcXLCD(0b01110);
putcXLCD(0b11011);
putcXLCD(0b10001);
putcXLCD(0b10011);
putcXLCD(0b10111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
// Battery 4
putcXLCD(0b01110);
putcXLCD(0b11011);
putcXLCD(0b10011);
putcXLCD(0b10111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
// Battery 5
putcXLCD(0b01110);
putcXLCD(0b11011);
putcXLCD(0b10111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
// Battery 6
putcXLCD(0b01110);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
putcXLCD(0b11111);
ClearXLCD(); //Clear display
led1=1; //Turn on led1
//-------------------------------------------------------------------------
// Display External LCD
//-------------------------------------------------------------------------
SetCurXLCD(0); //Set cursor to line 1, position 0
putcXLCD(1); //Display user-defined graphic 1
SetCurXLCD(20); //Set cursor to line 2, position 0
putcXLCD(0); //Display user-defined graphic 0
SetCurXLCD(2); //Set cursor to line 1, position 2
for(i=2;i<8;i++) //Display user-defined graphic 2 to 7
{
putcXLCD(i);
}
putrsXLCD(" SK40C"); //Display "SK40C"
while(1) //Loop the battery level graphics
{
for(i=0;i<6;i++) //Refresh battery level graphics
{ //continuously every 500ms
led2=!led2; //Toggle led2
SetCurXLCD(22); //Set cursor to line 2, position 2
putcXLCD(i+2); //Display current user-defined graphic
Delay_100msX(5); //Delay 500ms
}
}
}//End of main
//=============================================================================
// Subroutines
//=============================================================================
/********************************************************************
* Function Name: Delay_1msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 1ms (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (1ms * 48MHz) / 4 *
* Cycles = 12,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 12,000. *
********************************************************************/
void Delay_1msX (unsigned int miliseconds)
{
t=0;
while(t<miliseconds)
{
Delay1KTCYx(11);
Delay10TCYx(96);
Nop();
Nop();
Nop();
Nop();
Nop();
t++;
}
}//End of Delay_1msX
/********************************************************************
* Function Name: Delay_100msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 100ms *
* (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (100ms * 48MHz) / 4 *
* Cycles = 1,200,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 1,200,000. *
********************************************************************/
void Delay_100msX (unsigned int msec)
{
t=0;
while(t<msec)
{
Delay10KTCYx(119);
Delay1KTCYx(9);
Delay10TCYx(96);
t++;
}
}//End of Delay_100msX
the error displayed was :
----------------------------------------------------------------------
Debug build of project `C:\Users\dell\Downloads\SK40C 18F4520 Sample Program\SK40C 18F4520 Sample Program\LCD Display\SK40C_18F4520.mcp' started.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v9.80, mcc18.exe v9.80, mplib.exe v9.80
Preprocessor symbol `__DEBUG' is defined.
Sun Dec 18 17:06:52 2011
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\dell\Downloads\SK40C 18F4520 Sample Program\SK40C 18F4520 Sample Program\LCD Display\SK40C_18F4520.mcs".
Clean: Done.
Executing: "D:\PSM project\mplab\compiler\bin\mcc18.exe" -p=18F4520 "xlcd.c" -fo="xlcd.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
"D:\PSM project\mplab\compiler\bin\picc18" --cmode=c18 -q --asmlist --pass1 -I. --chip=18F4520 xlcd.c -Oxlcd.o -D__DEBUG
xlcd.c: OpenXLCD()
29: Delay_1msX(15);
^ (361) function declared implicit int (warning)
xlcd.c:
115: {
^ (984) type redeclared
^ (1098) conflicting declarations for variable "putrsXLCD" (D:\PSM project\mplab\compiler\include\plib/xlcd.h:129)
^ (252) argument 0 conflicts with prototype
(908) exit status = 1
(908) exit status = 1
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Users\dell\Downloads\SK40C 18F4520 Sample Program\SK40C 18F4520 Sample Program\LCD Display\SK40C_18F4520.mcp' failed.
Language tool versions: MPASMWIN.exe v5.30.01, mplink.exe v9.80, mcc18.exe v9.80, mplib.exe v9.80
Preprocessor symbol `__DEBUG' is defined.
Sun Dec 18 17:06:54 2011
----------------------------------------------------------------------
BUILD FAILED