/*****************************************************
This program was produced by the
CodeWizardAVR V2.05.0 Professional
Automatic Program Generator
© Copyright 1998-2010 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 2012-05-16
Author  : 
Company : 
Comments: 


Chip type               : ATmega2560
Program type            : Application
AVR Core Clock frequency: 16.000000 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 2048
*****************************************************/

#include <mega2560.h>

#include <delay.h>

// Standard Input/Output functions
#include <stdio.h>
//------------------------------------------servo Motor
#define max ((1.5+0.8)*10)
#define min ((1.5-0.9)*10)
#define mideum (1.5*10) //¼­º¸¸ðÅÍÀÇ 90µµ À§Ä¡ÀÇ On-Time dury 1.5ms
#define duty 200
bit direction_flag;
char Pulse=0;
//------------------------------------------Stepping Motor
char cw[4]={0x11,0x44,0x22,0x88};
char ccw[4]={0x88,0x22,0x44,0x11};
bit Flag;
int Dir;
int Pulse_cnt;
//------------------------------------------DC Motor
#define CW1 PORTD.0
#define CWC1 PORTD.1
#define CW2 PORTD.2
#define CCW2 PORTD.3
#define EN1 PORTD.4
#define EN2 PORTD.5
unsigned int DCMotorduty=0;
unsigned int MotorDir=0;

