PIC單片機(jī)實(shí)例八:四種方式24X24點(diǎn)陣顯示
掃描二維碼
隨時(shí)隨地手機(jī)看文章
最近終于有空更新了,花了幾天時(shí)間,弄出個(gè)小東西,雖然有很多種實(shí)現(xiàn)方式在網(wǎng)上流傳了,但我卻從沒(méi)有試過(guò),乘有時(shí)間,也弄出了四種方式的顯示,各位幫忙看看,哪里還有不好的地方,希不吝指教.
一.原理及仿真圖
此種為從右往左顯示.
此中為從左往右顯示
此種為從下往上顯示
此種為從上往下顯示
原理圖說(shuō)明:
1.本實(shí)例采用微芯PIC16F877A單片機(jī),此單片機(jī)適合初學(xué)者
2.點(diǎn)陣采用24X24點(diǎn),左邊為行線(xiàn),采用U1-U3三個(gè)74LS373地址所存芯片,復(fù)用單片機(jī)RB端口.
右邊為列線(xiàn),采用U4-U6三個(gè)74LS373地址所存芯片,復(fù)用單片機(jī)RD端口.
3.單片機(jī)RC端口控制六片373的選通.
4.顯示原理:24列列線(xiàn)輪流拉為低電平時(shí),行線(xiàn)輸出行瑪,通過(guò)一定延時(shí),字符即可顯示,并通過(guò)計(jì)算,即可實(shí)現(xiàn)上述四種顯示方式.
二.程序(已附解釋,PICC 8.05 通過(guò))
#include
#define uch unsigned char
int offset;//定義偏置變量,以使字符運(yùn)動(dòng)
//以下為需顯示的字符數(shù)組
const uch zxhn[]=
{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x10,0x30,0xE0,0x60,0x00,0x80,0x00,0xF0,0xF0,0x10,0x00,0xF0,0xE0,
0x20,0x00,0x00,0xF0,0xF0,0x10,0x00,0x00,0x00,0x81,0x83,0x8E,0xCE,0xE0,0x78,0x76,
0x3D,0x00,0xFF,0x7F,0x04,0x38,0xFF,0xFF,0x00,0x3C,0x38,0xFF,0xFF,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x3F,0x3F,0x20,0x10,0x18,0x0E,0x07,0x00,0x00,0x00,0x1F,0x1F,
0x00,0x00,0x00,0x3F,0x3F,0x00,0x00,0x00,//"洲",
0x00,0x00,0x00,0x30,0x60,0x00,0x80,0x70,0x30,0x90,0x40,0x40,0x40,0x40,0xE0,0xE0,
0x40,0x40,0x40,0x40,0xE0,0xE0,0x40,0x00,0x00,0x41,0x49,0x49,0x49,0xFF,0xFF,0x49,
0x6D,0x6D,0x4B,0x9C,0x8C,0x40,0xFF,0xFF,0x01,0x8E,0x8C,0x40,0xFF,0xFF,0x00,0x00,
0x00,0x40,0x20,0x10,0x0C,0x07,0x01,0x00,0x00,0x03,0x03,0x11,0x10,0x30,0x3F,0x1F,
0x11,0x11,0x10,0x70,0x3F,0x3F,0x00,0x00,//"翔"
0x00,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0xC0,0xC0,0x80,0x00,0x00,0xE0,0xF8,0x38,
0x10,0x00,0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x02,0x04,0x18,0xB0,0xE0,0xFC,
0x9F,0x23,0x10,0x0C,0x07,0xC3,0xFD,0x3D,0x3D,0xE5,0x19,0x07,0x03,0x03,0x01,0x00,
0x00,0x10,0x08,0x04,0x03,0x41,0x20,0x21,0x27,0x1F,0x18,0x0C,0x06,0x03,0x01,0x00,
0x00,0x03,0x0F,0x1C,0x38,0x18,0x10,0x10,//"歡"
0x00,0x00,0x00,0x10,0x30,0xE0,0xC0,0x00,0x00,0xC0,0xC0,0x20,0x30,0x38,0x10,0xF0,
0xC0,0x40,0x40,0x40,0xE0,0xC0,0x40,0x00,0x00,0x00,0x08,0x08,0x08,0xFC,0xFC,0x08,
0x80,0xFF,0xFF,0x40,0x20,0x20,0x00,0xFF,0xFF,0x40,0x80,0x80,0xFF,0xFF,0x00,0x00,
0x00,0x00,0x18,0x18,0x0C,0x07,0x07,0x0C,0x08,0x18,0x10,0x10,0x30,0x30,0x30,0x37,
0x37,0x30,0x30,0x31,0x30,0x30,0x10,0x08,//"迎"
0x00,0x00,0x00,0x00,0x80,0xC0,0x70,0x30,0x10,0x00,0x00,0xC0,0x70,0x78,0x50,0x40,
0x40,0x40,0x40,0xC0,0xE0,0x40,0x40,0x00,0x00,0x08,0x04,0x02,0x03,0xFF,0x7F,0x00,
0x40,0x22,0x11,0x9C,0x0E,0x44,0xC0,0xFF,0x7F,0x01,0x06,0x09,0x38,0x70,0x00,0x00,
0x00,0x00,0x10,0x30,0x3C,0x1F,0x00,0x1F,0x3F,0x31,0x30,0x30,0x37,0x37,0x30,0x38,
0x3E,0x18,0x01,0x02,0x0E,0x1C,0x18,0x00, //"您"
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
const uch col[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//列碼
//初始化子程序
void init()
{
ADCON1=0x06;//初始化RA口為普通數(shù)字端口
TRISA=0X20;
PORTA=0;
TRISB=0;
PORTB=0;
TRISC=0;
PORTC=0;
TRISD=0;
PORTD=0;
}
//延時(shí)子程序
void delay1ms()
{
uch i;
for(i=0;i<150;i++)
{NOP();
}
}
//從右往左顯示
void display1()
{
uch i,j,k,t,n;
int m=0;//字符定位變量
for(n=0;n<6;n++)
{
for(offset=0;offset<24;offset++)//偏置最多24位
{
for(t=0;t<4;t++)//每個(gè)位置顯示4次
{
for(i=0;i<24;i++)//取數(shù),每行24列,故取24個(gè)數(shù)
{
PORTD=0xff;//一開(kāi)始先把列置高電平,關(guān)顯示
PORTC=0x70;
NOP();
PORTC=0;
PORTB=zxhn[i+offset+m];//取行碼
if((i+offset)>23)PORTB=zxhn[i+offset+48+m];
RC0=1;
NOP();
RC0=0;
PORTB=zxhn[i+24+offset+m];
if((i+offset)>23)PORTB=zxhn[i+offset+72+m];
RC1=1;
NOP();
RC1=0;
PORTB=zxhn[i+48+offset+m];
if((i+offset)>23)PORTB=zxhn[i+offset+96+m];
RC2=1;
NOP();
RC2=0;
j=i/8;//求需要選通的行線(xiàn)
k=i%8;//求需要選通的列線(xiàn)
PORTD=col[k];
switch(j)
{
case 0: RC4=1; NOP(); RC4=0; break;
case 1: RC5=1; NOP(); RC5=0; break;
case 2: RC6=1; NOP(); RC6=0; break;
}
delay1ms();//視覺(jué)暫留
}
}
}
m=m+72;//定位下一個(gè)初始字符
}
}
//從左往右顯示
void display2()
{
uch i,j,k,t,n,tt1,tt2,tt3;
int m=0;//字符定位變量
for(n=0;n<6;n++)
{
for(offset=24;offset>0;offset--)//偏置最多24位
{
for(t=0;t<4;t++)//每個(gè)位置顯示4次
{
for(i=24;i>0;i--)//取數(shù),每行24列,故取24個(gè)數(shù)
{
if((i+offset)>23)
{
tt1=zxhn[i+offset-24+m];
tt2=zxhn[i+offset+m];
tt3=zxhn[i+offset+24+m];
}
else
{
tt1=zxhn[i+offset+m+72];
tt2=zxhn[i+offset+m+96];
tt3=zxhn[i+120+offset+m];
}
PORTD=0xff;//一開(kāi)始先把列置高電平,關(guān)顯示
PORTC=0x70;
NOP();
PORTC=0;
PORTB=tt1;//取行碼
RC0=1;
NOP();
RC0=0;
PORTB=tt2;
RC1=1;
NOP();
RC1=0;
PORTB=tt3;
RC2=1;
NOP();
RC2=0;
j=(i-1)/8;//求需要選通的373
k=(i-1)%8;//求需要選通的列線(xiàn)
PORTD=col[k];
switch(j)
{
case 0: RC4=1; NOP(); RC4=0; break;
case 1: RC5=1; NOP(); RC5=0; break;
case 2: RC6=1; NOP(); RC6=0; break;
}
delay1ms();//視覺(jué)暫留
}
}
}
m=m+72;
}
}
//從下往上顯示
void display3()
{
uch i,j,k,t,n,tt1,tt2,tt3,l;
int m=0;//字符定位變量
for(n=0;n<18;n++)
{
for(l=0;l<7;l++)//滾動(dòng)8位
{
for(t=0;t<3;t++)//每個(gè)位置顯示4次
{
for(i=0;i<24;i++)//取數(shù),每行24列,故取24個(gè)數(shù)
{
tt1=(zxhn[i+m]>>l)|(zxhn[i+24+m]<<(8-l));
tt2=(zxhn[i+24+m]>>l)|(zxhn[i+48+m]<<(8-l));
tt3=(zxhn[i+48+m]>>l)|(zxhn[i+72+m]<<(8-l));
PORTD=0xff;//一開(kāi)始先把列置高電平,關(guān)顯示
PORTC=0x70;
NOP();
PORTC=0;
PORTB=tt1;//取行碼
RC0=1;
NOP();
RC0=0;
PORTB=tt2;
RC1=1;
NOP();
RC1=0;
PORTB=tt3;
RC2=1;
NOP();
RC2=0;
j=i/8;//求需要選通的373
k=i%8;//求需要選通的列線(xiàn)
PORTD=col[k];
switch(j)
{
case 0: RC4=1; NOP(); RC4=0; break;
case 1: RC5=1; NOP(); RC5=0; break;
case 2: RC6=1; NOP(); RC6=0; break;
}
delay1ms();//視覺(jué)暫留
}
}
}
m=m+24;
}
}
//從上往下顯示
void display4()
{
uch i,j,k,t,n,tt1,tt2,tt3,l,a,b;
int m=0;//字符定位變量
for(n=0;n<6;n++)
{
for(l=0;l<24;l++)
{
for(t=0;t<3;t++)//每個(gè)位置顯示4次
{
for(i=0;i<24;i++)//取數(shù),每行24列,故取24個(gè)數(shù)
{
a=l/8;
b=l%8;
if(a==0)
{
tt1=(zxhn[i+m]<>(8-b));
tt2=(zxhn[i+24+m]<>(8-b));
tt3=(zxhn[i+48+m]<>(8-b));
}
if(a==1)
{
tt1=(zxhn[i+m+120]<>(8-b));
tt2=(zxhn[i+m]<>(8-b));
tt3=(zxhn[i+24+m]<>(8-b));
}
if(a==2)
{
tt1=(zxhn[i+m+96]<>(8-b));
tt2=(zxhn[i+m+120]<>(8-b));
tt3=(zxhn[i+m]<>(8-b));
}
PORTD=0xff;//一開(kāi)始先把列置高電平,關(guān)顯示
PORTC=0x70;
NOP();
PORTC=0;
PORTB=tt1;//取行碼
RC0=1;
NOP();
RC0=0;
PORTB=tt2;
RC1=1;
NOP();
RC1=0;
PORTB=tt3;
RC2=1;
NOP();
RC2=0;
j=i/8;//求需要選通的行線(xiàn)
k=i%8;//求需要選通的列線(xiàn)
PORTD=col[k];
switch(j)
{
case 0: RC4=1; NOP(); RC4=0; break;
case 1: RC5=1; NOP(); RC5=0; break;
case 2: RC6=1; NOP(); RC6=0; break;
}
delay1ms();//視覺(jué)暫留
}
}
}
m=m+72;
}
}
void main()
{
uch mo;
init();
while(1)
{
display1();
display2();
display3();
display4();
}
}
三.總結(jié)
雖然已有四種方式顯示了,但我覺(jué)得可以嘗試更多的方式,例如,可以象滾輪子一樣,旋轉(zhuǎn)著從左滾到右顯示,只是數(shù)據(jù)處理的量可能大了些,已經(jīng)有兩個(gè)自由度了,而我的四種只有一個(gè)自由度.由于本人水平有限,沒(méi)有想到什么好的思路,不過(guò)希望拋磚引玉,寫(xiě)出這種顯示方式.