//ICC-AVR application builder : 2009-6-4 13:38:39
// Target : M64
// Crystal: 8.0000Mhz
#include <iom64v.h>
#include <macros.h>
//#include <math.h>
#include "bmplib.h"
#define uchar unsigned char
#define uint unsigned int
#define TEST 0
/*
#define K_OK 0
#define K_LEFT 1
#define K_DOWN 2
#define K_LAMP 3
#define K_QUIT 4
*/
#define K_OK 0x10
#define K_LEFT 0x08
#define K_DOWN 0x04
#define K_LAMP 0x02
#define K_QUIT 0x01
#define KL_OK (0x10|0x80)
#define KL_LEFT (0x08|0x80)
#define KL_DOWN (0x04|0x80)
#define KL_LAMP (0x02|0x80)
#define KL_QUIT (0x01|0x80)
#define KEYSCAN ((((PINA>>4)|((PING<<2)&0x10))|0xE0)^0xFF)
#define KEY_OK 0x10
#define KEY_LEFT 0x08
#define KEY_DOWN 0x04
#define KEY_LAMP 0x02
#define KEY_QUIT 0x01
#define KEYL_OK (0x10|0x80)
#define KEYL_LEFT (0x08|0x80)
#define KEYL_DOWN (0x04|0x80)
#define KEYL_LAMP (0x02|0x80)
#define KEYL_QUIT (0x01|0x80)
//#define KEY_S 300
//#define KEY_L 200
#if TEST==1
#define KEY_S 30
#else
#define KEY_S 300
#endif
#if TEST==1
#define KEY_L 20
#else
#define KEY_L 200
#endif
#define GLASSLX 11
#define GLASSRX 70
#define GLASSW 47
#define GLASSH 32
#define GLASSFS 14
#define GLASSFW 5
#define GLASSFM 10
#define ZEROX -5050
#define ZEROY -500
#define LONG_UNIT_X 2991 //1W*(3.14159*D/2048) //D=19.5,LONG_UNIT_X=0.02761165*1W
#define LONG_UNIT_Y 1994 //1W*(3.14159*D/2048) //D=18,LONG_UNIT
#define E_H PORTE|=BIT(2) //PE2//
#define E_L PORTE&=~BIT(2)
#define RW_H PORTE|=BIT(3) //PE3
#define RW_L PORTE&=~BIT(3)
#define RS_H PORTB|=BIT(2) //PB2
#define RS_L PORTB&=~BIT(2)
#define CS3_H PORTA|=BIT(3) //PA3
#define CS3_L PORTA&=~BIT(3)
#define CS2_H PORTA|=BIT(2) //PA2
#define CS2_L PORTA&=~BIT(2)
#define CS1_H PORTA|=BIT(0) //PA0
#define CS1_L PORTA&=~BIT(0)
#define RES_H PORTA|=BIT(1) //PA1
#define RES_L PORTA&=~BIT(1)
#define DB PORTF//LCD DB
#define LCD_LEFT CS1_L;CS2_H;CS3_H
#define LCD_MID CS1_H;CS2_L;CS3_H
#define LCD_RIGHT CS1_H;CS2_H;CS3_L
//#define ADD_Y0 0x40
//#define ADD_X0 0xB8
//#define DISP_SL0 0xC0
//#define DISP_ON 0x3F
//#define DISP_OFF 0x3E
//#define MOTOPUE_H TIMSK|=0x01;
//#define MOTOPUE_L TIMSK&=~0x01;
#define XMOTOMF_H PORTC|=BIT(7) //PC7
#define XMOTOMF_L PORTC&=~BIT(7)
#define XMOTOMF_T PORTC^=BIT(7)
#define XMOTODR_H PORTC|=BIT(6) //PC6
#define XMOTODR_L PORTC&=~BIT(6)
#define XMOTODR_T PORTC^=BIT(6)
#define XMOTODR_R ((PINC>>6)&0x01)
#define XMOTOPU_T PORTC^=BIT(5)//PC5
#define XSWITCHSTART ((PINE>>4)&0x01)//int4
#define XSWITCHSTOP ((PINE>>5)&0x01)//int5
#define XMAGNETC_H PORTC|=BIT(4) //PC4
#define XMAGNETC_L PORTC&=~BIT(4)
#define YMAGNETC_H PORTC|=BIT(3) //PC3
#define YMAGNETC_L PORTC&=~BIT(3)
#define YMOTOMF_H PORTC|=BIT(2) //PC2
#define YMOTOMF_L PORTC&=~BIT(2)
#define YMOTOMF_T PORTC^=BIT(2)
#define YMOTODR_H PORTC|=BIT(1) //PC1
#define YMOTODR_L PORTC&=~BIT(1)
#define YMOTODR_T PORTC^=BIT(1)
#define YMOTODR_R ((PINC>>1)&0x01)
#define YMOTOPU_T PORTC^=0x01//BIT(0)//PC0
#define YSWITCHSTART ((PIND>>2)&0x01)//int2
#define YSWITCHSTOP ((PIND>>3)&0x01)//int3
#define LAMP_H PORTB|=BIT(5) //PB5
#define LAMP_L PORTB&=~BIT(5)
#define LAMP_T PORTB^=BIT(5)
#define BEEP_H PORTB|=BIT(6) //PB6
#define BEEP_L PORTB&=~BIT(6)
#define BEEP_T PORTB^=BIT(6)
#define DRILL_H PORTD|=BIT(4) //PD4
#define DRILL_L PORTD&=~BIT(4)
#define DRILL_T PORTD^=BIT(4)
#define DRILL_R ((PIND>>4)&0x01)
#define T1_H TIMSK|=BIT(4)
#define T1_L TIMSK&=~BIT(4)
#define T1_T TIMSK^=BIT(4)
#define T1_R test_bit(TIMSK,4)
#define XB_INT ((PINE>>6)&0x01)//PINE6
#define XA_INT (PINE>>7)//PINE7
#define PINB_3 ((PINB>>3)&0x01)//PINB3
#define YB_INT (PIND&0x01)//PIND0
#define YA_INT ((PIND>>1)&0x01)//PIND1
//#define PING_4 ((PING>>4)&0x01)//PIND4
#define INTYB_H EICRA|=0x03//EICRA:11上升有效10下降有效EICRA|=0x03;//上升有效
#define INTYB_L EICRA|=0x02;EICRA&=~0x01//EICRA|=0x02;EICRA&=~0x01;
//#define INTYB_T EICRA^=0x01 //INT0 YB 上升下降沿中断方式翻转10下降11上升
//#define INTYB_R (EICRA&0x01)
signed int xz,yz;
signed int linex[4],liney[4];
signed int hole_left1x,hole_left1y,hole_left2x,hole_left2y;
signed int hole_targetx,hole_targety;
signed int hole_target[4][4][2];
signed int xztemp;
//uint t,t1; //test
uchar keyvalue;
uchar xmotopu,ymotopu;
uchar step;
uchar manmodel;
uchar MMenuSel,SMMenuSel,SLMenuSel,SRMenuSel,SMenuSel;
uchar SSubMenuSel[4][2];//左外,左内,右内,右外//Select And Max
uchar SSubMenuHanzi[4][4][4]={
{{6,9,3,15},{6,9,10,11},{6,9,3,16},{6,9,3,17}},
{{6,8,3,15},{6,8,10,11},{6,8,3,16},{6,8,3,17}},
{{7,8,3,15},{7,8,10,11},{7,8,3,16},{7,8,3,17}},
{{7,9,3,15},{7,9,10,11},{7,9,3,16},{7,9,3,17}}};
uchar studyleft;
uchar studyok[5];
uchar studynote[4][4];
uchar notchture;
uchar autodis=1;
uchar dispch[1]={0x00};
uchar StSubMenuMax[4];
//uchar hole1search[4];//////////////////
uchar t0tcnt,t0set;
uchar topline,bottomline;
uchar flashchange,flashture;
uchar drillok[4][4];
void xmotoctr(void);
void xmotostart(void);
void xmotostop(void);
void xmotounlock(void);
void xmotolock(void);
void ymotoctr(void);
void ymotostart(void);
void ymotostop(void);
void ymotounlock(void);
void ymotolock(void);
void timer0_init(void);
void timer0_set(uchar us);
////intit////intit////intit////intit////intit////intit////intit////intit///intit////intit////intit////intit///
////intit////intit////intit////intit////intit////intit////intit////intit///intit////intit////intit////intit///
////intit////intit////intit////intit////intit////intit////intit////intit///intit////intit////intit////intit///
////intit////intit////intit////intit////intit////intit////intit////intit///intit////intit////intit////intit///
////intit////intit////intit////intit////intit////intit////intit////intit///intit////intit////intit////intit///
//TIMER0 initialize - prescale:8
// WGM: Normal
// desired value: 30uSec
// actual value: 29.000uSec (3.3%)
void timer0_init(void)
{
TCCR0 = 0x00; //stop
ASSR = 0x00; //set async mode
TCNT0 = 0xE3; //set count
OCR0 = 0x1D;
TCCR0 = 0x02; //start timer
}
/*
//TIMER1 initialize - prescale:64
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 600mSec
// actual value: 599.984mSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0x6D; //setup
TCNT1L = 0x85;
OCR1AH = 0x92;
OCR1AL = 0x7B;
OCR1BH = 0x92;
OCR1BL = 0x7B;
OCR1CH = 0x92;
OCR1CL = 0x7B;
ICR1H = 0x92;
ICR1L = 0x7B;
TCCR1A = 0x00;
TCCR1B = 0x03; //start Timer
}
*/
//TIMER1 initialize - prescale:64
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 100mSec
// actual value: 100.000mSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xCF; //setup
TCNT1L = 0x2C;
OCR1AH = 0x30;
OCR1AL = 0xD4;
OCR1BH = 0x30;
OCR1BL = 0xD4;
OCR1CH = 0x30;
OCR1CL = 0xD4;
ICR1H = 0x30;
ICR1L = 0xD4;
TCCR1A = 0x00;
TCCR1B = 0x03; //start Timer
}
/*
//TIMER1 initialize - prescale:1
// WGM: 0) Normal, TOP=0xFFFF
// desired value: 100uSec
// actual value: 100.000uSec (0.0%)
void timer1_init(void)
{
TCCR1B = 0x00; //stop
TCNT1H = 0xFC; //setup
TCNT1L = 0xE0;
OCR1AH = 0x03;
OCR1AL = 0x20;
OCR1BH = 0x03;
OCR1BL = 0x20;
OCR1CH = 0x03;
OCR1CL = 0x20;
ICR1H = 0x03;
ICR1L = 0x20;
TCCR1A = 0x00;
TCCR1B = 0x01; //start Timer
}
*/
void port_init(void)
{
PORTA = 0xFF;/////////
DDRA = 0x0F;//PINA4567设置为输入
PORTB = 0x08;//PINB3上拉
DDRB = 0xF7;//PB3设置为输入
PORTC = 0x00; //m103 output only
DDRC = 0xFF;
PORTD = 0x0F;//低四位上拉
DDRD = 0x10;//PD4输出
PORTE = 0xF0;//PORTE高四位上拉
DDRE = 0x0F;//PORTE高四位设置为输入
PORTF = 0x00;
DDRF = 0xFF;
PORTG = 0xFF;
DDRG = 0x00;
}
//call this routine to initialize all peripherals
void init_devices(void)
{
//stop errant interrupts until set up
CLI(); //disable all interrupts
XDIV = 0x00; /