本帖最后由 sun520up 于 2011-5-28 11:50 编辑
第一行和第十七行会有显示是什么原因的?有些LED还不是很亮:handshake
列采用两片74HC154,一个接p1.0~P1.3,一个接P1.4~P1.7,控制32列,用32个S8550三极管驱动。行用两片74HC245驱动,上半部分接P0下半部分接P2
#include <reg52.h>
#define uchar unsigned char
#define uint unsigned int
#define hang1 P0 //hang1为点阵的上八行
#define hang2 P2 //hang2为点阵的下八行
#define lie P1 //P1口控制32列,P1.0~P1.3控制前16列,P1.4~P1.7控制后16列
sbit CS1=P3^0; //CS1为低电平时选通第一个74HC154
sbit CS2=P3^1; //CS2为低电平时选通第二个74HC154
uchar code date[]=
{
0x00,0x00,0x10,0x00,0x10,0x80,0x10,0x40,0x10,0x20,0x10,0x18,0x10,0x06,0xFF,0x01,
0x10,0x00,0x10,0x00,0x10,0x40,0x10,0x80,0x10,0x40,0xF0,0x3F,0x00,0x00,0x00,0x00,/*"力",0*/
0x40,0x40,0x40,0x40,0x40,0x40,0xDF,0x57,0x55,0x55,0x55,0x55,0x55,0x55,0xD5,0x7F,
0x55,0x55,0x55,0x55,0x55,0x55,0xDF,0x57,0x40,0x50,0x40,0x40,0x40,0x40,0x00,0x00,/*"量",1*/
};
void delay(uint z)
{
uchar x,y;
for(x=z;x>0;x--)
for(y=10;y>0;y--);
}
main()
{
uchar j,a=0;
uint i;
CS1=1;
CS2=1;
while(1)
{
CS1=0; //先扫描前16列
CS2=1;
a=0;
hang1=0;
hang2=0;
for(i=0;i<16;i++)
{
lie=i;
hang1=date[a];
delay(1);
a++;
hang2=date[a];
a++;
delay(1);
}
CS1=1; //然后扫描后16列
CS2=0;
j=0;
a=32;
i=0;
while(i<256)
{ i=16*j;
lie=i;
j++;
hang1=date[a];
delay(1);
a++;
hang2=date[a];
a++;
delay(1);
}
}
} |