//------------------------------------------Dotmatrix
#define PORT0 PORTH
#define PORT2 PORTK
flash unsigned int str[]={0xffff,0xe7ff,0xe7ff,0xe601,0xe601,0xe67f,0x867f,0x867f,0xe73f,0xe79f,0xe7cf,0xe7e7,0xe7f3,0xe7fb,0xe7ff,0xffff};  // °¡
flash unsigned int str1[]={0xffff,0xe7ff,0xe7ff,0xe601,0xe601,0xe67f,0x867f,0x867f,0xe73f,0xe79f,0xe7cf,0xe7e7,0xe7f3,0xe7fb,0xe7ff,0xffff}; // ³ª 
flash unsigned int str2[]={0xffff,0xfe7f,0xfe7f,0xfc3f,0xf99f,0xf3cf,0xe7e7,0xffff,0x8001,0x8001,0xfe7f,0xfe7f,0xfe7f,0xfe7f,0xfe7f,0xffff}; // ¼ö 
flash unsigned int str3[]={0xffff,0x9cf9,0x9cf9,0xccf9,0xe4f9,0xf0f9,0xf8f9,0xfcf9,0xf0f9,0xe4f9,0xccf9,0x9cf9,0x9c81,0x9c81,0xffff,0xffff}; // LK
flash unsigned int str4[]={0xffff,0xffff,0xffff,0xe3c7,0xddbb,0xffff,0xffff,0xffff,0xffff,0xf00f,0xf7ef,0xf7ef,0xfbdf,0xfc3f,0xffff,0xffff}; // SMILE 
flash unsigned int row[]={0x00001,0x00002,0x0004,0x0008,0x0010,0x0020,0x0040,0x0080,0x0100,0x0200,0x0400,0x0800,0x1000,0x2000,0x4000,0x8000,};
flash unsigned int str5[48][16]={   0xffff,0xffff,0xf607,0xf6ff,0xf6ff,0xf6ff,0xf6ff,0xc77f,0xf77f,0xf7bf,0xf7df,0xf7e7,0xf7ff,0xffff,0xffff,0xffff, //°¡
                                   0xffff,0xffff,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xc7f7,0xf7f7,0xf7f7,0xf7f7,0xf407,0xf7ff,0xffff,0xffff,0xffff, //³ª
                                   0xffff,0xffff,0xf607,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xc7f7,0xf7f7,0xf7f7,0xf7f7,0xf407,0xf7ff,0xffff,0xffff,0xffff, //´Ù 
                                   0xffff,0xffff,0xf607,0xf6ff,0xf6ff,0xf6ff,0xf607,0xc7f7,0xf7f7,0xf7f7,0xf7f7,0xf407,0xf7ff,0xffff,0xffff,0xffff, //¶ó 
                                   0xffff,0xffff,0xf607,0xf6f7,0xf6f7,0xf6f7,0xf6f7,0xc6f7,0xf6f7,0xf6f7,0xf6f7,0xf607,0xf7ff,0xffff,0xffff,0xffff, //¸¶      
                                   0xffff,0xffff,0xf6f7,0xf6f7,0xf6f7,0xf6f7,0xf607,0xc6f7,0xf6f7,0xf6f7,0xf6f7,0xf607,0xf7ff,0xffff,0xffff,0xffff, //¹Ù
                                   0xffff,0xffff,0xf7bf,0xf7bf,0xf7bf,0xf7bf,0xf7bf,0xc75f,0xf75f,0xf6ef,0xf6ef,0xf5f7,0xf7ff,0xffff,0xffff,0xffff, //»ç 
                                   0xffff,0xffff,0xf70f,0xf6f7,0xf6f7,0xf6f7,0xf6f7,0xc6f7,0xf6f7,0xf6f7,0xf6f7,0xf70f,0xf7ff,0xffff,0xffff,0xffff, //¾Æ         
                                   0xffff,0xffff,0xf407,0xf7bf,0xf7bf,0xf7bf,0xf7bf,0xc75f,0xf75f,0xf6ef,0xf6ef,0xf5f7,0xf7ff,0xffff,0xffff,0xffff, //ÀÚ  
                                   0xffff,0xffff,0xf607,0xf6ff,0xf6ff,0xf6ff,0xf607,0xc77f,0xf77f,0xf7bf,0xf7df,0xf7e7,0xf7ff,0xffff,0xffff,0xffff, //Ä«   
                                   0xffff,0xffff,0xf71f,0xf7ff,0xf407,0xf7bf,0xf7bf,0xc7bf,0xf75f,0xf6df,0xf5ef,0xf7f7,0xf7ff,0xffff,0xffff,0xffff, //Â÷            
                                   0xffff,0xffff,0xf607,0xf7f7,0xf7f7,0xf7f7,0xf607,0xc7f7,0xf7f7,0xf7f7,0xf7f7,0xf407,0xf7ff,0xffff,0xffff,0xffff, //Å¸     
                                   0xffff,0xffff,0xf407,0xf7ff,0xf76f,0xf76f,0xf76f,0xc76f,0xf76f,0xf76f,0xf76f,0xf407,0xf7ff,0xffff,0xffff,0xffff, //ÆÄ          
                                   0xffff,0xffff,0xf78f,0xf7ff,0xf603,0xf7ff,0xf78f,0xc777,0xf777,0xf777,0xf777,0xf78f,0xf7ff,0xffff,0xffff,0xffff, //ÇÏ  
                                   0xffff,0xffff,0xffbf,0xffbf,0xff5f,0xff5f,0xfeef,0xfeef,0xfe0f,0xfdf7,0xfdf7,0xfdf7,0xffff,0xffff,0xffff,0xffff, //A     
                                   0xffff,0xffff,0xff07,0xfef7,0xfef7,0xfef7,0xff07,0xfef7,0xfef7,0xfef7,0xfef7,0xff07,0xffff,0xffff,0xffff,0xffff, //B      
                                   0xffff,0xffff,0xfe1f,0xfdef,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfdef,0xfe1f,0xffff,0xffff,0xffff,0xffff, //C           
                                   0xffff,0xffff,0xff87,0xff77,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xff77,0xff87,0xffff,0xffff,0xffff,0xffff, //D       
                                   0xffff,0xffff,0xfe07,0xfff7,0xfff7,0xfff7,0xfe07,0xfff7,0xfff7,0xfff7,0xfff7,0xfe07,0xffff,0xffff,0xffff,0xffff, //E  
                                   0xffff,0xffff,0xfe07,0xfff7,0xfff7,0xfff7,0xff07,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xffff,0xffff,0xffff,0xffff, //F
                                   0xffff,0xffff,0xfe1f,0xfdef,0xfff7,0xfff7,0xfc37,0xfdf7,0xfdf7,0xfdf7,0xfcef,0xfd1f,0xffff,0xffff,0xffff,0xffff, //G  
                                   0xffff,0xffff,0xfef7,0xfef7,0xfef7,0xfef7,0xfe07,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xffff,0xffff,0xffff,0xffff, //H  
                                   0xffff,0xffff,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xffff,0xffff,0xffff,0xffff, //I 
                                   0xffff,0xffff,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffbb,0xffbb,0xffc7,0xffff,0xffff,0xffff,0xffff, //J  
                                   0xffff,0xffff,0xfef7,0xff77,0xffb7,0xffd7,0xffe7,0xffd7,0xffb7,0xff77,0xfef7,0xfdf7,0xffff,0xffff,0xffff,0xffff, //K             
                                   0xffff,0xffff,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfe07,0xffff,0xffff,0xffff,0xffff, //L        
                                   0xffff,0xffff,0xf7f7,0xf3e7,0xf3e7,0xf5d7,0xf5d7,0xf6b7,0xf6b7,0xf777,0xf777,0xf7f7,0xffff,0xffff,0xffff,0xffff, //M         
                                   0xffff,0xffff,0xfde7,0xfde7,0xfdd7,0xfdd7,0xfdb7,0xfdb7,0xfd77,0xfd77,0xfcf7,0xfcf7,0xffff,0xffff,0xffff,0xffff, //N     
                                   0xffff,0xffff,0xff1f,0xfeef,0xfdf7,0xfdf7,0xfdf7,0xfdf7,0xfdf7,0xfdf7,0xfeef,0xff1f,0xffff,0xffff,0xffff,0xffff, //O          
                                   0xffff,0xffff,0xff07,0xfef7,0xfef7,0xfef7,0xfef7,0xff07,0xfff7,0xfff7,0xfff7,0xfff7,0xffff,0xffff,0xffff,0xffff, //P  
                                   0xffff,0xffff,0xff1f,0xfeef,0xfdf7,0xfdf7,0xfdf7,0xfdf7,0xfdf7,0xfd77,0xfeef,0xfd1f,0xffff,0xffff,0xffff,0xffff, //Q   
                                   0xffff,0xffff,0xff07,0xfef7,0xfef7,0xfef7,0xff07,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xffff,0xffff,0xffff,0xffff, //R 
                                   0xffff,0xffff,0xff0f,0xfef7,0xfef7,0xfff7,0xffcf,0xff3f,0xfeff,0xfef7,0xfef7,0xff0f,0xffff,0xffff,0xffff,0xffff, //S        
                                   0xffff,0xffff,0xfc07,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffbf,0xffff,0xffff,0xffff,0xffff, //T 
                                   0xffff,0xffff,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xfef7,0xff0f,0xffff,0xffff,0xffff,0xffff, //U    
                                   0xffff,0xffff,0xfdf7,0xfdf7,0xfdf7,0xfeef,0xfeef,0xfeef,0xff5f,0xff5f,0xffbf,0xffbf,0xffff,0xffff,0xffff,0xffff, //V           
                                   0xffff,0xffff,0xf777,0xf777,0xf777,0xfaaf,0xfaaf,0xfaaf,0xfaaf,0xfddf,0xfddf,0xfddf,0xffff,0xffff,0xffff,0xffff, //W
                                   0xffff,0xffff,0xfdf7,0xfdf7,0xfeef,0xff5f,0xffbf,0xffbf,0xff5f,0xfeef,0xfdf7,0xfdf7,0xffff,0xffff,0xffff,0xffff, //X
                                   0xffff,0xffff,0xfdf7,0xfdf7,0xfeef,0xfeef,0xff5f,0xff5f,0xffbf,0xffbf,0xffbf,0xffbf,0xffff,0xffff,0xffff,0xffff, //Y 
                                   0xffff,0xffff,0xfe07,0xfeff,0xff7f,0xffbf,0xffbf,0xffdf,0xffef,0xffef,0xfff7,0xfe07,0xffff,0xffff,0xffff,0xffff, //Z  
                                   0xffff,0xffff,0xf407,0xf7bf,0xf7bf,0xc75f,0xf6ef,0xf5f7,0xffff,0xf00f,0xf7ff,0xf7ff,0xf7ff,0xffff,0xffff,0xffff, //ÀÛ                                 
                                   0xffff,0xffff,0xf7bf,0xf7bf,0xf09f,0xf75f,0xf6ef,0xf5f7,0xffff,0xf81f,0xf7ef,0xf7ef,0xf81f,0xffff,0xffff,0xffff, //¼º  
                                   0xffff,0xffff,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfff7,0xfe07,0xffff,0xffff,0xffff,0xffff, //L                                     
                                   0xffff,0xffff,0xfef7,0xff77,0xffb7,0xffd7,0xffe7,0xffd7,0xffb7,0xff77,0xfef7,0xfdf7,0xffff,0xffff,0xffff,0xffff, //K                                   
                                   0xffff,0xffff,0xf70f,0xf6f7,0xf6f7,0xf6f7,0xf70f,0xf7ff,0xffff,0xf00f,0xf7ef,0xf7ef,0xf00f,0xffff,0xffff,0xffff, //ÀÓ                                        
                                   0xffff,0xffff,0xf5b7,0xf5b7,0xf5b7,0xf5b7,0xf407,0xf5b7,0xf5b7,0xf5b7,0xf5b7,0xf587,0xf5ff,0xffff,0xffff,0xffff, //º£                          
                                   0xffff,0xffff,0xf607,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xf7f7,0xf407,0xf7ff,0xffff,0xffff,0xffff, //µð                           
                                   0xffff,0xffff,0xf00f,0xffef,0xffef,0xffef,0xffef,0xf00f,0xffff,0xffff,0xffff,0xe007,0xffff,0xffff,0xffff,0xffff,  //µå
                                   };
#define OrangeLed_Clk0 0xfe
#define OrangeLed_Clk1 0xfd

#define RedLed_Clk0 0xfb
#define RedLed_Clk1 0xf7

#define Row_Clk0 0xef
#define Row_Clk1 0xdf

#define CP_Enable 0xFF
#if 0
74hc574¿¡ ±¸µ¿½ÅÈ£´Â Low to HighÀÌ´Ù.
#endif
#define MoveSpeed 10
bit Toggle=0;
int timeCnt=0;

