|
驅動點陣有很多方法,比如單用HC138,單用HC595以及它兩混用均可,本壇也有許多例子供大家參考,但是它們都是采用級聯的方式來做,出于初學者的好奇心,想用一片595控制列,一片控制行,而不采用級聯,然而程序無法運行。不知是程序問題還是硬件本身不支持這種接法,請高手們指教!
程序:
#include <reg51.H>
//#define uint unsigned int
//#define uchar unsigned char
typedef unsigned char u8;
typedef unsigned int u16;
sbit ds1 =P2^0;
sbit shcp = P2^1;
sbit stcp = P2^2;
sbit ds2 = P2^3;
u8 code display[]={
0x66,0x99,0x81,0x81,0x42,0x24,0x18,0x00};//“心”圖案
u8 code wei[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
void delay(u8 b)//延時
{
while(b--);
}
/**************** 向HC595發送一個字節函數 ******************/
void Send1(u8 dat)
{
u8 i;
for(i=0;i<8;i++)
{
ds1 =dat&0x01;
dat>>=1;
shcp = 1;
shcp = 0;
}
stcp = 1;
stcp = 0;
}
void Send2(u8 ddat)
{
u8 j;
for(j=0;j<8;j++)
{
ds2 =ddat&0x80;
ddat<<=1;
shcp = 1;
shcp = 0;
}
stcp = 1;
stcp = 0;
}
void main()
{
u8 k;
while(1)
{
for(k=0;k<8;k++)
{
Send2(wei[k]);
Send1(display[k]);
delay(100);
}
}
}
|
|