|
//displey
//port 2
#define d_rw BIT2
#define d_e BIT3
//port 4
#define d_cs1 BIT3
#define d_cs2 BIT4
#define d_di BIT6
#define d_rst BIT7
//set control word
#define dc_on 0x3f
#define dc_off 0x3e
#define dc_sa 0x40
#define dc_sp 0xb8
#define dc_sl 0xc0
//end displey
void dp_check_busy(void)
{
unsigned int i_;
P5DIR = 0x0;
do
{
P4OUT &= ~d_di;
P2OUT |= d_rw;
P4OUT &= ~dp_cs;
__no_operation();
__no_operation();
P2OUT |= d_e;
wait_cyc(0x1);
i_=P5IN&0x90;
P2OUT &= ~d_e;
__no_operation();
P4OUT |= dp_cs;
}
while (i_!=0);
P5DIR = 0xff;
}
void dp_send_command(char byte2send)
{
dp_check_busy();
__no_operation();
P5OUT = byte2send;
P4OUT &= ~d_di;
P2OUT &= ~d_rw;
P4OUT &= ~dp_cs;
__no_operation();
__no_operation();
P2OUT |= d_e;
wait_cyc(0x1);
P2OUT &= ~d_e;
__no_operation();
P4OUT |= dp_cs;
}
void dp_send_data(char byte2send)
{
dp_check_busy();
__no_operation();
P5OUT = byte2send;
P4OUT |= d_di;
P2OUT &= ~d_rw;
P4OUT &= ~dp_cs;
__no_operation();
__no_operation();
P2OUT |= d_e;
wait_cyc(0x1);
P2OUT &= ~d_e;
__no_operation();
P4OUT |= dp_cs;
}
char dp_receive2(void)
{
char i_;
__no_operation();
P5DIR = 0x0;
P4OUT |= d_di;
P2OUT |= d_rw;
P4OUT &= ~dp_cs;
__no_operation();
__no_operation();
P2OUT |= d_e;
__no_operation();
__no_operation();
__no_operation();
i_=P5IN;
P2OUT &= ~d_e;
__no_operation();
P4OUT |= dp_cs;
P5DIR = 0xff;
return(i_);
}
char dp_receive(void)
{
char i_;
dp_check_busy();
i_=dp_receive2();
dp_check_busy();
i_=dp_receive2();
return(i_);
}
void dp_init(void)
{
P4OUT &= ~d_cs1;
__no_operation();
P4OUT &= ~d_rst;
__no_operation();
__no_operation();
P4OUT |= d_rst;
__no_operation();
P4OUT |= d_cs1;
dp_cs=d_cs1;
dp_send_command(dc_off);
dp_send_command(dc_on);
dp_send_command(dc_sa);
dp_send_command(dc_sp);
dp_send_command(dc_sl);
//
P4OUT &= ~d_cs2;
__no_operation();
P4OUT &= ~d_rst;
__no_operation();
__no_operation();
P4OUT |= d_rst;
__no_operation();
P4OUT |= d_cs2;
dp_cs=d_cs2;
dp_send_command(dc_off);
dp_send_command(dc_on);
dp_send_command(dc_sa);
dp_send_command(dc_sp);
dp_send_command(dc_sl);
}
E-mail: info@telesys.ru