//------------------------------------------GLCD
//---------------------------------------------
#define lcd_dt PORTJ
#define RW     PORTA.1
#define lcd_en PORTA.2
#define lcd_di PORTA.0
#define lcd_s2 PORTA.5
#define lcd_s1 PORTA.4
#define rst    PORTA.6
//----------------------------------------------------
unsigned char screen[8][128];
bit flg;
char bf;
struct {
   char bf, x, y, ty;
}  lcd;
bit lcd_pg, lcd_blk;
flash char han[62][24]={

0x00,0xfe,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //L  0
0x00,0x0f,0x0f,0x0c,0x0c,0x0c,0x0c,0x0c,0x00,0x00,0x00,0x00,


0x00,0xfe,0xfe,0xe0,0xb0,0x18,0x0c,0x06,0x02,0x00,0x00,0x00, //K
0x00,0x0f,0x0f,0x00,0x01,0x03,0x06,0x0c,0x08,0x00,0x00,0x00,


0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x00,0x00,0xfc,0x00,0x00, //ÀÓ  2
0x00,0x00,0x1e,0x12,0x12,0x12,0x12,0x12,0x12,0x1e,0x00,0x00,

0x00,0xfc,0x40,0x40,0xfc,0x40,0x40,0xfc,0x00,0xfc,0x00,0x00, //º£  3
0x00,0x0f,0x08,0x08,0x0f,0x00,0x00,0x1f,0x00,0x1f,0x00,0x00,

0x00,0xfc,0x04,0x04,0x04,0x04,0x04,0x00,0x00,0xfc,0x00,0x00, //µð   4
0x00,0x0f,0x08,0x08,0x08,0x08,0x08,0x08,0x00,0x1f,0x00,0x00,

0x00,0x00,0xfc,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x00,0x00, //µå   5
0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,

0x00,0x04,0x04,0xfc,0x04,0x44,0x40,0xfc,0x00,0xfc,0x00,0x00, //Á¦   6
0x00,0x0c,0x03,0x00,0x03,0x0c,0x00,0x1f,0x00,0x1f,0x00,0x00,

0x00,0x80,0xa4,0xa4,0xbc,0xa4,0xa4,0xbc,0xa4,0xa4,0x80,0x00, //Ç°   7
0x00,0x00,0x1e,0x12,0x12,0x12,0x13,0x12,0x12,0x1e,0x00,0x00,

0x00,0x04,0x04,0x04,0xfc,0x00,0xfc,0x80,0x80,0xfc,0x00,0x00, //°³   8
0x00,0x08,0x04,0x03,0x00,0x00,0x1f,0x00,0x00,0x1f,0x00,0x00,

0x00,0x7c,0x48,0x48,0x48,0x48,0x7c,0x00,0x00,0x7c,0x10,0x10, //¹ß   9
0x00,0x00,0x1d,0x15,0x15,0x15,0x15,0x15,0x15,0x17,0x00,0x00,

0x00,0xf8,0x04,0x04,0x04,0x04,0xf8,0x00,0x00,0xfc,0x00,0x00, //ÀÌ   10
0x00,0x07,0x08,0x08,0x08,0x08,0x07,0x00,0x00,0x1f,0x00,0x00,

0x00,0x84,0x84,0x84,0x44,0x24,0x5c,0x48,0x48,0xfc,0x00,0x00, //°æ   11
0x00,0x00,0x0c,0x12,0x12,0x12,0x12,0x12,0x12,0x0c,0x00,0x00,

0x00,0x7c,0x40,0x40,0x40,0x40,0x40,0x40,0x00,0xfc,0x10,0x10, //³²   12
0x00,0x00,0x1e,0x12,0x12,0x12,0x12,0x12,0x12,0x1e,0x00,0x00,

0x00,0x00,0xc0,0x30,0x0c,0x30,0xc0,0x00,0x00,0x00,0x00,0x00, //A    13
0x00,0x0e,0x01,0x01,0x01,0x01,0x01,0x0e,0x00,0x00,0x00,0x00,

0x00,0x1c,0xe0,0x00,0x00,0x00,0xe0,0x1c,0x00,0x00,0x00,0x00, //V    14
0x00,0x00,0x00,0x03,0x0c,0x03,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xfc,0x44,0x44,0x44,0x44,0xb8,0x00,0x00,0x00,0x00,0x00, //R   15
0x00,0x0f,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,

0x00,0xfc,0x84,0x84,0x84,0x84,0x78,0x00,0x00,0x00,0x00,0x00, //P   16
0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0xfc,0x00,0x00,0x00,0x00,0x00,0x00, //I   17
0x00,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xf0,0x08,0x04,0x04,0x04,0x04,0x08,0x00,0x00,0x00,0x00, //C   18
0x00,0x03,0x04,0x08,0x08,0x08,0x08,0x04,0x00,0x00,0x00,0x00,

0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //,   19
0x00,0x10,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xfc,0x84,0x84,0x84,0x84,0x78,0x00,0x00,0x00,0x00,0x00, //P   20
0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0xc0,0x30,0x0c,0x30,0xc0,0x00,0x00,0x00,0x00,0x00, //A   21
0x00,0x0e,0x01,0x01,0x01,0x01,0x01,0x0e,0x00,0x00,0x00,0x00,

0x00,0xfc,0x04,0x04,0x04,0x08,0xf0,0x00,0x00,0x00,0x00,0x00, //D    22
0x00,0x0f,0x08,0x08,0x08,0x04,0x03,0x00,0x00,0x00,0x00,0x00,

0x00,0x38,0x44,0x44,0x84,0x84,0x18,0x00,0x00,0x00,0x00,0x00, //S    23
0x00,0x06,0x08,0x08,0x08,0x08,0x07,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0x04,0xc4,0x04,0x04,0xc4,0x04,0x04,0xfc,0x00,0x00, //±³   24
0x00,0x08,0x08,0x0f,0x08,0x08,0x0f,0x08,0x0a,0x09,0x08,0x00,

0x00,0x80,0x98,0xa4,0xa4,0xa4,0xa4,0xa4,0xa4,0x98,0x80,0x00, //À°   25
0x00,0x00,0x02,0x03,0x02,0x02,0x02,0x02,0x03,0x1e,0x00,0x00,

0x00,0x04,0x84,0x64,0x1c,0x24,0x44,0x94,0x10,0xfc,0x00,0x00, //Àü   26
0x00,0x01,0x1c,0x10,0x10,0x10,0x10,0x10,0x10,0x13,0x00,0x00,

0x00,0x00,0x3c,0x24,0x24,0x24,0x24,0x24,0x24,0x3c,0x00,0x00, //¹®  27
0x00,0x01,0x1d,0x11,0x11,0x11,0x17,0x11,0x11,0x11,0x01,0x00,


0x00,0x84,0x84,0x84,0x44,0x24,0x1c,0x00,0x00,0xfc,0x20,0x20, //°­  28
0x00,0x00,0x0c,0x12,0x12,0x12,0x12,0x12,0x12,0x0c,0x00,0x00,

0x00,0x00,0x00,0x80,0x7c,0x80,0x00,0x00,0x00,0xfc,0x80,0x80, //»ç  29
0x00,0x08,0x06,0x01,0x00,0x01,0x06,0x08,0x00,0x1f,0x00,0x00,

0x00,0x04,0x84,0x64,0x1c,0x24,0x44,0x94,0x10,0xfc,0x00,0x00, //Àü  30
0x00,0x01,0x1c,0x10,0x10,0x10,0x10,0x10,0x10,0x13,0x00,0x00,

0x00,0x04,0x04,0x84,0x7c,0x84,0x04,0x04,0x00,0xfc,0x80,0x80, //ÀÚ   31
0x00,0x08,0x06,0x01,0x00,0x01,0x06,0x08,0x00,0x1f,0x00,0x00,

0x00,0x04,0x04,0x04,0xfc,0x00,0xfc,0x80,0x80,0xfc,0x00,0x00, //°³   32
0x00,0x08,0x04,0x03,0x00,0x00,0x1f,0x00,0x00,0x1f,0x00,0x00,

0x00,0x7c,0x48,0x48,0x48,0x48,0x7c,0x00,0x00,0x7c,0x10,0x10, //¹ß   33
0x00,0x00,0x1d,0x15,0x15,0x15,0x15,0x15,0x15,0x17,0x00,0x00,

0x00,0x80,0x98,0xe4,0xa4,0xa4,0xa4,0xa4,0xe4,0x98,0x80,0x00, //¿ë   34
0x00,0x00,0x0c,0x12,0x12,0x12,0x12,0x12,0x12,0x0c,0x00,0x00,

0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x28,0x28,0xfc,0x00,0x00, //¿ª   35
0x00,0x00,0x02,0x02,0x02,0x02,0x02,0x02,0x02,0x1e,0x00,0x00,

0x00,0xfc,0x04,0x04,0x04,0x04,0xfc,0x00,0x00,0xfc,0x80,0x80, //¸¶   36
0x00,0x0f,0x08,0x08,0x08,0x08,0x0f,0x00,0x00,0x1f,0x00,0x00,

0x00,0xf8,0x04,0x04,0x04,0x04,0xf8,0x00,0x00,0xfc,0x00,0x00, //ÀÌ   37
0x00,0x07,0x08,0x08,0x08,0x08,0x07,0x00,0x00,0x1f,0x00,0x00,

0x00,0x94,0x94,0x94,0x54,0x34,0x1c,0x10,0x10,0xfc,0x00,0x00, //ÄÄ   38
0x00,0x00,0x1e,0x12,0x12,0x12,0x12,0x12,0x12,0x1e,0x00,0x00,

0x00,0x04,0x04,0xfc,0x04,0x44,0x40,0xfc,0x00,0xfc,0x00,0x00, //Á¦   39
0x00,0x0c,0x03,0x00,0x03,0x0c,0x00,0x1f,0x00,0x1f,0x00,0x00,

0x00,0xf8,0x04,0x04,0x04,0x04,0xf8,0x40,0x40,0xfc,0x00,0x00, //¾î   40
0x00,0x07,0x08,0x08,0x08,0x08,0x07,0x00,0x00,0x1f,0x00,0x00,

0x00,0x00,0x80,0x60,0x1c,0x20,0x40,0x80,0x00,0xfc,0x00,0x00, //½Å   41
0x00,0x01,0x1c,0x10,0x10,0x10,0x10,0x10,0x10,0x13,0x00,0x00,

0x00,0x04,0x04,0xfc,0x04,0x44,0x40,0xfc,0x00,0xfc,0x00,0x00, //Á¦   42
0x00,0x0c,0x03,0x00,0x03,0x0c,0x00,0x1f,0x00,0x1f,0x00,0x00,

0x00,0x80,0xa4,0xa4,0xbc,0xa4,0xa4,0xbc,0xa4,0xa4,0x80,0x00, //Ç°   43
0x00,0x00,0x1e,0x12,0x12,0x12,0x13,0x12,0x12,0x1e,0x00,0x00,

0x00,0x04,0x04,0x04,0xfc,0x00,0xfc,0x80,0x80,0xfc,0x00,0x00, //°³   44
0x00,0x08,0x04,0x03,0x00,0x00,0x1f,0x00,0x00,0x1f,0x00,0x00,

0x00,0x7c,0x48,0x48,0x48,0x48,0x7c,0x00,0x00,0x7c,0x10,0x10, //¹ß   45
0x00,0x00,0x1d,0x15,0x15,0x15,0x15,0x15,0x15,0x17,0x00,0x00,

0x00,0xfc,0x44,0x44,0x44,0x44,0xb8,0x00,0x00,0x00,0x00,0x00, //R    46
0x00,0x0f,0x00,0x00,0x00,0x00,0x0f,0x00,0x00,0x00,0x00,0x00,

0x00,0xfc,0x18,0x60,0x80,0x00,0x80,0x60,0x18,0xfc,0x00,0x00, //M    47
0x00,0x0f,0x00,0x00,0x01,0x06,0x01,0x00,0x00,0x0f,0x00,0x00,

0x00,0x10,0x90,0x54,0x54,0x54,0x90,0x10,0x00,0xfc,0x00,0x00, //È¸   48
0x00,0x08,0x09,0x0a,0x0e,0x0a,0x09,0x08,0x00,0x1f,0x00,0x00,

0x00,0x00,0xe4,0x24,0x24,0x24,0x24,0x24,0x24,0x3c,0x00,0x00, //·Î   49
0x00,0x08,0x09,0x09,0x09,0x09,0x0f,0x09,0x09,0x09,0x08,0x00,

0x00,0x80,0x40,0x30,0x1c,0x20,0x50,0x10,0x10,0x7c,0x00,0x00, //¼³   50
0x00,0x00,0x1d,0x15,0x15,0x15,0x15,0x15,0x15,0x17,0x00,0x00,

0x00,0x04,0x04,0x04,0xfc,0x10,0x10,0xfc,0x00,0xfc,0x00,0x00, //°è   51
0x00,0x08,0x04,0x03,0x00,0x01,0x01,0x1f,0x00,0x1f,0x00,0x00,

0x00,0x84,0x84,0xfc,0x84,0xfc,0x84,0x94,0x10,0xfc,0x00,0x00, //Æß   52
0x00,0x00,0x1e,0x12,0x12,0x12,0x12,0x12,0x12,0x1e,0x00,0x00,

0x00,0x38,0x44,0x44,0x44,0x38,0x00,0xfc,0x00,0xfc,0x00,0x00, //¿þ   53
0x00,0x01,0x09,0x07,0x01,0x05,0x04,0x1f,0x00,0x1f,0x00,0x00,

0x00,0xf8,0x04,0x04,0x04,0x04,0xf8,0x40,0x40,0xfc,0x00,0x00, //¾î   54
0x00,0x07,0x08,0x08,0x08,0x08,0x07,0x00,0x00,0x1f,0x00,0x00,

0x00,0xfc,0x84,0x84,0x84,0x84,0x78,0x00,0x00,0x00,0x00,0x00, //P    55
0x00,0x0f,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0xf0,0x08,0x04,0x04,0x04,0x04,0x08,0x00,0x00,0x00,0x00, //C   56
0x00,0x03,0x04,0x08,0x08,0x08,0x08,0x04,0x00,0x00,0x00,0x00,

0x00,0xfc,0x44,0x44,0x44,0x44,0xb8,0x00,0x00,0x00,0x00,0x00, //B   57
0x00,0x0f,0x08,0x08,0x08,0x08,0x07,0x00,0x00,0x00,0x00,0x00,

0x00,0xe0,0x18,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //(   58
0x00,0x03,0x0c,0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x04,0x18,0xe0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, //)   59
0x00,0x10,0x0c,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,

0x00,0x00,0xfc,0x90,0x90,0x90,0x90,0x90,0x90,0xfc,0x00,0x00, //º¸    60
0x00,0x08,0x08,0x08,0x08,0x08,0x0f,0x08,0x08,0x08,0x08,0x00,

0x00,0x00,0xfc,0x84,0x84,0x84,0x84,0x84,0x84,0x84,0x00,0x00, //µå    61
0x00,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x00,




};
char SecCnt=0;
bit SecFlag;

// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
 static int cnt,cnt2,cnt3,cnt4,cnt5=0;
    cnt++;cnt2++;
    if(cnt==2)//2ms¸¶´Ù 
    { 
        Pulse_cnt++; // Pulse Count!
        if(Pulse_cnt==4)
        {
        Pulse_cnt=0;
        }
        cnt=0;
    }     
    if(cnt2==3000)
    {
		Dir^=1;    
        cnt2=0;
    }
    
    cnt3++;cnt4++;     
    if(cnt3==duty)
    {
      EN1=EN2=0;
    }   
    if(cnt3==50)
    {
      EN1=EN2=1;   
      cnt3=0;
    }    
    if(cnt4==500)
    {
        DCMotorduty++; 
        if(DCMotorduty>50) 
        {
            DCMotorduty=1;// pwm pluseÀÇ initialization value
            MotorDir^=1;  //direction Select variable value 
         
        }
        cnt4=0;
    } 
    cnt5++;
    if(cnt5>=1000)
    {
    SecCnt++;
    SecFlag^=1;
    cnt5=0;
        if(SecCnt>=10)
        {
         SecCnt=0;

        }
    }         
    


    switch(Dir)
    {
    case 0:PORTL=ccw[Pulse_cnt];break; //forward direction
    case 1:PORTL=cw[Pulse_cnt];break; //reverse direction      
    }   
    TCNT0+=0x06;

  //printf("UART0 Serial Output Test\r\n");
}

