27,381
社区成员
发帖
与我相关
我的任务
分享
#include<reg51.h>
#include<intrins.h>
#define NOP() _nop_()
sbit MOSIO=P3^0;
sbit R_CLK=P3^2;
sbit S_CLK=P3^1;
void HC595Send(unsigned int SendVal);
unsigned int Val;
unsigned char codetab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
unsigned char codedigittab[24][8]={
{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00},//0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00},//1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00},//2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00},//3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00},//4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00},//5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00},//6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00},//7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00},//8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00},//9
{0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00},//P
{0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00},//R
{0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00},//E
{0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00},//C
{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00},//H
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00},//I
{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00},//N
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00},
{0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00},//H
{0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00},//I
{0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00},//N
{0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00}
};
unsigned int timecount;
unsigned char cnta;
unsigned char cntb;
void HC595Send(unsigned int SendVal)
{
unsigned char i;
for(i = 0; i < 16; i++)
{
if((SendVal << i)&0x8000)
{
MOSIO=1; //setdatalinehigh0X8000
}
else
{
MOSIO=0; //MOSIO=1
}
S_CLK = 0;
NOP();
NOP();
S_CLK = 1;
}
R_CLK = 0; //setdatalinelow
NOP();
NOP();
R_CLK = 1;
}
void main(void)
{
TMOD=0x01;
TH0 = (65536 - 3000) / 256;
TL0 = (65536 - 3000) % 256;
TR0 = 1;
ET0 = 1;
EA = 1;
cntb = 0;
while(1)
{
}
}
void timer0() interrupt 1 using 0
{
TH0=(65536-3000) / 256;
TL0=(65536-3000) % 256;
if(cntb < 16)
{
P0 = ~codedigittab[cntb][cnta];
Val = codetab[cnta]&0x00ff;
Val <<= 8;
Val = Val + 0x00ff;
HC595Send(Val);
}
else
{
P0 = ~codedigittab[cntb - 24][cnta];
Val = codetab[cnta];
Val = Val + 0xFF00;
HC595Send(Val);
}
if(++cnta >= 8)
cnta = 0;
if(++timecount >= 333)
{
timecount = 0;
if(++cntb >= 36)
cntb = 0;
}
}