LCD CODE
/*
LCD Module
Lines to be included in
initialization of MCU
DDRB=0xff; // PORT B - LCD Control Line
DDRC=0xff; // PORT C - LCD Command Line
LCDinit(); //
initialize LCD
Main functions
LCDinit()
ClearLCD() Clears
screen
DrawLCD() Draws EVA
face, menu options and status bars on LCD
Highlight(butnum,on/off) Hightlight action on
button press. On=1 Off=0
UpdateStatus(discipline,
happiness, health) Updates status bars
DisplayEmotion(emotion) Displays msg and face
WriteHungry() Displays Hungry on Msg box
WriteUrgent() Displays
Urgent! on Msg box
WriteLate() Displays
Too Late! in Msg box
DrawFood() Displays
food icon when hungry to be placed after display emotion
DrawSick() Displays
Med icon when sick
DrawToilet() Displays
Toilet bowl when urgent
ClearFood() Clears
food icon
ClearSick() Clears Med
icon
ClearToilet() Clears
Toilet bowl
Subfunctions
ClearMsg() Clears
Msgbox
Write'Emotion'() Writes Urgent,lcd_Happy,lcd_Sad,etc in
msg box
ClearFace() Clears EVA face in graphics box
Draw'Emotion'() Draws face corresponding to emotion
*/
#include <delay.h>
// LCD Control lines (PORTB)
#define LCDreset
0x00 // Reset the Display
#define LCDnop 0x47 // No operation
#define CmdSetup 0x47
// Set A0 high
#define CmdWrite 0x43
// Set WR low
#define DataSetup 0x07
// Set A0 low
#define DataWrite 0x03
// Set WR low
#define StatusRead 0x05
//
#define DataRead 0x45
//
// LCD Data Line Commands
(PORTC)
#define SystemSet 0x40 // Initialize system
#define SleepIn 0x53 // Enter standby mode
#define DispOFF 0x58 // Display Off
#define DispON 0x59 // Display On
#define Scroll 0x44 // Initialize Address & Regions
#define CSRForm 0x5D // Set cursor type
#define CharAddr 0x5C // Set address of character RAM
#define CSRRight 0x4C // Cursor direction = right
#define CSRLeft 0x4D // Cursor direction = left
#define CSRUp 0x4E // Cursor direction = up
#define CSRDown 0x4F // Cursor direction = down
#define HorzScroll 0x5A // Set horz scroll position
#define Overlay 0x5B // Set Display Format
#define CSRW 0x46 //
Set cursor address
#define CSRR 0x47 // Read cursor address
#define MWRITE 0x42 // Write to display memory
#define MREAD 0x43 // Read from display memory
#define TextAddress 0x0000
// Character layer base address (1st layer)
#define GraphicsAddress
0x1000 // Graphics layer base
address (2nd layer)
//States corresponding to
emotions
#define lcd_Excited 1
#define lcd_Happy 2
#define lcd_Neutral 3
#define lcd_Bored 4
#define lcd_Sad 5
#define lcd_Angry 6
#define lcd_Naughty 7
#define lcd_Death 8
//Variable declaration
int graphicsaddr=0x1366;
int faceaddr=0x15DB;
char previous=lcd_Neutral;
// Messages limited to 12
char
flash unsigned char
word_Urgent[9] = {8,'U','r','g','e','n','t','!','!'};
flash unsigned char
word_Late[10]={9,'T','o','o',' ','L','a','t','e','!'};
flash unsigned char
word_Hungry[9] = {8,'S','t','a','r','v','i','n','g'};
flash unsigned char
word_Neutral[8] = {7,'N','e','u','t','r','a','l'};
flash unsigned char word_Angry[8]
= {7,'A','n','g','r','y','!','!'};
flash unsigned char
word_Sad[4] = {3,'S','a','d'};
flash unsigned char
word_Happy[6] = {5,'H','a','p','p','y'};
flash unsigned char
word_Bored[6] = {5,'B','o','r','e','d'};
flash unsigned char word_Excited[8]
= {7,'E','x','c','i','t','e','d'};
flash unsigned char
word_Naughty[8]={7,'N','a','u','g','h','t','y'};
flash unsigned char
word_Death[9]={8,'G','a','m','e','o','v','e','r'};
// Bitmap for Graphics
display
flash unsigned char
feed[16][2]={{0x00,0x00},{0x00,0x00},{0x00,0x00},{0x00,0xE0},{0x00,0xA0},{0x00,0x98},
{0x01,0x04},{0x02,0x38},{0x04,0x40},{0x38,0x80},{0x21,0x00},{0x3A,0x00},
{0x0A,0x00},{0x06,0x00},{0x00,0x00},{0x00,0x00}};
flash unsigned char
med[16][2]={{0x00,0x00},{0x00,0x00},{0x00,0x00},{0x07,0x80},{0x07,0x80},{0x07,0x80},
{0x3F,0xF0},{0x3F,0xF0},{0x3F,0xF0},{0x3F,0xF0},{0x3F,0xF0},{0x07,0x80},
{0x07,0x80},{0x07,0x80},{0x00,0x00},{0x00,0x00}};
flash unsigned char
wc[16][2]={{0x01,0xFC},{0x02,0x0C},{0x07,0xF4},{0x04,0x14},{0x04,0x14},{0x04,0x18},
{0x07,0xF0},{0x08,0x10},{0x13,0x10},{0x24,0x90},{0x24,0xA0},{0x23,0x20},
{0x18,0xE0},{0x0F,0x60},{0x04,0x80},{0x02,0x80}};
flash unsigned char
play[16][2]={{0x00,0x20},{0x00,0xD8},{0x01,0x04},{0x01,0x04},{0x01,0x04},{0x01,0x04},
{0x01,0x8C},{0x00,0x88},{0x00,0x88},{0x00,0x88},{0x00,0x50},{0x38,0x50},
{0x6C,0x50},{0x44,0xD8},{0x6C,0x88},{0x38,0xF8}};
flash unsigned char
pat[16][2]={{0x00,0x00},{0x00,0x00},{0x00,0x00},{0x0E,0x38},{0x1F,0x7C},{0x3F,0xFE},
{0x3F,0xFE},{0x3F,0xFE},{0x1F,0xFC},{0x0F,0xF8},{0x07,0xF0},{0x03,0xE0},
{0x01,0xC0},{0x00,0x80},{0x00,0x00},{0x00,0x00}};
flash unsigned char word_Spank[16][2]={{0x00,0x00},{0x0F,0xF0},{0x10,0x08},{0x20,0x04},{0x28,0x14},{0x24,0x24},
{0x22,0x44},{0x20,0x04},{0x20,0x04},{0x23,0xC4},{0x22,0x44},{0x23,0xC4},
{0x20,0x04},{0x10,0x08},{0x0F,0xF0},{0x00,0x00}};
// LCD Subroutines
void LCDinit(void); //
Setup LCD
void DrawLCD(void); // Initial Display
void ClearLCD(void); //clear LCD
void UpdateStatus(char
discipline,char local_Happy,char health,unsigned char barDisc,unsigned char
barH,unsigned char barHealth);
// Updates Statusbar
void DrawBar(char level); // Draws individual
bars
void ClearBar(char type);
void WriteCMD(unsigned char
CommandCode); //write command
void WriteDATA(unsigned char
CommandCode); //write command
parameters
// Text for msg display
void WriteUrgent(void);
void WriteLate(void);
void WriteHungry(void);
void WriteNeutral(void);
void WriteAngry(void);
void WriteSad(void);
void WriteHappy(void);
void WriteBored(void);
void WriteExcited(void);
void
WriteNaughty(void);
void WriteDeath(void);
void ClearMsg(void);
void Highlight(char
butnum,char on); // Highlights action on button press
//funtions to draw EVA faces
void DrawLineVert(int
address,char lines,char pixel); //Draws vertical line
void DrawLineHoriz(int
address,char lines,char align); //Draws horizontal line
void DrawNeutral(void);
void DrawAngry(void);
void DrawSad(void);
void DrawHappy(void);
void DrawBored(void);
void DrawExcited(void);
void DrawNaughty(void);
void DrawDeath(void);
void ClearFace(void);
//functions to draw icons
void DrawPat(void);
void DrawFeed(void);
void DrawPlay(void);
void DrawSpank(void);
void DrawMed(void);
void DrawWC(void);
void DrawFood(void);
void DrawSick(void);
void DrawToilet(void);
void ClearFood(void);
void ClearSick(void);
void ClearToilet(void);
//void TestLCD(void);
//Initialize the LCD screen
void LCDinit(void){
PORTB = LCDnop;
delay_ms(5); //
Delay 5 ms
PORTB = LCDreset;
delay_ms(3);
PORTB = LCDnop;
delay_ms(2);
WriteCMD(SystemSet); // Setup LCD parameters
WriteDATA(0x30);
WriteDATA(0x87); // horiz character size = 8 pixel
WriteDATA(0x07); // vertical character size = 8 pixel
WriteDATA(0x20); // 32 characters per row (256/8)
WriteDATA(0x2F);
WriteDATA(0x7f); // 128 lines per screen
WriteDATA(0x21);
WriteDATA(0x00);
WriteCMD(Overlay);
WriteDATA(0x01); // layer1 XOR layer2
WriteCMD(Scroll); // Setup display layers
WriteDATA(0x00);
WriteDATA(0x00); // layer 1(text) address= 0x0000
WriteDATA(0x7f); // Number of lines in layer 1 =128
WriteDATA(0x00);
WriteDATA(0x10); // Layer 2(graphics) address =0x1000
WriteDATA(0x7f); // Number of lines in layer 2 =128
ClearLCD();
WriteCMD(CSRW);
WriteDATA(0x00);
WriteDATA(0x00); // Position cursor to top left of screen (layer1)
WriteCMD(CSRRight); // Set cursor direction to right
WriteCMD(HorzScroll);
WriteDATA(0x00); // Don't scroll Display horizontally
WriteCMD(DispON); // turn on display
WriteDATA(0x14); // turn on layer 1 and layer 2
DrawLCD(); //
Draws menu and face
}// LCD init
// Draws EVA face, menu
options and status bars on LCD
void DrawLCD(void){
unsigned char i;
// Display Text
WriteCMD(CSRRight); // Set cursor direction to right
WriteCMD(CSRW); //Position
cursor at center of 1st layer line 2
WriteDATA(0x30);
WriteDATA(0x00);
WriteCMD(MWRITE);
// Prints EVA
WriteDATA('E');
WriteDATA('V');
WriteDATA('A');
WriteCMD(CSRW); //Position
cursor at 1st layer char line 4, 1st char
WriteDATA(0x63);
WriteDATA(0x00);
WriteCMD(MWRITE);
// Prints Pat
WriteDATA('P');
WriteDATA('a');
WriteDATA('t');
DrawPat();
WriteCMD(CSRW); //Position
cursor at 1st layer char line 4, 26th char
WriteDATA(0x7E);
WriteDATA(0x00);
WriteCMD(MWRITE);
// Prints Spank
WriteDATA('S');
WriteDATA('p');
WriteDATA('a');
WriteDATA('n');
WriteDATA('k');
DrawSpank();
WriteCMD(CSRW); //Position
cursor at 1st layer char line 8, 1st char
WriteDATA(0xE7);
WriteDATA(0x00);
WriteCMD(MWRITE);
// Prints feed
WriteDATA('F');
WriteDATA('e');
WriteDATA('e');
WriteDATA('d');
DrawFeed();
WriteCMD(CSRW); //Position
cursor at 1st layer char line 8, 28th char
WriteDATA(0x04);
WriteDATA(0x01);
WriteCMD(MWRITE);
// Prints Medicine
WriteDATA('M');
WriteDATA('e');
WriteDATA('d');
DrawMed();
WriteCMD(CSRW); //Position
cursor at 1st layer char line 12, 1st char
WriteDATA(0x6B);
WriteDATA(0x01);
WriteCMD(MWRITE);
// Prints Play
WriteDATA('P');
WriteDATA('l');
WriteDATA('a');
WriteDATA('y');
DrawPlay();
WriteCMD(CSRW); //Position
cursor at 1st layer char line 12, 29th char
WriteDATA(0x89);
WriteDATA(0x01);
WriteCMD(MWRITE);
// Prints WC
WriteDATA('W');
WriteDATA('C');
DrawWC();
//Display Graphics
WriteCMD(CSRW); //Position cursor at 2nd layer
WriteDATA(0x09);
WriteDATA(0x10);
WriteCMD(CSRDown); //
Set cursor direction to down
WriteCMD(MWRITE);
// Draw Vertical line
for(i=0;i<103;i++)
{
WriteDATA(0x08);
}
WriteCMD(CSRW); //Position
cursor at 2nd layer
WriteDATA(0x17);
WriteDATA(0x10);
WriteCMD(MWRITE);
// Draw Vertical liine
for(i=0;i<103;i++)
{
WriteDATA(0x08);
}
WriteCMD(CSRW); //Position
cursor at 2nd layer
WriteDATA(0x21);
WriteDATA(0x13);
WriteCMD(CSRRight); //Cursor
direction = right
WriteCMD(MWRITE); // Draw horizontal line beneath EVA
WriteDATA(0x0F);
for(i=0;i<13;i++)
{
WriteDATA(0xFF);
}
WriteDATA(0xF8);
WriteCMD(CSRW); //Position cursor at 2nd layer
WriteDATA(0x25);
WriteDATA(0x1D);
WriteCMD(MWRITE); // Draw horizontal line beneath above
status bar
for(i=0;i<33;i++)
{
WriteDATA(0xFF);
}
WriteCMD(CSRW); //Draws labels in status bars
WriteDATA(0xD0);
WriteDATA(0x01);
WriteCMD(MWRITE);
WriteDATA('D');
WriteCMD(CSRW);
WriteDATA(0xDC);
WriteDATA(0x01);
WriteCMD(MWRITE);
WriteDATA('H');
DrawNeutral();
WriteNeutral();
}//end DrawLCD
//These next 3 procedures
were used from the a final project from the year before last
//year, the Tilt Maze. The source code can be see at
//http://instruct1.cit.cornell.edu/courses/ee476/FinalProjects/s2001/kmo15/m1dc.c
/*********************************************************************/
/* WriteCMD() : Sends Command to LCD controller */
/*********************************************************************/
void WriteCMD(unsigned char
CommandCode) {
PORTC = CommandCode;
PORTB = CmdSetup;
PORTB = CmdWrite;
PORTB = CmdSetup;
return;
} // end WriteCMD
/*********************************************************************/
/* WriteDATA() : Sends parameters or data to LCD
controller */
/*********************************************************************/
void WriteDATA(unsigned char
CommandCode) {
PORTC = CommandCode;
PORTB = DataSetup;
PORTB = DataWrite;
PORTB = DataSetup;
return;
} // end WriteDATA
/*********************************************************************/
/* clearLCD() : Clears the LCD display memory */
/*********************************************************************/
void ClearLCD(void) {
unsigned short i;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(0x00);
WriteDATA(0x00); // Beginning address of layer1
WriteCMD(MWRITE);
for (i=0; i<550; i++) { // layer 1(text) 512 character spaces on
screen. 8x8 pixel characters
WriteDATA(0x20); // write " " to character memory
}
WriteCMD(CSRW);
WriteDATA(0x00);
WriteDATA(0x10); // Beginning address of layer 2
WriteCMD(MWRITE);
for (i=0; i<4500; i++) { // layer
2(graphics) 512*8 byte pixel spaces on screen.
WriteDATA(0x00); // erase graphics memory
}
return;
} // end clearLCD
// Writes and centers the
messages in Msgbox
void WriteUrgent(void){
char i;
char temp;
ClearMsg();
temp=(word_Urgent[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight); //Set
cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Urgent[0];i++){
WriteDATA(word_Urgent[i]);
}
}
void WriteLate(void){
char i;
char temp;
ClearMsg();
temp=(word_Late[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Late[0];i++){
WriteDATA(word_Late[i]);
}
}
void WriteHungry(void){
char i;
char temp;
ClearMsg();
temp=(word_Hungry[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Hungry[0];i++){
WriteDATA(word_Hungry[i]);
}
}
void WriteNeutral(void)
{
char i;
char temp;
ClearMsg();
temp=(word_Neutral[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Neutral[0];i++){
WriteDATA(word_Neutral[i]);
}
}
void WriteNaughty(void)
{
char i;
char temp;
ClearMsg();
temp=(word_Naughty[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Naughty[0];i++){
WriteDATA(word_Naughty[i]);
}
}
void WriteAngry(void){
char i;
char temp;
ClearMsg();
temp=(word_Angry[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Angry[0];i++){
WriteDATA(word_Angry[i]);
}
}
void WriteSad(void){
char i;
char temp;
ClearMsg();
temp=(word_Sad[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Sad[0];i++){
WriteDATA(word_Sad[i]);
}
}
void WriteHappy(void){
char i;
char temp;
ClearMsg();
temp=(word_Happy[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Happy[0];i++){
WriteDATA(word_Happy[i]);
}
}
void WriteBored(void){
char i;
char temp;
ClearMsg();
temp=(word_Bored[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Bored[0];i++){
WriteDATA(word_Bored[i]);
}
}
void WriteExcited(void){
char i;
char temp;
ClearMsg();
temp=(word_Excited[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Excited[0];i++){
WriteDATA(word_Excited[i]);
}
}
void WriteDeath(void){
char i;
char temp;
ClearMsg();
temp=(word_Death[0]-1)/2;
temp=0x31-temp;
WriteCMD(CSRRight);
//Set cursor direction = right
WriteCMD(CSRW);
WriteDATA(temp); //Centers
cursor
WriteDATA(0x00);
WriteCMD(MWRITE);
for(i=1;i<=word_Death[0];i++){
WriteDATA(word_Death[i]);
}
}
/* Clears text in message box in order to
present a new message */
void ClearMsg(void) {
unsigned short i;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(0x2B);
WriteDATA(0x00);
WriteCMD(MWRITE);
for (i=0; i<13; i++) {
WriteDATA(0x20); // write " " to character memory
}
}// end ClearMsg
//Highlights action when
button is pressed
void Highlight(char
butnum,char on){
char i,j;
int
tempaddr;
WriteCMD(CSRRight);
// if button 1 is pressed highlight the action 'pat'
if(butnum==1){
tempaddr=0x12F7;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<9;i++){
WriteCMD(MWRITE);
for(j=0;j<3;j++){
if(on)
WriteDATA(0xff);
else
WriteDATA(0x00);
}//for
tempaddr
+= 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}//for
}//if butnum==1
// if button 3 is pressed highlight the action 'Spank'
if(butnum==3){
tempaddr=0x1312;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<9;i++){
WriteCMD(MWRITE);
for(j=0;j<5;j++){
if(on)
WriteDATA(0xff);
else
WriteDATA(0x00);
}//for
tempaddr
+= 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}//for
}//if butnum==3
// if button 4 is pressed highlight the action 'Feed'
if(butnum==4){
tempaddr=0x1717;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<9;i++){
WriteCMD(MWRITE);
for(j=0;j<4;j++){
if(on)
WriteDATA(0xff);
else
WriteDATA(0x00);
}//for
tempaddr
+= 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}//for
}//if butnum==4
// if button 6 is pressed highlight the action 'Medicine'
if(butnum==6){
tempaddr=0x1734;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<9;i++){
WriteCMD(MWRITE);
for(j=0;j<3;j++){
if(on)
WriteDATA(0xff);
else
WriteDATA(0x00);
}//for
tempaddr
+= 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}//for
}//if butnum==6
// if button 7 is pressed highlight the action 'Play'
if(butnum==7){
tempaddr=0x1B37;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<9;i++){
WriteCMD(MWRITE);
for(j=0;j<4;j++){
if(on)
WriteDATA(0xff);
else
WriteDATA(0x00);
}//for
tempaddr
+= 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}//for
}//if butnum==7
//
if button 9 is pressed highlight the action 'WC'
if(butnum==9){
tempaddr=0x1B55;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<9;i++){
WriteCMD(MWRITE);
for(j=0;j<2;j++){
if(on)
WriteDATA(0xff);
else
WriteDATA(0x00);
}//for
tempaddr
+= 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}//for
}//if butnum==9
}//end Highlight
// Draws a symbol beside the
printed word
void DrawPat(void){
char i;
char j;
int tempaddr=0x1276;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(pat[i][j]); // Draw heart
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawPat
// Draws a symbol beside the
printed word
void DrawSpank(void){
char i;
char j;
int tempaddr=0x128B;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(word_Spank[i][j]); // Draw Spank
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawSpank
// Draws a symbol beside the
printed word
void DrawFeed(void){
char i;
char j;
int tempaddr=0x16D9;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(feed[i][j]); // Draw bone
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawFeed
void DrawFood(void){
char i;
char j;
int tempaddr=0x1385;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(feed[i][j]); // Draw bone
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawFood
// Clears food icon
void ClearFood(void){
char j;
char i;
int tempaddr;
tempaddr=0x1385;
WriteCMD(CSRRight); //Cursor
direction = right
for(j=1;j<17;j++)
{
WriteCMD(CSRW); //Position
cursor at 2nd layer
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
WriteCMD(MWRITE);
for(i=0;i<2;i++) //clear
line
{
WriteDATA(0x00);
}
tempaddr+=33;
}
}
void DrawMed(void){
char i;
char j;
int tempaddr=0x16F0;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(med[i][j]); // Draw Medicine
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
tempaddr=0x1DC2;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(med[i][j]); // Draw Medicine
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawMed
void DrawSick(void){
char i;
char j;
int tempaddr=0x15B6;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(med[i][j]); // Draw Medicine
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
}//end DrawSick
// Clears Sick icon
void ClearSick(void){
char j;
char i;
int tempaddr;
tempaddr=0x15B6;
WriteCMD(CSRRight); //Cursor
direction = right
for(j=1;j<17;j++)
{
WriteCMD(CSRW); //Position
cursor at 2nd layer
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
WriteCMD(MWRITE);
for(i=0;i<2;i++) //clear
line
{
WriteDATA(0x00);
}
tempaddr+=33;
}
}
void DrawPlay(void){
char i;
char j;
int tempaddr=0x1A54;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(play[i][j]); // Draw baseball bat
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawPlay
void DrawWC(void){
char i;
char j;
int tempaddr=0x1A6B;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(wc[i][j]); // Draw WC
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawWC
void DrawToilet(void){
char i;
char j;
int tempaddr=0x17E7;
WriteCMD(CSRRight);
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
for(i=0;i<16;i++)
{
WriteCMD(MWRITE);
for(j=0;j<2;j++)
{
WriteDATA(wc[i][j]); // Draw WC
}
tempaddr += 33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
} //end DrawToilet
// Clears Toilet icon
void ClearToilet(void){
char j;
char i;
int tempaddr;
tempaddr=0x17E7;
WriteCMD(CSRRight); //Cursor
direction = right
for(j=1;j<17;j++)
{
WriteCMD(CSRW); //Position
cursor at 2nd layer
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
WriteCMD(MWRITE);
for(i=0;i<2;i++) //clear
line
{
WriteDATA(0x00);
}
tempaddr+=33;
}
}
/* Draw Functions for
vertical line
Address= Beginning address
of line
lines= Height of VertLine
pixel= 8 bit map of pixel
*/
void DrawLineVert(int
address,char lines,char pixel){
char j;
WriteCMD(CSRW);
WriteDATA(address);
WriteDATA(address>>8);
WriteCMD(CSRDown);
//Cursor direction = down
WriteCMD(MWRITE);
for(j=0;j<lines;j++)
{
WriteDATA(pixel); //draw pixel
}
} //end drawVert
/*Draw Function for
Horizontal line
address=pixel address for
start of horiz line
lines= width of horizontal
line in pixels.
align= right/left justify
For right justify, line will
draw from right to left
For left justify, line will
draw from left to right
*/
void DrawLineHoriz(int
address,char lines,char align){
char j,points,termpixel;
termpixel=0x00;
points=lines>>3;
//Convert lines(no.of pixels) into no.of bytes
if(lines%8==1){
if(align)
termpixel=0b00000001;
else
termpixel=0b10000000;
}
if(lines%8==2){
if(align)
termpixel=0b00000011;
else
termpixel=0b11000000;
}
if(lines%8==3){
if(align)
termpixel=0b00000111;
else
termpixel=0b11100000;
}
if(lines%8==4){
if(align)
termpixel=0b00001111;
else
termpixel=0b11110000;
}
if(lines%8==5){
if(align)
termpixel=0b00011111;
else
termpixel=0b11111000;
}
if(lines%8==6){
if(align)
termpixel=0b001111111;
else
termpixel=0b111111100;
}
if(lines%8==7){
if(align)
termpixel=0b011111111;
else
termpixel=0b111111110;
}
if(align)
{
WriteCMD(CSRLeft); //Cursor direction=left
address=address-1; //right justify address
}
else
WriteCMD(CSRRight);
//Cursor direction = Right
WriteCMD(CSRW); //position
cursor
WriteDATA(address);
WriteDATA(address>>8);
WriteCMD(MWRITE);
for(j=0;j<points;j++)
{
WriteDATA(0xff); //draw pixel
}
if((lines%8)!=0)
WriteDATA(termpixel); //draws
terminating pixel
}//end drawhoriz
//Draws EVA's face
void DrawHappy(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,6,0b10000111);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp+=3;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,6,0b11110000);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp=faceaddr+0x35A;
DrawLineVert(temp,8, 0b11110000);
DrawLineVert(temp+3,8,0b00001111);
temp+=0xE7;
DrawLineHoriz(temp,32,0);
DrawLineHoriz(temp+33,32,0);
DrawLineHoriz(temp+66,32,0);
DrawLineHoriz(temp+99,32,0);
}// end drawhappy
void DrawSad(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,6,0b10000111);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp+=3;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,6,0b11110000);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
DrawLineVert(temp+0x1EF,5,0b11100000);
temp=faceaddr+0x35A;
DrawLineHoriz(temp,32,0);
DrawLineHoriz(temp+33,32,0);
DrawLineHoriz(temp+66,32,0);
DrawLineHoriz(temp+99,32,0);
temp+=0x84;
DrawLineVert(temp,8,
0b11110000);
DrawLineVert(temp+3,8,0b00001111);
}// end drawsad
//Draws EVA's face
void DrawBored(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+33,6,0b10000111);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp+=3;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+33,6,0b10000111);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp=faceaddr+0x35A;
DrawLineHoriz(temp,32,0);
DrawLineHoriz(temp+33,32,0);
DrawLineHoriz(temp+66,32,0);
DrawLineHoriz(temp+99,32,0);
}// end drawbored
void DrawAngry(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,3,0b11100000);
DrawLineVert(temp+99,3,0b00111000);
DrawLineVert(temp+0xC6,3,0b00001110);
DrawLineVert(temp+0x129,3,0b00000011);
DrawLineVert(temp+0x12A,3,0b10000000);
temp+=1;
DrawLineVert(temp,2,0b00000100);
DrawLineVert(temp+66,1,0b00000110);
DrawLineVert(temp+99,2,0b00000010);
temp+=1;
DrawLineVert(temp,2,0b00100000);
DrawLineVert(temp+66,1,0b01100000);
DrawLineVert(temp+99,2,0b01000000);
temp+=1;
DrawLineVert(temp,3,0b00000111);
DrawLineVert(temp+99,3,0b00011100);
DrawLineVert(temp+0xC6,3,0b01110000);
DrawLineVert(temp+0x129,3,0b11000000);
DrawLineVert(temp+0x128,3,0b00000001);
temp=faceaddr+0x2F8;
DrawLineHoriz(temp,16,0);
DrawLineHoriz(temp+33,16,0);
DrawLineHoriz(temp+66,16,0);
DrawLineHoriz(temp+99,16,0);
} //end drawangry
void DrawNaughty(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+33,6,0b10000111);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp+=3;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,6,0b11110000);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp=faceaddr+0x35A;
DrawLineHoriz(temp,32,0);
DrawLineHoriz(temp+33,32,0);
DrawLineHoriz(temp+66,32,0);
DrawLineHoriz(temp+99,32,0);
temp+=0x84;
DrawLineVert(temp,3,0b00001111);
DrawLineVert(temp+1,3,0b11111000);
temp+=99;
DrawLineVert(temp,2,0b00000111);
DrawLineVert(temp+1,2,0b11110000);
temp+=66;
DrawLineVert(temp,2,0b00000011);
DrawLineVert(temp+1,2,0b11100000);
temp+=66;
DrawLineVert(temp,1,0b00000001);
DrawLineVert(temp+1,1,0b11000000);
}//end drawnaughty
void DrawExcited(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,6,0b10000111);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp+=3;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,6,0b11110000);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp=faceaddr+0x35B;
DrawLineHoriz(temp,16,0);
DrawLineHoriz(temp+33,16,0);
DrawLineHoriz(temp+66,16,0);
temp+=99;
DrawLineVert(temp,5,
0b11110000);
DrawLineVert(temp+1,5,0b00001111);
temp+=0xA5;
DrawLineHoriz(temp,16,0);
DrawLineHoriz(temp+33,16,0);
DrawLineHoriz(temp+66,16,0);
}//end drawexcited
void DrawNeutral(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,5,0b10001110);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp+=3;
DrawLineVert(temp,14,0b10000000);
DrawLineVert(temp+1,14,0b10000000);
DrawLineVert(temp+0xE7,5,0b10111000);
DrawLineHoriz(temp+0x1AD,8,0);
DrawLineHoriz(temp,8,0);
temp=faceaddr+0x35A;
DrawLineHoriz(temp,32,0);
DrawLineHoriz(temp+33,32,0);
DrawLineHoriz(temp+66,32,0);
DrawLineHoriz(temp+99,32,0);
}//end drawneutral
void DrawDeath(void){
int temp;
temp=faceaddr;
DrawLineVert(temp,3,0b00111000);
DrawLineVert(temp+99,3,0b00001110);
DrawLineVert(temp+0xC6,3,0b00000011);
DrawLineVert(temp+0x129,3,0b00001110);
DrawLineVert(temp+0x18C,3,0b00111000);
temp+=1;
DrawLineVert(temp,3,0b00011100);
DrawLineVert(temp+99,3,0b01110000);
DrawLineVert(temp+0xC6,3,0b11000000);
DrawLineVert(temp+0x129,3,0b01110000);
DrawLineVert(temp+0x18C,3,0b00011100);
temp+=1;
DrawLineVert(temp,3,0b00111000);
DrawLineVert(temp+99,3,0b00001110);
DrawLineVert(temp+0xC6,3,0b00000011);
DrawLineVert(temp+0x129,3,0b00001110);
DrawLineVert(temp+0x18C,3,0b00111000);
temp+=1;
DrawLineVert(temp,3,0b00011100);
DrawLineVert(temp+99,3,0b01110000);
DrawLineVert(temp+0xC6,3,0b11000000);
DrawLineVert(temp+0x129,3,0b01110000);
DrawLineVert(temp+0x18C,3,0b00011100);
temp=faceaddr+0x37B;
DrawLineHoriz(temp,32,0);
DrawLineHoriz(temp+33,32,0);
DrawLineHoriz(temp+66,32,0);
DrawLineHoriz(temp+99,32,0);
} //end drawdeath
// Clears EVA's face
void ClearFace(void){
char j;
char i;
int tempaddr;
tempaddr=graphicsaddr;
WriteCMD(CSRW); //Position cursor at 2nd layer
WriteDATA(graphicsaddr);
WriteDATA(graphicsaddr>>8);
WriteCMD(CSRRight); //Cursor
direction = right
for(j=1;j<75;j++)
{
WriteCMD(MWRITE);
for(i=0;i<11;i++) //clear
line
{
WriteDATA(0x00);
}
tempaddr+=33;
WriteCMD(CSRW);
WriteDATA(tempaddr);
WriteDATA(tempaddr>>8);
}
}
// Draws the status bars
corresponding to the current level of Discipline, Happiness and Health
// For 1-21, 1 bar is drawn
// 22-42, 2 bars
// 43-63, 3 bars
// 64-84, 4 bars
// >84, 5 bars
void UpdateStatus(unsigned
char discipline,unsigned char local_Happy,unsigned char health,unsigned char
barDisc,unsigned char barH,unsigned char barHealth){
int
addrD=0x1EB5; //address of Discipline
int addrH=0x1EC1;
//address of lcd_Happy
int addrHealth=0x1ECC; //address
of Health
WriteCMD(CSRRight);
if(barDisc!=(discipline/21+1)){
ClearBar(1);
barDisc=(discipline/21+1);
}
WriteCMD(CSRW);
WriteDATA(addrD);
WriteDATA(addrD>>8);
DrawBar(discipline/21+1);
/* WriteCMD(CSRW);
WriteDATA(0x1B);
WriteDATA(0x07);
WriteCMD(MWRITE);
WriteDATA(discipline);*/
WriteCMD(CSRW);
WriteDATA(addrD+33);
WriteDATA(addrD+33>>8);
DrawBar(discipline/21+1);
if(barH!=local_Happy/21+1){
ClearBar(2);
barH=local_Happy/21+1;
}
WriteCMD(CSRW);
WriteDATA(addrH);
WriteDATA(addrH>>8);
DrawBar(local_Happy/21+1);
WriteCMD(CSRW);
WriteDATA(addrH+33);
WriteDATA(addrH+33>>8);
DrawBar(local_Happy/21+1);
if(barHealth!=health/21+1){
ClearBar(3);
barHealth=health/21+1;
}
WriteCMD(CSRW);
WriteDATA(addrHealth);
WriteDATA(addrHealth>>8);
DrawBar(health/21+1);
WriteCMD(CSRW);
WriteDATA(addrHealth+33);
WriteDATA(addrHealth+33>>8);
DrawBar(health/21+1);
}//end updatestatus
// Draws status bars
void DrawBar(char level){
WriteCMD(MWRITE);
if(level>=1){
WriteDATA(0b00111110);
}
if(level>=2){
WriteDATA(0b00111110);
}
if(level>=3){
WriteDATA(0b00111110);
}
if(level>=4){
WriteDATA(0b00111110);
}
if(level>=5){
WriteDATA(0b00111110);
}
}//end DrawBar
Clears Status bars
void ClearBar(char x){
int addrD=0x1EB5; //address
of Discipline
int addrH=0x1EC1; //address of lcd_Happy
int addrHealth=0x1ECC; //address of Health
if(x==1){
WriteCMD(CSRW);
WriteDATA(addrD);
WriteDATA(addrD>>8);
WriteCMD(MWRITE);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteCMD(CSRW);
WriteDATA(addrD+33);
WriteDATA(addrD+33>>8);
WriteCMD(MWRITE);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
}
if(x==2){
WriteCMD(CSRW);
WriteDATA(addrH);
WriteDATA(addrH>>8);
WriteCMD(MWRITE);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteCMD(CSRW);
WriteDATA(addrH+33);
WriteDATA(addrH+33>>8);
WriteCMD(MWRITE);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
}
if(x==3){
WriteCMD(CSRW);
WriteDATA(addrHealth);
WriteDATA(addrHealth>>8);
WriteCMD(MWRITE);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteCMD(CSRW);
WriteDATA(addrHealth+33);
WriteDATA(addrHealth+33>>8);
WriteCMD(MWRITE);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
WriteDATA(0x00);
}
}//end ClearBar
// Displays EVA's face
corresponding to input parameter 'emotion' from main program
void DisplayEmotion(char
emotion){
switch (emotion) {
case lcd_Happy:
if(previous!=lcd_Happy)
{
ClearFace();
DrawHappy();
WriteHappy();
}
previous=lcd_Happy;
break;
case lcd_Excited:
if(previous!=lcd_Excited) {
ClearFace();
DrawExcited();
WriteExcited();
}
previous=lcd_Excited;
break;
case lcd_Neutral:
if(previous!=lcd_Neutral){
ClearFace();
DrawNeutral();
WriteNeutral();
}
previous=lcd_Neutral;
break;
case lcd_Bored:
if(previous!=lcd_Bored){
ClearFace();
DrawBored();
WriteBored();
}
previous=lcd_Bored;
break;
case lcd_Sad:
if(previous!=lcd_Sad){
ClearFace();
DrawSad();
WriteSad();
}
previous=lcd_Sad;
break;
case lcd_Angry:
if(previous!=lcd_Angry){
ClearFace();
DrawAngry();
WriteAngry();
}
previous=lcd_Angry;
break;
case lcd_Naughty:
if(previous!=lcd_Naughty){
ClearFace();
DrawNaughty();
WriteNaughty();
}
previous=lcd_Naughty;
break;
case
lcd_Death:
if(previous!=lcd_Death){
ClearFace();
DrawDeath();
WriteDeath();
}
previous=lcd_Death;
break;
}//end switch
}//end displayemotion
// Draws icons beside EVA's
face if needs (Hunger, Sick or nature calls) arises.
void DrawCondition(unsigned
char Hungry,unsigned char Starve,unsigned char NeedToPee,unsigned char
Urgent,unsigned char Sick )
{
if(Hungry==1)
DrawFood();
if(NeedToPee==1)
DrawToilet();
if(Sick==1)
DrawSick();
if(Starve==1)
WriteHungry();
if(Urgent==1)
WriteLate();
}//void drawcondition