// Timer2 overflow interrupt service routine
interrupt [TIM2_OVF] void timer2_ovf_isr(void)
{
static unsigned int cnt,cnt2,cnt3=0;    
    cnt2++;
    cnt++;       
    if(cnt2==20000)// 2ÃÊ ?
    {           
       Pulse=min;
       }  
    if(cnt2==40000)// 4ÃÊ ?
    {           
       Pulse=max; 
       cnt2=0;
       }
    if(cnt==Pulse)
    {
    PORTB.0=0; 
    PORTB.1=0;
    PORTB.2=0;
    PORTB.3=0;
    }             
    if(cnt==duty)
    {
    PORTB.0=1;
    PORTB.1=1;
    PORTB.2=1;
    PORTB.3=1;
    cnt=0;
    }  
    


 TCNT2+=0xe7;//100uS Tick Time
}

#define ADC_VREF_TYPE 0x40

// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=(adc_input & 0x1f) | (ADC_VREF_TYPE & 0xff);
if (adc_input & 0x20) ADCSRB |= 0x08;
else ADCSRB &= 0xf7;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}

void reverse_dis() //¹ÝÀüÇÏ¸é¼­ ½ÃÇÁÆ® µ¿ÀÛ Function
{
        int i,j,k,l=0;     
        static int sum,rowsum=0;
        static unsigned int buff[];   
        #if 1
        for(j=15;j>=1;j--){ 
        for(i=0;i<16;i++){
        buff[i]=str5[timeCnt][i]>>j; //¹®ÀÚ¸¦ ÁÂÃø »çÀÌµå¿¡¼­ Áß¾ÓÀ¸¿ì·Î ½ÃÇÁÆ® ÇÔ       
   
        switch(j){   //¹®ÀÚ°¡ ÀÌµ¿½Ã¿¡ ¿©¹é¿¡ led¸¦ offÇÏ±â À§ÇÑ Á¶°ÇÀÌ´Ù. ÀÌÇØ°¡ ¾È µÉ½Ã¿¡´Â switch¹®ÀåÀ» ÁÖ¼®Ã³¸® ÇÏ¿© ½ÇÇèÇØº¸¸é ¾Ë¼ö ÀÖÀ»°ÍÀÌ´Ù    
        case 15:
        for(l=0;l<16;l++){buff[l]|=0xfffe;} break;
        case 14:
        for(l=0;l<16;l++){buff[l]|=0xfffc;} break;
        case 13:
        for(l=0;l<16;l++){buff[l]|=0xfff8;} break;
        case 12:
        for(l=0;l<16;l++){buff[l]|=0xfff0;} break;  
        case 11:
        for(l=0;l<16;l++){buff[l]|=0xffe0;} break;   
        case 10:
        for(l=0;l<16;l++){buff[l]|=0xffc0;} break;
        case 9:
        for(l=0;l<168;l++){buff[l]|=0xff80;} break;
        case 8:
        for(l=0;l<16;l++){buff[l]|=0xff00;} break;
        case 7:
        for(l=0;l<16;l++){buff[l]|=0xfe00;} break;
        case 6:
        for(l=0;l<16;l++){buff[l]|=0xfc00;}break;
        case 5:
        for(l=0;l<16;l++){buff[l]|=0xf800;} break;
        case 4:
        for(l=0;l<16;l++){buff[l]|=0xf000;} break;
        case 3:
        for(l=0;l<16;l++){buff[l]|=0xe000;}break;
        case 2:
        for(l=0;l<16;l++){buff[l]|=0xc000;}break;
        case 1:
        for(l=0;l<16;l++){buff[l]|=0x8000;}break;
        }

        }      
        for(k=0;k<MoveSpeed;k++){        
             for(i=0;i<16;i++){           
                if(Toggle){                         
                PORT0=0xff; 
                PORT2=OrangeLed_Clk0;                  
                PORT2=CP_Enable;                     
    
                PORT0=0xff;
                PORT2=OrangeLed_Clk1;                  
                PORT2=CP_Enable;                     
                           
                sum=buff[i];             
                PORT0=(sum&0xff);
                PORT2=RedLed_Clk0;                  
                PORT2=CP_Enable;                  
                       
                PORT0=(sum>>8);
                PORT2=RedLed_Clk1;                  
                PORT2=CP_Enable;    
                } 
                else
                {
                sum=buff[i];                   
                PORT0=sum&0xff;
                PORT2=OrangeLed_Clk0;                  
                PORT2=CP_Enable;                   
                              
                PORT0=sum>>8;
                PORT2=OrangeLed_Clk1;                  
                PORT2=CP_Enable; 
                   
                PORT0=0xff;
                PORT2=RedLed_Clk0;                  
                PORT2=CP_Enable;                  
                           
                           
                PORT0=0xff;
                PORT2=RedLed_Clk1;                  
                PORT2=CP_Enable;    
                }     
        
           
                rowsum=row[i];              
                PORT0=rowsum&0xff;
                PORT2=Row_Clk0;                  
                PORT2=CP_Enable;
                    
                            
                PORT0=rowsum>>8;
                PORT2=Row_Clk1;                  
                PORT2=CP_Enable;
                delay_ms(1);
                
            }
        }

     }
     #endif                 
     
     for(j=0;j<16;j++){ 
        for(i=0;i<16;i++){   //¹®ÀÚ¸¦ Áß¾Ó¿¡¼­ ¿ìÃøÀ¸·Î ½ÃÇÁÆ® ÇÔ       
        buff[i]=str5[timeCnt][i]<<j;
        switch(j){    //¹®ÀÚ°¡ ÀÌµ¿½Ã¿¡ ¿©¹é¿¡ led¸¦ offÇÏ±â À§ÇÑ Á¶°ÇÀÌ´Ù. ÀÌÇØ°¡ ¾È µÉ½Ã¿¡´Â switch¹®ÀåÀ» ÁÖ¼®Ã³¸® ÇÏ¿© ½ÇÇèÇØº¸¸é ¾Ë¼ö ÀÖÀ»°ÍÀÌ´Ù.                */
         case 15:for(l=0;l<16;l++){buff[l]|=0xffff;} break;
        case 14:for(l=0;l<16;l++){buff[l]|=0x7fff;}break;
        case 13:for(l=0;l<16;l++){buff[l]|=0x3fff;} break;
        case 12:for(l=0;l<16;l++){buff[l]|=0x1fff;} break;
        case 11:for(l=0;l<16;l++){buff[l]|=0x0fff;}break;
        case 10:for(l=0;l<16;l++){buff[l]|=0x07ff;}break;
        case 9:for(l=0;l<16;l++){buff[l]|=0x03ff;}break;
        case 8:for(l=0;l<16;l++){buff[l]|=0x01ff;}break;    
        case 7:for(l=0;l<16;l++){buff[l]|=0x00ff;} break;
        case 6:for(l=0;l<16;l++){buff[l]|=0x007f;}break;
        case 5:for(l=0;l<16;l++){buff[l]|=0x003f;} break;
        case 4:for(l=0;l<16;l++){buff[l]|=0x001f;} break;
        case 3:for(l=0;l<16;l++){buff[l]|=0x000f;}break;
        case 2:for(l=0;l<16;l++){buff[l]|=0x0007;}break;
        case 1:for(l=0;l<16;l++){buff[l]|=0x0003;}break;
        case 0:for(l=0;l<16;l++){buff[l]|=0x0001;}break;   
               
           }              
      }      
      
         for(k=0;k<MoveSpeed;k++){        
             for(i=0;i<16;i++){           
               if(Toggle){                            
                PORT0=0xff; 
                PORT2=OrangeLed_Clk0;                  
                PORT2=CP_Enable;                     
    
                PORT0=0xff;
                PORT2=OrangeLed_Clk1;                  
                PORT2=CP_Enable;                     
                           
                sum=buff[i];             
                PORT0=(sum&0xff);
                PORT2=RedLed_Clk0;                  
                PORT2=CP_Enable;                  
                       
                PORT0=(sum>>8);
                PORT2=RedLed_Clk1;                  
                PORT2=CP_Enable;    
                } 
                else
                {
                PORT0=0xff;
                PORT2=RedLed_Clk0;                  
                PORT2=CP_Enable;                  
                           
                           
                PORT0=0xff;
                PORT2=RedLed_Clk1;                  
                PORT2=CP_Enable;    
                
                sum=buff[i];                   
                PORT0=(sum&0xff);
                PORT2=OrangeLed_Clk0;                  
                PORT2=CP_Enable;                   
                              
                PORT0=(sum>>8);
                PORT2=OrangeLed_Clk1;                  
                PORT2=CP_Enable;   
                }     
        
           
                rowsum=row[i];              
                PORT0=rowsum&0xff;
                PORT2=Row_Clk0;                  
                PORT2=CP_Enable;
                    
                            
                PORT0=rowsum>>8;
                PORT2=Row_Clk1;                  
                PORT2=CP_Enable;
                delay_ms(1);
                
            }
        }
      
    }           
    timeCnt++; //¹®ÀÚ°¡ µµÆ®¸ÅÆ®¸¯½º¿¡¼­ »ç¶óÁö¸é ´ÙÀ½ ¹®ÀÚ·Î ¹Ù²ï´Ù   
    Toggle^=1;
        if(timeCnt==48)
    {
        timeCnt=0;
        }
     
}
//----------------------------------------------------
char gbuf[128][8];
//----------------------------------------------------
//----------------------------------------------------
void dsp_str(char n)
{
   delay_us(30); lcd_di=1; lcd_dt=n; //data
   lcd_en=1; #asm("nop"); lcd_en=0;  //on->off
}
//----------------------------------------------------
void dsp_cmd(char n)
{
   delay_us(30); lcd_di=0; lcd_dt=n; //data
   lcd_en=1; #asm("nop"); lcd_en=0;  //on->off
}
//----------------------------------------------------
void lcd_init()
{
   lcd_s1=1;
   lcd_s2=1; //page0,1
   dsp_cmd(0x3f);
   dsp_cmd(0xc0);
}
//----------------------------------------------------
void set_page0() { lcd.x=0x40; lcd_pg=0; }
void set_page1() { lcd.x=0x40; lcd_pg=1; }

