#include<pic.h>
#include<htc.h>
#include "Picture.h"
#define __PIC16F877_H
// LCD Port and Connection Configurations
#define Output 0
#define ConfigureLCDPINsDirection(Value) (TRISD = Value, \
TRISCbits.TRISC3 = Value, \
TRISCbits.TRISC4 = Value, \
TRISCbits.TRISC5 = Value, \
TRISCbits.TRISC6 = Value, \
TRISCbits.TRISC7 = Value)
#define DataBusLCD PORTD
#define RegisterSelect PORTCbits.RC3
#define EnableLCD PORTCbits.RC4
#define ChipSelect1 PORTCbits.RC5
#define ChipSelect2 PORTCbits.RC6
#define ResetLCD PORTCbits.RC7
#define Enable 1
#define Disable 0
#define Command 0
#define Data 1
#define DisplayON 63
#define DisplayStartLine 192
#define LeftChip 1
#define RightChip 2
#define BothChip 3
// LCD Index addresses
#define Index0 0x40
#define Index1 0x50
#define Index2 0x60
#define Index3 0x70
#define Index4 0x80
#define Index5 0x90
#define Index6 0xA0
#define Index7 0xB0
// LCD Pages address
#define Page0 0xB8
#define Page1 0xB9
#define Page2 0xBA
#define Page3 0xBB
#define Page4 0xBC
#define Page5 0xBD
#define Page6 0xBE
#define Page7 0xBF
#define ColourON 1
#define ColourOFF 0
void delay(unsigned int i)
{
while(i--);
}
void InitializeGraphicalLCD(void);
void ChipSelection(unsigned char Chip);
void ToggleEnablePin(void);
void WriteCommandToLCD(unsigned char CommandToLCD, unsigned char SelectChip);
void WriteDataToLCD(unsigned char DataToLCD, unsigned char SelectChip);
void WriteAddressToLCD(unsigned char AddressX, unsigned char AddressY, unsigned char SelectChip);
void ClearScreen(void);
void FillScreen(void);
void DisplayPicture(const unsigned char *PtrArray);
void InitializeGraphicalLCD(void)
{
ConfigureLCDPINsDirection(Output);
RegisterSelect = Command;
EnableLCD = Enable;
DataBusLCD = Disable;
ChipSelect1 = Disable;
ChipSelect2 = Disable;
ResetLCD = Enable;
delay(1);
ResetLCD = Disable; // Normal Operation
WriteCommandToLCD(DisplayON, BothChip); // Sending 63 to both chip CS1 and CS2
WriteCommandToLCD(DisplayStartLine, BothChip); // Sending 192 to both chip CS1 and CS2
ClearScreen();
}
void ChipSelection(unsigned char Chip)
{
if (Chip == 1)
{
ChipSelect1 = Enable;
ChipSelect2 = Disable;
}
else if (Chip == 2)
{
ChipSelect1 = Disable;
ChipSelect2 = Enable;
}
else if (Chip == 3)
{
ChipSelect1 = Enable;
ChipSelect2 = Enable;
}
}
void ToggleEnablePin(void)
{
delay(1);
EnableLCD = Enable;
delay(1);
EnableLCD = Disable;
}
void WriteCommandToLCD(unsigned char CommandToLCD, unsigned char SelectChip)
{
// sending data to LCD.
ChipSelection(SelectChip);
RegisterSelect = Command;
DataBusLCD = CommandToLCD;
ToggleEnablePin();
}
void WriteDataToLCD(unsigned char DataToLCD, unsigned char SelectChip)
{
// sending data to LCD.
ChipSelection(SelectChip);
RegisterSelect = Data;
DataBusLCD = DataToLCD;
ToggleEnablePin();
}
void WriteAddressToLCD(unsigned char AddressX, unsigned char AddressY, unsigned char SelectChip)
{
// sending X address.
WriteCommandToLCD(AddressX, SelectChip);
// sending Y address.
WriteCommandToLCD(AddressY, SelectChip);
}
void ClearScreen(void)
{
unsigned char X = 0, Y = 0, Page = 0;
Page = Page0;
for (X = 0; X < 8; X++)
{
WriteAddressToLCD(Page++, Index0, BothChip);
for (Y = 0; Y < 64; Y++)
WriteDataToLCD(0x00, BothChip);
}
}
void FillScreen(void)
{
unsigned char X = 0, Y = 0, Page = 0;
Page = Page0;
for (X = 0; X < 8; X++)
{
WriteAddressToLCD(Page++, Index0, BothChip);
for (Y = 0; Y < 64; Y++)
WriteDataToLCD(0xFF, BothChip);
}
}
void DisplayPicture(const unsigned char *PtrArray)
{
unsigned char X = 0, Y = 0, Page = 0;
Page = Page0;
for (X = 0; X < 8; X++)
{
WriteAddressToLCD(Page, Index0, LeftChip);
for (Y = 0; Y < 64; Y++)
WriteDataToLCD(*PtrArray++, LeftChip);
WriteAddressToLCD(Page++, Index0, RightChip);
for (Y = 0; Y < 64; Y++)
WriteDataToLCD(*PtrArray++, RightChip);
}
}
int main() {
InitializeGraphicalLCD();
//FillScreen();
ClearScreen();
DisplayPicture(Picture1);
while(1)
{
}
return 0;
}
//**************************************PICTURE.H******************//
#ifndef PICTURE_H
#define PICTURE_H
#ifdef __cplusplus
extern "C" {
#endif
const unsigned char Picture1 [] ={ /* 0X22,0X01,0X80,0X00,0X40,0X00, */
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XF8,0XFC,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0XC0,0XF8,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFC,0XE0,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0XC0,0XF8,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFC,0XE0,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XF8,0XFF,
0XFF,0X3F,0X1F,0X8F,0XCF,0XE7,0XF3,0XF1,0XF9,0XF9,0XF9,0XF8,0XF9,0XF1,0XF3,0X87,
0X1F,0XF8,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XF8,0X3F,0X0F,0XC3,0XF1,
0XF8,0XFE,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X7F,0X3F,0X3F,0X3F,0X3F,0X7F,0X7F,
0X00,0XFF,0XFF,0XFF,0XF8,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0XF8,0XFE,0XFF,0XFF,0XFF,0XFF,0XFF,0XFC,0XF0,0XC0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X7F,0X7F,0X7F,0X7F,0X7F,
0X7F,0X7F,0X7F,0X7F,0X7E,0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X00,0X00,
0X00,0XFF,0X7F,0X7F,0X7F,0X7F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X7F,0X7F,0X7F,
0X7F,0X7F,0X00,0X00,0X00,0X80,0XF0,0XFC,0XFE,0XFF,0XFF,0XFF,0XFF,0XFE,0XFC,0XE0,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XC0,0XF8,0X3F,0X07,0XF0,0XFC,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X03,0X00,0X00,0X00,0X00,0X80,0XE0,0XFC,0X1F,
0X03,0X1F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0XFF,0XFF,0XFF,0XFF,
0X00,0X80,0XF0,0XFE,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFC,0XF1,0XF3,0XE7,0XC7,0XCF,
0XC7,0XE7,0XE7,0XF3,0XF1,0XF9,0XFC,0XFC,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0XF8,0XC0,0X00,
0X00,0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0X7F,0X00,0XFE,0XFE,0XFE,0XFF,0XFF,0XFF,0XFF,
0XFF,0X7F,0X3F,0X02,0X3F,0X7F,0XFF,0XFF,0XFF,0XFF,0XFE,0XFE,0XFE,0XFE,0XFE,0XFE,
0XFE,0XFE,0XFE,0XFE,0X7C,0X00,0X3F,0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0XFE,0XFE,0XFE,
0XFE,0XFE,0XFE,0XFE,0XFE,0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X1F,0X7F,
0XFF,0XFF,0XFF,0XFF,0XFF,0XFE,0XFE,0XFE,0X00,0X00,0XFF,0XFF,0XFF,0XFF,0XFF,0X7F,
};
#ifdef __cplusplus
}
#endif
#endif /* PICTURE_H */
//*********************************************************************//
No comments:
Post a Comment