#include <reg52.h>
#include <intrins.h>
#define uchar unsigned char
#define uint unsigned int
#define NOP _nop_()
sbit OUT1=P1^2; //
sbit OUT2=P1^3; //
sbit OE=P1^1; //74HC245 A1
sbit A1=P1^0; //74HC138A
sbit B1=P3^7; //74HC138B
sbit SRCK=P1^7; //11脚 移位时钟
sbit RCK=P1^4; //12脚 锁存时钟
sbit SER=P1^5; //14 脚数据输入
uchar code table[640]=
{
0x40,0x80,0x20,0x40,0x20,0x20,0x00,0x20,
0x89,0x00,0x49,0x00,0x51,0x08,0x15,0x04,
0x25,0x02,0x29,0x02,0xC9,0x00,0x51,0x08,
0x41,0x08,0x41,0x08,0x40,0xF8,0x00,0x00,
0x10,0x00,0x11,0xFC,0x20,0x20,0x3E,0x20,
0x40,0x20,0x7C,0x20,0x90,0x20,0x11,0xFC,
0xFE,0x20,0x10,0x28,0x10,0x24,0x12,0x24,
0x14,0x20,0x18,0x20,0x13,0xFE,0x00,0x00
};
void delay(uint t)
{
uint i,j,k;
for(i=0;i<t;i++)
{
for(j=0;j<10;j++)
{
for(k=0;k<20;k++);
}
}
}
void serial_input(uchar dat)
{
uint m;
for(m=0;m<8;m++)
{
if(dat&0x80)
SER=1;
else
SER=0;
SRCK=0;
SRCK=1; //数据移入移位寄存器
NOP;
NOP;
SRCK=0;
NOP;
NOP;
dat=dat<<1;
}
}
void serial_output()
{
RCK=1; //上升沿移位寄存器数据存入8为锁存器
NOP;
NOP;
RCK=0;
}
void HC138_scan(uchar temp)
{
OE=1;
A1=0x01&temp;
B1=0x01&(temp>>1);
}
void display()
{
uint i,j,k;
for(k=0;k<4;k++) //4行同时扫描,共扫4次4X4=16
{
for(j=0;j<2;j++) //两个字的其中一个
{
for(i=0;i<2;i++) //一个字的两排 i=0为一个字的左半部i=1为一个字的右半部
{
serial_input(~table[3*8+2*k+i+j*32]);//第一个起始为24 J=0X*32 j*32
serial_input(~table[2*8+2*k+i+j*32]);//第一个起始为16
serial_input(~table[1*8+2*k+i+j*32]);//第一个起始为8
serial_input(~table[0*8+2*k+i+j*32]);//第一个起始为0
}
}
serial_output();
HC138_scan(k);
}
}
void main()
{
while(1)
{
display();
}
}