void dsp_addr()
{
   if(lcd_pg) { lcd_s1=0; lcd_s2=1; } //page1?
   else       { lcd_s1=1; lcd_s2=0; } //page0
   dsp_cmd(lcd.y);
   dsp_cmd(lcd.x);
}
 void dsp_nul(char n)
{
   char i; dsp_addr();
   for(i=0; i<n; ++i)///64°³ÀÇ ¿­À» Å¬¸®¾î ½ÃÅ²´Ù.
   dsp_str(0);
}
void dsp_nul2(char n)
{
   char i;
   dsp_addr(); //ÇöÀç ÁÂÇ¥ Ãâ·Â
   lcd.bf=0;  //°ø¹éÀ¸·Î Ã¤¿ò
   if(lcd_blk)
   lcd.bf=~lcd.bf;
   for(i=0; i<n; ++i) //n°ª¸¸Å­ Áõ°¡ÇÏ¸é Ãâ·Â
    dsp_str(lcd.bf);
   ++lcd.y;// xÃàÁÂÇ¥ÀÇ °ª Áõ°¡ 2¹øÂ° ¿­µµ °ø¹éÀ¸·Î Ãâ·Â
    dsp_addr();
    lcd.bf=0;
   if(lcd_blk)
   { lcd.bf=~lcd.bf; lcd.bf&=~0x80; }
   for(i=0; i<n; ++i)
   dsp_str(lcd.bf);
   lcd.x+=n; //yÃàÀº n°ª ¸¸Å­ Áõ°¡!
   lcd.y=lcd.ty;
}
void lcd_clear()
{
   char i;
   lcd.x=0x40; lcd.y=0xb8;
   for(i=0; i<8; ++i) {
     lcd_pg=0;
     dsp_nul(64);
     lcd_pg=1;
      dsp_nul(64);
     ++lcd.y;


   }
}
void dsp_han(flash char *p, char n)
{
   char i, bf1, bf2;
   static int cnt=0;
     static int cnt2=0;
      static int cnt3=0;
   bf1=n*12;//Ã¹¹øÂ° ¹®ÀÚ¿­ÀÇ Å©±â¸¦ È®ÀÎ
   dsp_addr();///ÇöÀç ÁÂÇ¥ È®ÀÎ
   for(i=0; i<bf1; ++i) {  //¹®ÀÚ¿­ÀÇ Å©±â¸¸Å­ ¹®ÀÚ Ãâ·Â
      lcd.bf=p[i];
      if(lcd_blk) lcd.bf=~lcd.bf; //¹ÝÀü Ãâ·Â ¿©ºÎ
       dsp_str(lcd.bf); //µ¥ÀÌÅ¸ Ãâ·Â
   }
    bf2=bf1*2;  //2¹øÂ° ¿­ÀÇ Å©±â °è»ê
    ++lcd.y; //lcd y adrees 0xb9 2¹øÂ° ¿­ °è»ê
    dsp_addr(); ///ÇöÀç ÁÂÇ¥ È®ÀÎ
   for(i=bf1; i<bf2; ++i) {
      lcd.bf=p[i];
      if(lcd_blk)
       { lcd.bf=~lcd.bf; lcd.bf&=~0x80; }
        dsp_str(lcd.bf);
   }

   lcd.x+=bf1; //lcd y addressÀÇ °ªÀ» 0x4c·Î ¹Ù…d ÁÜ, ´ÙÀ½ ¹®ÀÚÀÇ ½ÃÀÛÁÂÇ¥¸¦ ±â¾ï ÇÔ
   lcd.y=lcd.ty; //lcd xÁÂÇ¥ 0xb8À» ÀúÀå
}
void first()
{
    set_page0();
    lcd.ty=lcd.y=0xb8;///Ã¹¹øÂ° ¶óÀÎ
    lcd_blk=1;
    dsp_nul2(28);
    dsp_han(han[0],1);
    dsp_han(han[1],1);
    dsp_han(han[2],1);

    set_page1();
    lcd.ty=lcd.y=0xb8;
    lcd_blk=1;
    dsp_han(han[3],1);
    dsp_han(han[4],1);
    dsp_han(han[5],1); dsp_nul2(28);

}
void second()
{
    switch(SecCnt)
    {
    case 0: //avr
    set_page0();
    lcd.ty=lcd.y=0xba; //2¹øÂ° ¶óÀÎ 
    lcd_blk=0;
    dsp_nul2(16);
    dsp_han(han[30],1);
    dsp_han(han[31],1);
    dsp_han(han[32],1);
    dsp_han(han[33],1);
    set_page1();
    lcd.ty=lcd.y=0xba;
    lcd_blk=0;
    dsp_han(han[34],1);
    dsp_han(han[35],1);
    dsp_han(han[26],1);
    dsp_han(han[27],1);
    dsp_nul2(16);
    break;
    case 5:
    set_page0();
    lcd.ty=lcd.y=0xba; //2¹øÂ° ¶óÀÎ 
    lcd_blk=0;
    dsp_nul2(16);
    dsp_han(han[36],1);
    dsp_han(han[37],1);
    dsp_han(han[38],1);
    dsp_han(han[39],1);
    set_page1();
    lcd.ty=lcd.y=0xba;
    lcd_blk=0;
     dsp_han(han[40],1);
    dsp_han(han[60],1);
    dsp_han(han[61],1);
    dsp_han(han[44],1);
    dsp_han(han[45],1);
    dsp_nul2(3);
    break;
    }


}

