#include <intrins.h>
#include <reg52.h>
#include "zlg7289a.h"
//fosc:22.1184MHz, 1个指令周期0.5425us
/*
T1 从CS下降沿至CLK脉冲时间: 50uS
T2 传送指令时CLK脉冲宽度: 8uS
T3 字节传送中CLK脉冲时间间隔: 8uS
T4 指令与数据时间间隔:25uS
T5 读键盘指令中指令与输出数据时间间隔:25uS
T6 输出键盘数据建立时间: 8uS
T7 读键盘数据时CLK脉冲宽度: 8uS
T8 读键盘数据完成后DATA转为输入状态时间: 5uS
*/
sfr P4 = 0x0E8;
sbit ZLG7289A_CS = P1^1;
sbit ZLG7289A_CLK = P2^5;
sbit ZLG7289A_DATA = P1^0;
void zlg7289a_out_byte(unsigned char byte)
{
unsigned char temp, temp1, temp2;
temp = byte;
ZLG7289A_CLK = 0;
temp1 = 8;
EA=0;
while(temp1--)
{
temp <<= 1;
ZLG7289A_DATA = CY;
temp2 = 12;
while(--temp2);
ZLG7289A_CLK = 1;
temp2 = 12;
while(--temp2);
ZLG7289A_CLK = 0;
}
EA=1;
}
unsigned char zlg7289a_in_byte(void)
{
unsigned char temp, temp1;
unsigned char ret;
temp = 8;
ret = 0;
ZLG7289A_CLK = 0;
while(temp--)
{
ZLG7289A_CLK = 1;
ret <<= 1;
temp1 = 10;
while(temp1--)
{
_nop_();
}
ZLG7289A_CLK = 0;
if(ZLG7289A_DATA)
{
ret++;
}
}
return ret;
}
void zlg7289a_reset(void)
{
ZLG7289A_CS = 0;
zlg7289a_out_byte(ZLG7289A_RESET);
ZLG7289A_CS = 1;
}
void zlg7289a_test(void)
{
//unsigned char i;
//ZLG7289A_CS = 0;
//for(i=0;i<50;i++);
//zlg7289a_out_byte(ZLG7289A_TEST);
/*
zlg7289a_out_byte(0x90);
zlg7289a_out_byte(0xff);
zlg7289a_out_byte(0x91);
zlg7289a_out_byte(0xff);
zlg7289a_out_byte(0x92);
zlg7289a_out_byte(0xff);
zlg7289a_out_byte(0x93);
zlg7289a_out_byte(0xff);
zlg7289a_out_byte(0x94);
zlg7289a_out_byte(0xff);
zlg7289a_out_byte(0x95);
zlg7289a_out_byte(0xff);
zlg7289a_out_byte(0x96);
zlg7289a_out_byte(0xff);
zlg7289a_out_byte(0x97);
zlg7289a_out_byte(0xff);
*/
zlg7289a_load_2(0, 0xFF);
zlg7289a_load_2(1, 0xFF);
zlg7289a_load_2(2, 0xFF);
zlg7289a_load_2(3, 0xFF);
//zlg7289a_load_2(4, 0xFF);
//zlg7289a_load_2(5, 0xFF);
//zlg7289a_load_2(6, 0xFF);
//zlg7289a_load_2(7, 0xFF);
// ZLG7289A_CS = 1;
}
void zlg7289a_load_0(unsigned char address, unsigned char show_data, unsigned char DP)
{
unsigned char temp;
ZLG7289A_CS = 0;
temp = (address & 0x07);
temp |= ZLG7289A_LOAD_DATA_0;
zlg7289a_out_byte(temp);
temp = show_data & 0x0F;
if(DP)
{
temp |= 0x80;
}
zlg7289a_out_byte(temp);
ZLG7289A_CS = 1;
}
void zlg7289a_load_1(unsigned char address, unsigned char show_data, unsigned char DP)
{
unsigned char temp;
ZLG7289A_CS = 0;
temp = address & 0x07;
temp |= ZLG7289A_LOAD_DATA_1;
zlg7289a_out_byte(temp);
temp = show_data & 0x0F;
if(DP)
{
temp |= 0x80;
}
zlg7289a_out_byte(temp);
ZLG7289A_CS = 1;
}
void zlg7289a_load_2(unsigned char address, unsigned char show_data)
{
unsigned char temp;
temp = address & 0x07;
temp |= ZLG7289A_LOAD_DATA_2;
ZLG7289A_CS = 0;
zlg7289a_out_byte(temp);
zlg7289a_out_byte(show_data);
ZLG7289A_CS = 1;
}
void zlg7289a_flash(unsigned char show_data)
{
ZLG7289A_CS = 0;
zlg7289a_out_byte(ZLG7289A_FLASH);
zlg7289a_out_byte(show_data);
ZLG7289A_CS = 1;
}
void zlg7289a_show(unsigned char show_data)
{
if(show_data == 0)
{
return ;
}
ZLG7289A_CS = 0;
zlg7289a_out_byte(ZLG7289A_HIDE);
zlg7289a_out_byte(show_data);
ZLG7289A_CS = 1;
}
void zlg7289a_segment_on(unsigned char show_data)
{
ZLG7289A_CS = 0;
zlg7289a_out_byte(ZLG7289A_SEGMENT_ON);
show_data &= 0x3F;
zlg7289a_out_byte(show_data);
ZLG7289A_CS = 1;
}
void zlg7289a_segment_off(unsigned char show_data)
{
ZLG7289A_CS = 0;
zlg7289a_out_byte(ZLG7289A_SEGMENT_OFF);
show_data &= 0x3F;
zlg7289a_out_byte(show_data);
ZLG7289A_CS = 1;
}
/*
unsigned char zlg7289a_read_key(void)
{
unsigned char ret;
ZLG7289A_CS = 0;
zlg7289a_out_byte(ZLG7289A_READ_KEY);
ZLG7289A_DATA = 1;
ret = zlg7289a_in_byte();
ZLG7289A_CS = 1;
return ret;
}
*/
文章评论(0条评论)
登录后参与讨论