头文件
#ifndef __LED_LATTICE_H__
#define __LED_LATTICE_H__
#define _LATTICE_LOW_TO_HIGH 1
#define _LATTICE_HIGH_TO_LOW 0
#define _LATTICE_OUTPUT_PATTERN _LATTICE_LOW_TO_HIGH
#include <reg52.h>
#define latticeInit() latticeWriteData(0, 0)
#define latticeWriteLine(data, line) latticeWriteData(~(data), 0x0001 << (line))
#define latticeWriteList(data, list) latticeWriteData(~(0x0001 << (list)), data)
extern void latticeWriteData(unsigned int, unsigned int);
#endif
源文件
#include "LEDLattice.h"
void latticeWriteData(unsigned int lineData, unsigned int listData) {
unsigned char i;
for (i = 0; i < 16; i++) {
#if _LATTICE_OUTPUT_PATTERN == _LATTICE_LOW_TO_HIGH
DATA = lineData & 0x8000;
lineData <<= 1;
#elif _LATTICE_OUTPUT_PATTERN == _LATTICE_HIGH_TO_LOW
DATA = lineData & 0x0001;
lineData >>= 1;
#endif
CLK = 1;
CLK = 0;
}
for (i = 0; i < 16; i++) {
#if _LATTICE_OUTPUT_PATTERN == _LATTICE_LOW_TO_HIGH
DATA = listData & 0x8000;
listData <<= 1;
#elif _LATTICE_OUTPUT_PATTERN == _LATTICE_HIGH_TO_LOW
DATA = listData & 0x0001;
listData >>= 1;
#endif
CLK = 1;
CLK = 0;
}
LOAD = 1;
LOAD = 0;
}