void third()
{
    switch(SecCnt)
    {
    case 0: //avr
    set_page0();
    lcd.ty=lcd.y=0xbc; //3¹øÂ° ¶óÀÎ
    lcd_blk=1;
     dsp_nul2(4);
    dsp_han(han[13],1);
    dsp_han(han[14],1);
    dsp_han(han[15],1);
    dsp_han(han[52],1);
    dsp_han(han[53],1);
    set_page1();
    lcd.ty=lcd.y=0xbc;
    lcd_blk=1;

    dsp_han(han[54],1);
    dsp_han(han[26],1);
    dsp_han(han[27],1);
    dsp_han(han[24],1);
    dsp_han(han[25],1);
    dsp_nul2(5);
    break;
    
    case 2: //pic
    set_page0();
    lcd.ty=lcd.y=0xbc; //3¹øÂ° ¶óÀÎ
    lcd_blk=1;
     dsp_nul2(4);
    dsp_han(han[16],1);
    dsp_han(han[17],1);
    dsp_han(han[18],1);
    dsp_han(han[52],1);
    dsp_han(han[53],1);
    set_page1();
    lcd.ty=lcd.y=0xbc;
    lcd_blk=1;

    dsp_han(han[54],1);
    dsp_han(han[26],1);
    dsp_han(han[27],1);
    dsp_han(han[24],1);
    dsp_han(han[25],1);
    dsp_nul2(5);
    break;
    case 4: //arm
    set_page0();
    lcd.ty=lcd.y=0xbc; //3¹øÂ° ¶óÀÎ
    lcd_blk=1;
     dsp_nul2(4);
    dsp_han(han[21],1);
    dsp_han(han[46],1);
    dsp_han(han[47],1);
    dsp_han(han[52],1);
    dsp_han(han[53],1);
    set_page1();
    lcd.ty=lcd.y=0xbc;
    lcd_blk=1;

    dsp_han(han[54],1);
    dsp_han(han[26],1);
    dsp_han(han[27],1);
    dsp_han(han[24],1);
    dsp_han(han[25],1);
    dsp_nul2(5);
    break;
    
    case 6: //pcb¼³°è 
    set_page0();
    lcd.ty=lcd.y=0xbc; //3¹øÂ° ¶óÀÎ
    lcd_blk=1;
     dsp_nul2(4);
    dsp_han(han[55],1);
    dsp_han(han[56],1);
    dsp_han(han[57],1);
    dsp_han(han[50],1);
    dsp_han(han[51],1);
    set_page1();
    lcd.ty=lcd.y=0xbc;
    lcd_blk=1;

    dsp_han(han[26],1);
    dsp_han(han[27],1);
    dsp_han(han[24],1);
    dsp_han(han[25],1);
 //   dsp_han(han[25],1);
    dsp_nul2(15);
    break;
    
     case 8: //pcb¼³°è 
    set_page0();
    lcd.ty=lcd.y=0xbc; //3¹øÂ° ¶óÀÎ
    lcd_blk=1;
     dsp_nul2(4);
    dsp_han(han[30],1);
    dsp_han(han[31],1);
    dsp_han(han[48],1);
    dsp_han(han[49],1);
    dsp_han(han[50],1);
    set_page1();
    lcd.ty=lcd.y=0xbc;
    lcd_blk=1;

    dsp_han(han[51],1);
    dsp_han(han[26],1);
    dsp_han(han[27],1);
    dsp_han(han[24],1);
    dsp_han(han[25],1);
    //dsp_nul2(15);
    break;
    }
    
}

