说明:力天电子的此款开发板,跟周立功的LPC2131不同,周立功的开发板上可以用跳线棒来选择是否用595驱动,周立功课本上进行GPIO输出实验——单路LED控制实验时,直接把LED接到了arm2131处理器上,如下图所示:
而力天电子的流水灯跟驱动是直接连在一起的必须使用595驱动,如下图所示:
#include <NXP/iolpc2148.h>
#define SCLK 0x01<<24
#define MISO 0x01<<5
#define MOSI 0x01<<6
#define RCK 0x01<<7
void Delayn(unsigned long n);
void HC595_Init(void);
void Write595(void);
unsigned int HC595_DATA = 0;
//初始化595接口
void HC595_Init(void)
{
IO0DIR |= MOSI|RCK;
IO1DIR |= SCLK;
IO1CLR |= SCLK;
IO0DIR |= RCK;
HC595_DATA = 0xFFFFFFFF;
Write595();
}
//写字节
void WriteByte(unsigned char data)
{
unsigned char i;
//IO0CLR = RCK;
for(i=0;i<8;i++)
{
if(data&0x01) IO0SET=MOSI;
else IO0CLR=MOSI;
IO1SET=SCLK;
data>>=1;
IO1CLR=SCLK;
}
//IO0SET = RCK;
}
//刷新595的数据
void Write595(void)
{
IO0CLR = RCK;
WriteByte(HC595_DATA&0xff);
WriteByte((HC595_DATA&0xff00)>>8);
WriteByte((HC595_DATA&0xff0000)>>16);
WriteByte((HC595_DATA&0xff000000)>>24);
IO0SET = RCK;
}
main()
{
//初始化74HC595
HC595_Init();
//主循环
while(1)
{
HC595_DATA &=~(1<<18);Write595();
Delayn(250000);
HC595_DATA |=(1<<18);Write595();
Delayn(250000);
}
}
//延时函数
void Delayn(unsigned long n)
{
while(n--);
}