📄 d12_hal.c
字号:
///////////////////////////////////////////////////////////////////////
#include "d12_hal.h"
///////////////////////////////////////////////////////////////////////
u8 P37A=0;
#define SET_DPORT(x) P37A&=(~0x20); _outp(0x37a,P37A); _outp(0x378,x)
#define GET_DPORT() (P37A|=0x20,_outp(0x37a,P37A),_inp(0x378))
#define D12_CS(x) P37A=(P37A&(~0x04))|((x)?0x04:0x00); _outp(0x37a,P37A) // Init Pin-16
#define D12_WR(x) P37A=(P37A&(~0x08))|((x)?0x00:0x08); _outp(0x37a,P37A) // Select In Pin-17 INV
#define D12_RD(x) P37A=(P37A&(~0x02))|((x)?0x00:0x02); _outp(0x37a,P37A) // AutoLF Pin-14 INV
#define D12_A0(x) P37A=(P37A&(~0x01))|((x)?0x00:0x01); _outp(0x37a,P37A) // Strobe Pin-1 INV
#define D12_INT() ((_inp(0x379)&0x40)?1:0) // ACK Pin-10
#define delay0()
///////////////////////////////////////////////////////////////////////
// No hardware reset to D12
void d12_reset(void)
{
P37A=_inp(0x37a);
D12_CS(1);
D12_RD(1);
D12_WR(1);
delay_ms(200);
}
///////////////////////////////////////////////////////////////////////
/*
Access Timing:
_________________________________________________
A0 _________________________________________________
_________ ________
CS \______________________________/
RD _____________ ____________
\______________________/
WR ___________________ ____________
\________________/
_______________________
DATA______________/ \_________
\_______________________/
*/
u8 d12_read0(u8 a)
{
u8 nVal;
nVal=GET_DPORT(); // set parallel port input mode
D12_A0((a&0x01)?1:0);
D12_CS(0);
D12_RD(0);
delay0();
nVal=GET_DPORT();
D12_RD(1);
D12_CS(1);
delay0();
return nVal;
}
void d12_write0(u8 a, u8 d)
{
SET_DPORT(d);
D12_A0((a&0x01)?1:0);
D12_CS(0);
D12_WR(0);
delay0();
D12_WR(1);
D12_CS(1);
delay0();
}
///////////////////////////////////////////////////////////////////////
u8 d12_read(u8 a)
{
u8 nVal;
d12_write0(T_CMD,a);
nVal=d12_read0(T_DAT);
return nVal;
}
///////////////////////////////////////////////////////////////////////
void d12_write(u8 a, u8 d)
{
d12_write0(T_CMD,a);
d12_write0(T_DAT,d);
}
///////////////////////////////////////////////////////////////////////
void d12_bufread(u8 addr, u8 *s, u8 c)
{
u8 i;
u8 addr0;
addr0=addr;
d12_write0(T_CMD,addr0);
for(i=0;i<c;i++)
*s++ =d12_read0(T_DAT);
}
///////////////////////////////////////////////////////////////////////
void d12_bufwrite(u8 addr, u8 *s, u8 c)
{
u8 i;
u8 addr0;
addr0=addr;
d12_write0(T_CMD,addr0);
for(i=0;i<c;i++)
d12_write0(T_DAT,*s++);
}
///////////////////////////////////////////////////////////////////////
u16 u16_swap(u16 input)
{
return (input>>8)|(input<<8);
}
///////////////////////////////////////////////////////////////////////
u32 u32_swap(u32 input)
{
u32 ret;
ret= ((input>>24))
|((input>>8)&0x0000ff00UL)
|((input<<8)&0x00ff0000UL)
|((input>>0)<<24);
return ret;
}
///////////////////////////////////////////////////////////////////////
void delay_ms(u16 ms)
{
u16 idx;
for(idx=0;idx<ms;idx++)
delay_us(1000);
}
///////////////////////////////////////////////////////////////////////
void delay_us(u16 us)
{
u16 i;
for(i=0;i<us;i++)
{
_inp(0x378);
}
}
///////////////////////////////////////////////////////////////////////
void show_buf(char *prompt,u8 *buf,u16 len)
{
char buf0[17];
u16 idx;
buf0[16]=0;
printf("%s\n",prompt);
for(idx=0;idx<len;idx++)
{
printf("%02X ",buf[idx]);
buf0[idx%16]=(buf[idx]>=0x20 && buf[idx]<=0x7f)?buf[idx]:'.';
if((idx+1)%16==0) printf(" %s %04x0\n",buf0,idx>>4);
}
if(len%16)
{
for(idx=0;idx<16-(len%16);idx++)
{
buf0[idx+(len%16)]=' ';
printf(" ");
}
printf(" %s %04x0\n",buf0,len>>4);
}
printf("\n");
}
///////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -