#include <reg51.h>
#include <intrins.h>
sbit ser = P3^4;
sbit rclk= P3^5;
sbit srclk = P3^6;
unsigned char code ledbuf[40] = {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x41,0x7F,0x7F,0x41,0x00,0x00,
0x38,0x44,0x42,0x21,0x21,0x42,0x44,0x38,
0x00,0x00,0x7E,0x7F,0x03,0x03,0x7F,0x7E,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
unsigned char code P0buf[8] = {0x7f,0xbf,0xdf,0xef,
0xf7,0xdb,0xfd,0xfe};
void HC595SendByte(unsigned char dat)
{
unsigned char i;
srclk = 0;
rclk = 0;
for(i=0;i<8;i++)
{
ser = dat>>7;
dat=dat<<1;
srclk = 1;
_nop_();
_nop_();
srclk = 0;
}
rclk = 1;
_nop_();
_nop_();
rclk = 0;
}
void main()
{
TMOD=0x01;
TH0 = 0xfc;
TL0 = 0x67;
EA = 1;
ET0 =1;
TR0 = 1;
while(1);
}
void InterruptTimer0() interrupt 1
{
static unsigned char i= 0;
static unsigned char cnt= 0;
static unsigned char tmr250ms = 0;
TH0 = 0xfc;
TL0 = 0x67;
if(i>=8)
{i=0;}
P0 = 0xff;
HC595SendByte(ledbuf[cnt+i]);
P0 =P0buf[i]; //
i++;
tmr250ms++;
if(tmr250ms>=250)
{
cnt++;
tmr250ms = 0;
if(cnt>=32)
cnt = 0;
}
}
|
在点阵显示上出现不想要的图形