使用LPC2220的GPIO模拟SPI协议,驱动HT16511芯片
首先定义:
#define HTDO GPIOA0
#define HTDI GPIOA2
#define HTCLK GPIOA4
#define HTCS GPIOA6
//向HT16511写一个字符
extern void write_char(unsigned char data)
{
unsigned char k;
for (k=0;k<8;k++)
{
gpio_set(HTCLK);
if (data & 0x01 == 0x01)
{gpio_clr(HTDI);}
else
{gpio_set(HTDI);}
delay(50);
gpio_clr(HTCLK);
delay(50);
data = data>>1;
}
return;
}
//从HT16511读一个字符
extern unsigned char read_char(void)
{
register char i;
unsigned char temp="0";
for(i=0;i<8;i++)
{
gpio_clr(HTCLK);
delay(50);
gpio_set(HTCLK);
delay(25);
temp=temp>>1;
if(gpio_get(HTDO))
{temp &= ~0x80;}
else
{temp |= 0x80;}
delay(25);
}
return temp;
}
//刷新显示
extern void update_disp(unsigned char *disp_data)
{
unsigned char i;
//发送0x40,数据模式:一般模式、地址自增、向显存写数据
gpio_clr(HTCS);
delay(100);
gpio_set(HTCS);
write_char(0x40);
//发送0xc0,设置地址为00H
gpio_clr(HTCS);
delay(100);
gpio_set(HTCS);
write_char(0xc0);
//向显示RAM发送数据
for(i=0;i<36;i++)
{write_char(*(i+disp_data));}
//发送0x8f,打开显示
gpio_clr(HTCS);
delay(100);
gpio_set(HTCS);
write_char(0x8f);
return;
}
需要说明的是,由于使用了一篇ULN2003,所以这里的电平是反的
文章评论(0条评论)
登录后参与讨论