void fourth()
{


   switch(SecFlag)
   {
   case 0:
    set_page0();
    lcd.ty=lcd.y=0xbe; //4¹øÂ° ¶óÀÎ
    lcd_blk=1;
    dsp_nul2(40);
    dsp_han(han[10],1);
    dsp_han(han[11],1);

    set_page1();
    lcd.ty=lcd.y=0xbe;
    lcd_blk=1;

    dsp_han(han[12],1);
    dsp_nul2(1);
    dsp_han(han[28],1);
    dsp_han(han[29],1);
    dsp_nul2(28);
    break;
    case 1:
    set_page0();
    lcd.ty=lcd.y=0xbe; //4¹øÂ° ¶óÀÎ
    lcd_blk=0;
    dsp_nul2(40);
    dsp_han(han[10],1);
    dsp_han(han[11],1);

    set_page1();
    lcd.ty=lcd.y=0xbe;
    lcd_blk=0;
    dsp_han(han[12],1);
    dsp_nul2(1);
    dsp_han(han[28],1);
    dsp_han(han[29],1);
    dsp_nul2(28);
    break;
    }


}
void main(void)
{
// Declare your local variables here

// Crystal Oscillator division factor: 1
#pragma optsize-
CLKPR=0x80;
CLKPR=0x00;
#ifdef _OPTIMIZE_SIZE_
#pragma optsize+
#endif

// Input/Output Ports initialization
// Port A initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTA=0x00;
DDRA=0xFF;

// Port B initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTB=0x00;
DDRB=0xff;

// Port D initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTD=0x00;
DDRD=0xFF;

// Port E initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTE=0x00;
DDRE=0xFF;

// Port F initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTF=0x00;
DDRF=0x00;

// Port G initialization
// Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State5=T State4=T State3=T State2=T State1=T State0=T 
PORTG=0x00;
DDRG=0x00;

// Port H initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTH=0xFF;
DDRH=0xFF;

// Port J initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTJ=0x00;
DDRJ=0xFF;

// Port K initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTK=0x00;
DDRK=0xFF;

// Port L initialization
// Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
// State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
PORTL=0x00;
DDRL=0xff;

TCCR0A=0x00;//Normal Mode Operation(Overflow Interrupt Enable) 
TCCR0B=0x03;//64Prescale Select
TCNT0=0x06;// Timer/Count Register initialization

// Timer/Counter 1 initialization
// Clock source: System Clock
// Clock value: Timer1 Stopped
// Mode: Normal top=0xFFFF
// OC1A output: Discon.
// OC1B output: Discon.
// OC1C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer1 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR1A=0x00;
TCCR1B=0x00;
TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1AH=0x00;
OCR1AL=0x00;
OCR1BH=0x00;
OCR1BL=0x00;
OCR1CH=0x00;
OCR1CL=0x00;

// Timer/Counter 2 initialization
// Clock source: System Clock
// Clock value: Timer2 Stopped
// Mode: Normal top=0xFF
// OC2A output: Disconnected
// OC2B output: Disconnected
ASSR=0x00;
TCCR2A=0x00;
TCCR2B=0x04;
TCNT2=0xe7;
OCR2A=0x00;
OCR2B=0x00;

// Timer/Counter 3 initialization
// Clock source: System Clock
// Clock value: Timer3 Stopped
// Mode: Normal top=0xFFFF
// OC3A output: Discon.
// OC3B output: Discon.
// OC3C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer3 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR3A=0x00;
TCCR3B=0x00;
TCNT3H=0x00;
TCNT3L=0x00;
ICR3H=0x00;
ICR3L=0x00;
OCR3AH=0x00;
OCR3AL=0x00;
OCR3BH=0x00;
OCR3BL=0x00;
OCR3CH=0x00;
OCR3CL=0x00;

// Timer/Counter 4 initialization
// Clock source: System Clock
// Clock value: Timer4 Stopped
// Mode: Normal top=0xFFFF
// OC4A output: Discon.
// OC4B output: Discon.
// OC4C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer4 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR4A=0x00;
TCCR4B=0x00;
TCNT4H=0x00;
TCNT4L=0x00;
ICR4H=0x00;
ICR4L=0x00;
OCR4AH=0x00;
OCR4AL=0x00;
OCR4BH=0x00;
OCR4BL=0x00;
OCR4CH=0x00;
OCR4CL=0x00;

// Timer/Counter 5 initialization
// Clock source: System Clock
// Clock value: Timer5 Stopped
// Mode: Normal top=0xFFFF
// OC5A output: Discon.
// OC5B output: Discon.
// OC5C output: Discon.
// Noise Canceler: Off
// Input Capture on Falling Edge
// Timer5 Overflow Interrupt: Off
// Input Capture Interrupt: Off
// Compare A Match Interrupt: Off
// Compare B Match Interrupt: Off
// Compare C Match Interrupt: Off
TCCR5A=0x00;
TCCR5B=0x00;
TCNT5H=0x00;
TCNT5L=0x00;
ICR5H=0x00;
ICR5L=0x00;
OCR5AH=0x00;
OCR5AL=0x00;
OCR5BH=0x00;
OCR5BL=0x00;
OCR5CH=0x00;
OCR5CL=0x00;

// External Interrupt(s) initialization
// INT0: Off
// INT1: Off
// INT2: Off
// INT3: Off
// INT4: Off
// INT5: Off
// INT6: Off
// INT7: Off
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;
// PCINT0 interrupt: Off
// PCINT1 interrupt: Off
// PCINT2 interrupt: Off
// PCINT3 interrupt: Off
// PCINT4 interrupt: Off
// PCINT5 interrupt: Off
// PCINT6 interrupt: Off
// PCINT7 interrupt: Off
// PCINT8 interrupt: Off
// PCINT9 interrupt: Off
// PCINT10 interrupt: Off
// PCINT11 interrupt: Off
// PCINT12 interrupt: Off
// PCINT13 interrupt: Off
// PCINT14 interrupt: Off
// PCINT15 interrupt: Off
// PCINT16 interrupt: Off
// PCINT17 interrupt: Off
// PCINT18 interrupt: Off
// PCINT19 interrupt: Off
// PCINT20 interrupt: Off
// PCINT21 interrupt: Off
// PCINT22 interrupt: Off
// PCINT23 interrupt: Off
PCMSK0=0x00;
PCMSK1=0x00;
PCMSK2=0x00;
PCICR=0x00;

// Timer/Counter 0 Interrupt(s) initialization
TIMSK0=0x01;

// Timer/Counter 1 Interrupt(s) initialization
TIMSK1=0x00;

// Timer/Counter 2 Interrupt(s) initialization
TIMSK2=0x01;

// Timer/Counter 3 Interrupt(s) initialization
TIMSK3=0x00;

// Timer/Counter 4 Interrupt(s) initialization
TIMSK4=0x00;

// Timer/Counter 5 Interrupt(s) initialization
TIMSK5=0x00;

// USART0 initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART0 Receiver: Off
// USART0 Transmitter: On
// USART0 Mode: Asynchronous
// USART0 Baud Rate: 9600
UCSR0A=0x00;
UCSR0B=0x08;
UCSR0C=0x06;
UBRR0H=0x00;
UBRR0L=0x67;

// USART1 initialization
// USART1 disabled
UCSR1B=0x00;

// USART2 initialization
// USART2 disabled
UCSR2B=0x00;

// USART3 initialization
// USART3 disabled
UCSR3B=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
ADCSRB=0x00;
DIDR1=0x00;

// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: AVCC pin
// ADC Auto Trigger Source: ADC Stopped
// Digital input buffers on ADC0: On, ADC1: On, ADC2: On, ADC3: On
// ADC4: On, ADC5: On, ADC6: On, ADC7: On
DIDR0=0x00;
// Digital input buffers on ADC8: On, ADC9: On, ADC10: On, ADC11: On
// ADC12: On, ADC13: On, ADC14: On, ADC15: On
DIDR2=0x00;
ADMUX=ADC_VREF_TYPE & 0xff;
ADCSRA=0x84;

// SPI initialization
// SPI disabled
SPCR=0x00;

// TWI initialization
// TWI disabled
TWCR=0x00;
rst=1; 
 lcd_init();     //±×·¡ÇÈÇüLCD È®Àåº¸µå ÃÊ±âÈ­
// Global enable interrupts
#asm("sei")
first();     //±×·¡ÇÈÇüLCD Ã¹¹øÂ° ¶óÀÎ 
second();    //±×·¡ÇÈÇüLCD µÎ¹øÂ° ¶óÀÎ 
 third();     //±×·¡ÇÈÇüLCD ³×¹øÂ° ¶óÀÎ       
while (1)
      {  
         printf("UART0 Serial Output Test\r\n"); 
      reverse_dis(); // ¹ÝÀüÇÏ¸é¼­ ¹®ÀÚ ½ÃÇÁÆ® 
   
        switch(MotorDir)
        {
        case 0: CW1=1;CWC1=0;CW2=1;CCW2=0;break; //forward direction
        case 1: CW1=0;CWC1=1;CW2=0;CCW2=1;break; //reverse direction      
        }     
  
       fourth();    //±×·¡ÇÈÇüLCD ¼¼¹øÂ° ¶óÀÎ 
      
      
      }
}
