#include "Uln2803Drive.h" SUln2803Drive Uln2803; volatile unsigned char idata cPwmDriveBuffer[17]; unsigned char code cTableUnl2803DriveMask[]= { 0xfc, 0xf3, 0xcf, 0x3f, }; unsigned char code cTableUnl2803DrivePhase[] = { 0x03, 0x01, 0x00, 0x02, 0x03, 0x0c, 0x08, 0x00, 0x04, 0x0c, 0x30, 0x10, 0x00, 0x20, 0x30, 0xc0, 0x40, 0x00, 0x80, 0xc0, }; unsigned int code wTableUnl2803DriveValue[] = { 0x0000, 0x0080, 0x0820, 0x1110, 0x2244, 0x2492, 0x4a52, 0x5554, 0xaaaa, 0xabaa, 0xbaae, 0xbbba, 0xeeee, 0xeefe, 0xf7f7, 0x7fff, }; void Uln2803Drive(unsigned char cPort, unsigned char cPosition) { unsigned long int wTemp; unsigned char c, cDriveValue, cPhaseValueLeft, cPhaseValueRight, cShieldValue; cPosition &= 0x3f; wTemp = wTableUnl2803DriveValue[cPosition & 0x0f]; cPhaseValueLeft = cTableUnl2803DrivePhase[(cPosition / 16) + (cPort * 5)]; cPhaseValueRight = cTableUnl2803DrivePhase[(cPosition / 16) + (cPort * 5) + 1]; cShieldValue = cTableUnl2803DriveMask[cPort]; for (c = 0; c != 16; c ++) { if (wTemp & 0x0001) cDriveValue = cPhaseValueRight; else cDriveValue = cPhaseValueLeft; cPwmDriveBuffer[c] &= cShieldValue; cPwmDriveBuffer[c] |= cDriveValue; wTemp >>= 1; } cPwmDriveBuffer[16] &= cShieldValue; cPwmDriveBuffer[16] |= cPhaseValueRight; }