//LED屏驱动
#include "reg52.h" #include "string.h" #define uchar unsigned char #define uint unsigned int #define ulong unsigned long
extern void ShT_LEDBoard_ColShiftOut(void); void TestRefreshLEDScreen(void);
#define c_MaxColNumber 64 #define c_MaxRowNumber 16
#define c_MaxColByte c_MaxColNumber/8
uchar ucColDataBuff_High[c_MaxColByte]; //一行数据缓冲区 uchar idata ucLEDDisplayMemory[c_MaxColByte*c_MaxRowNumber];
//uchar ucColDataBuff_Low[c_MaxDataBuffLength]; //此缓冲区是为拼成32行而设置的
uint uiRowControlValue; uchar ucRowLineCount;
sbit c_Row_SData = P2^1; sbit c_Row_SClk = P2^2; sbit c_Row_SOut = P2^0;
//sbit c_Col_SData = P1^5; //sbit c_Col_SClk = P1^7; //sbit c_Col_SOut_High = P1^0; //sbit c_Col_SOut_Low = P1^1;
//sbit c_Col_SOE = P1^2;
void ShT_LEDBoard_RowShiftOut(uint uiWriteValue) { uchar ucCount; uint uiTemp;
c_Row_SClk = 0; c_Row_SOut = 0;
uiTemp = uiWriteValue;
for(ucCount=0; ucCount<c_MaxRowNumber; ucCount++) { if(uiTemp & 0x8000) { c_Row_SData = 1; } else { c_Row_SData = 0; } c_Row_SClk = 1;
uiTemp <<= 1;
c_Row_SClk = 0; }
c_Row_SOut = 1;
c_Row_SOut = 0; }
//列驱动 //以下列驱动输出为并行方式 #if 0 #define c_Col_DataPort P0 sbit c_Latch373_O1 = P2^0; sbit c_Latch373_O2 = P2^1; sbit c_Latch373_O3 = P2^2; sbit c_Latch373_O4 = P2^3; sbit c_Latch373_O5 = P2^4; sbit c_Latch373_O6 = P2^5; sbit c_Latch373_O7 = P2^6; sbit c_Latch373_O8 = P2^7;
#define c_Latch_No1 1 #define c_Latch_No2 2 #define c_Latch_No3 3 #define c_Latch_No4 4 #define c_Latch_No5 5 #define c_Latch_No6 6 #define c_Latch_No7 7 #define c_Latch_No8 8
void Init_LED_Board(void) { c_Latch373_O1 =0; c_Latch373_O2 =0; c_Latch373_O3 =0; c_Latch373_O4 =0; c_Latch373_O5 =0; c_Latch373_O6 =0; c_Latch373_O7 =0; c_Latch373_O8 =0; }
void Latch_Data_Out(uchar ucData,uchar LatchRecord) { switch(LatchRecord) { case c_Latch_No1:
c_Col_DataPort = ucData; c_Latch373_O1 =0; // Delay_10MS(1); c_Latch373_O1 =1; break;
case c_Latch_No2:
c_Col_DataPort = ucData; c_Latch373_O2 =0; c_Latch373_O2 =1; break; case c_Latch_No3:
c_Col_DataPort = ucData; c_Latch373_O3 =0; c_Latch373_O3 =1; break; case c_Latch_No4:
c_Col_DataPort = ucData; c_Latch373_O4 =0; c_Latch373_O4 =1; break; case c_Latch_No5:
c_Col_DataPort = ucData; c_Latch373_O5 =0; c_Latch373_O5 =1; break; case c_Latch_No6:
c_Col_DataPort = ucData; c_Latch373_O6 =0; c_Latch373_O6 =1; break; case c_Latch_No7:
c_Col_DataPort = ucData; c_Latch373_O7 =0; c_Latch373_O7 =1; break; case c_Latch_No8:
c_Col_DataPort = ucData; c_Latch373_O8 =0; c_Latch373_O8 =1; break; } }
void ShT_LEDBoard_ColShiftOut(void) {
Latch_Data_Out(ucColDataBuff_High[0],c_Latch_No1); Latch_Data_Out(ucColDataBuff_High[1],c_Latch_No2); Latch_Data_Out(ucColDataBuff_High[2],c_Latch_No3); Latch_Data_Out(ucColDataBuff_High[3],c_Latch_No4); Latch_Data_Out(ucColDataBuff_High[4],c_Latch_No5); Latch_Data_Out(ucColDataBuff_High[5],c_Latch_No6); Latch_Data_Out(ucColDataBuff_High[6],c_Latch_No7); Latch_Data_Out(ucColDataBuff_High[7],c_Latch_No8); } #endif
//以下列输出为串行列移位输出方式 sbit c_Col_SData = P2^5; sbit c_Col_SClk = P2^6; sbit c_Col_SOut_High = P2^4; //sbit c_Col_SOut_Low = P2^7;
sbit c_Col_SOE = P2^3;
void Init_LED_Board(void) { c_Col_SData = 1; c_Col_SClk = 1; c_Col_SOut_High = 1; c_Col_SOE = 1; c_Row_SData = 1; c_Row_SClk = 1; c_Row_SOut = 1; }
void ShT_LEDBoard_ColShiftOut(void) { uchar ucByteCount; uchar ucBitCount; uchar ucTemp;
//开启显示 c_Col_SOE = 0; //执行数据锁存到列的操作 c_Col_SClk = 0; c_Col_SOut_High = 0; for(ucByteCount=0; ucByteCount<c_MaxColByte; ucByteCount++) { ucTemp = ucColDataBuff_High[ucByteCount]; for(ucBitCount=0; ucBitCount<8; ucBitCount++) { if(ucTemp & 0x80) { c_Col_SData = 0; //When Shift Register Latch Out Value is Zero,the Led is Light } else { c_Col_SData = 1; }
c_Col_SClk = 1; ucTemp <<= 1; c_Col_SClk = 0; } }
c_Col_SOut_High = 1; c_Col_SOut_High = 0;
//以下操作是给32行屏体用 /* for(ucByteCount=0; ucByteCount<16; ucByteCount++) { ucTemp = ucColDataBuff_Low[ucByteCount]; for(ucBitCount=0; ucBitCount<8; ucBitCount++) { if(ucTemp & 0x80) { c_Col_SData = 0; //When Shift Register Latch Out Value is Zero,the Led is Light } else { c_Col_SData = 1; }
c_Col_SClk = 1; ucTemp <<= 1; c_Col_SClk = 0; } } c_Col_SOut_Low = 1; c_Col_SOut_Low = 0; */
c_Col_SOE = 0; }
void TestLEDBoardHardware(void) { uchar ucCount; uint uiRowControlValue; uchar ucLoopCount;
// uint uiDelayCount; Init_LED_Board(); for(ucCount=0; ucCount<8; ucCount++) { ucColDataBuff_High[ucCount] = 0x00; // ucColDataBuff_Low[ucCount] = 0x00; }
// while(1) // { for(ucLoopCount=0; ucLoopCount<0x50; ucLoopCount++) { uiRowControlValue = 0x01; for(ucCount=0; ucCount<c_MaxColByte; ucCount++) { ucColDataBuff_High[ucCount] = 0x00; // ucColDataBuff_Low[ucCount] = 0x00; } for(ucCount=0; ucCount<c_MaxRowNumber; ucCount++) { ShT_LEDBoard_RowShiftOut(uiRowControlValue); ShT_LEDBoard_ColShiftOut(); uiRowControlValue <<= 1; } } for(ucLoopCount=0; ucLoopCount<0x50; ucLoopCount++) { uiRowControlValue = 0x01; for(ucCount=0; ucCount<c_MaxColByte; ucCount++) { ucColDataBuff_High[ucCount] = 0xff; // ucColDataBuff_Low[ucCount] = 0xff; } for(ucCount=0; ucCount<c_MaxRowNumber; ucCount++) { ShT_LEDBoard_RowShiftOut(uiRowControlValue); ShT_LEDBoard_ColShiftOut(); uiRowControlValue <<= 1; } }
// } }
void Main(void) { while(1) { TestLEDBoardHardware(); // TestRefreshLEDScreen(); } }
//以下功能实现字符显 void RefreshLEDScreen(uchar ucLoopCount) { uchar ucRowLineCount; uchar ucRefreshCount; uint uiRowControlValue;
// uchar uci; // uchar *pucSrcData; // uchar *pucDestData; // uchar ucCount;
// ucShiftCount = 0; for(ucRefreshCount=0; ucRefreshCount<ucLoopCount; ucRefreshCount++) { uiRowControlValue = 0x0001;
for(ucRowLineCount=0; ucRowLineCount<16; ucRowLineCount++) { memcpy(ucColDataBuff_High,ucLEDDisplayMemory+ucRowLineCount*c_MaxColByte,16);
ShT_LEDBoard_ColShiftOut(); // c_Col_SOE = 1; //关闭显示 ShT_LEDBoard_RowShiftOut(uiRowControlValue); // WriteScreenRowWithSPIModule(~uiRowControlValue); c_Col_SOE = 0; //打开显示
uiRowControlValue <<= 1; }
// ucShiftCount++; // ucShiftCount &= 0x07; //
} //补偿最后一行的亮度不?
c_Col_SOE = 1; //关闭显示 }
#define c_LineWidth 8 //行宽 #define c_MaxLineByteCount 8 //每行占用显示存储器字节数
//#define c_MaxColNumber 128 #define c_MaxLineCount 16 //行的高度 uchar code ucDispDotMaskTab[] = {0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01}; extern code unsigned char ASCII816[][16];
//测试动态显示效果 void TestRefreshLEDScreen(void) { uchar uci; uchar ucCount;
// while(1) // { uci =1; // while(uci) // {
RefreshLEDScreen(100); memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(200); memset(ucLEDDisplayMemory,0xff,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(200); memset(ucLEDDisplayMemory,0x5a,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(200); memset(ucLEDDisplayMemory,0xa5,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(200); //清屏 // memset(ucLEDDisplayMemory,0xff,c_LineWidth*c_MaxLineCount); memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(10); // }
/* while(1) { LED_DispString_ColArray(1,"abcdefghijklmnop"); LED_DispString_ColArray(2,"Tel:025-51615878");
RefreshCurrentScreen(200); LED_DispString_ColArray(1,"8888888888888888"); LED_DispString_ColArray(2,"6666666666666666");
RefreshCurrentScreen(200);
} */ uci =1; // while(uci) { for(ucCount=0; ucCount<c_MaxLineCount; ucCount++) { memset(ucLEDDisplayMemory+c_LineWidth*ucCount, 0xFF, c_LineWidth); // memset(ucLEDDisplayMemory + 16*ucCount, 0, 16); RefreshLEDScreen(10); }
memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(10); for(ucCount=c_MaxLineCount; ucCount>0; ucCount--) { memset(ucLEDDisplayMemory+c_LineWidth*ucCount, 0xFF, c_LineWidth); // memset(ucLEDDisplayMemory + 16*ucCount, 0, 16); RefreshLEDScreen(10); }
memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(10); }
memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(1); for(ucCount=0; ucCount<c_MaxColNumber; ucCount++) { uchar idata uci; for(uci=0; uci<c_MaxLineCount; uci++) { ucLEDDisplayMemory[uci*c_MaxLineByteCount+ucCount/8] |= ucDispDotMaskTab[ucCount%8]; } // memset(ucLEDDisplayMemory+c_LineWidth*ucCount, 0xFF, c_LineWidth); // memset(ucLEDDisplayMemory + 16*ucCount, 0, 16); RefreshLEDScreen(10); }
memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(1);
for(ucCount=c_MaxColNumber; ucCount>0; ucCount--) { uchar idata uci; for(uci=0; uci<c_MaxLineCount; uci++) { ucLEDDisplayMemory[uci*c_MaxLineByteCount+ucCount/8] |= ucDispDotMaskTab[ucCount%8]; } // memset(ucLEDDisplayMemory+c_LineWidth*ucCount, 0xFF, c_LineWidth); // memset(ucLEDDisplayMemory + 16*ucCount, 0, 16); RefreshLEDScreen(10); }
memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(1);
for(ucCount=1; ucCount<60; ucCount++) { uchar idata uci; uchar idata ucZMData; for(uci=0; uci<16; uci++) { ucZMData = ASCII816[ucCount][uci]; // ucLEDDisplayMemory[uci*c_MaxLineByteCount+c_HalfScreenMemoryOffset+8] =ucZMData; // ucLEDDisplayMemory[uci*c_MaxLineByteCount+8] =ucZMData; // ucLEDDisplayMemory[uci*c_MaxLineByteCount+c_HalfScreenMemoryOffset] =ucZMData; ucLEDDisplayMemory[uci*c_MaxLineByteCount] =ucZMData;
} // memset(ucLEDDisplayMemory+c_LineWidth*ucCount, 0xFF, c_LineWidth); // memset(ucLEDDisplayMemory + 16*ucCount, 0, 16); RefreshLEDScreen(20); memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(1);
}
memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(1); /* LED_DispString(1,"Tel:"); RefreshLEDScreen(20); */ memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); RefreshLEDScreen(1);
// LED_DispString(1,"Tel:025-51615878"); // LED_DispString(2,"Tel:025-83241657"); // RefreshLEDScreen(200);
// memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); // RefreshLEDScreen(1);
// LED_ScrollDispString(1, 20, "This is a Test Long String Disp Demo Line How are you!");
// memset(ucLEDDisplayMemory,0,c_LineWidth*c_MaxLineCount); // RefreshLEDScreen(1); // } } |