找回密码
 注册会员
更新自动建库工具PCB Footprint Expert 2024.04 Pro / Library Expert 破解版

led点阵屏左移显示时问题!急求!

[复制链接]
admin 发表于 2012-9-2 08:12:08 | 显示全部楼层 |阅读模式

本文包含原理图、PCB、源代码、封装库、中英文PDF等资源

您需要 登录 才可以下载或查看,没有账号?注册会员

×
led点阵屏左移显示时,用定时器中断扫描按键,按键按下就执行测试程序,问题是在执行左移显示时有问题。
是不是中断程序太长了,如果放在主程序,按下按键不会执行测试程序,哪位大哥能否帮忙看一下,并改正一下,谢谢!

#include<STC12C5A32S2.h>
#include"intrins.h" //调用_nop_();延时函数用
#define NOP() _nop_() /* 定义空指令 */
#define uchar unsigned char
#define uint unsigned int

uchar dat;
uchar j,k,m;
uint b;

sbit p14 = P1^4;
sbit p15 = P1^5;
sbit p16 = P1^6;
sbit p17 = P1^7;
sbit p52 = P5^2;
sbit p53 = P5^3;

sbit send_DATA =P5^1;
sbit shuchu_CLK =P5^0;
sbit yiwei_CLK =P4^0;
sbit EN = P4^3;
sbit p32 = P3^2;
sbit p33 = P3^3;
sbit p34 = P3^4;
sbit p35 = P3^5;
sbit p44 = P4^4;
uchar d=128;

uchar code HZ[]={
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xF7,0x7F,0xF3,0x77,0xEF,0x63,0xCF,0x1F,0xAC,0x7F,0x6F,0x7B,0xEF,0x7B,0xEF,0x83,
0xEE,0xFF,0xFE,0xFF,0x80,0x01,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,
/*以上为"华"的点阵*/
0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0x80,0x03,0xFE,0xFB,0xFE,0xFB,0xFE,0xFB,
0xFE,0xFB,0xFD,0xFB,0xFD,0xFB,0xFB,0xFB,0xFB,0xFB,0xF7,0xFB,0xEF,0xD7,0xDF,0xEF,
/*以上为"力"的点阵*/
0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xC0,0x07,0xDE,0xF7,0x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DF,0xF7,0xDF,0xF7,0xDF,0xFF,0xDF,0xFF,0xDF,0xFF,0xDF,0xDF,
0xC0,0x1F,0xDF,0xDF,0xDF,0xFF,0xDF,0xFF,0xDF,0xF7,0xDF,0xF7,0x80,0x07,0xFF,0xFF,
/*以上为"E"的点阵*/

0xFF,0xFF,0x80,0x1F,0xDF,0xEF,0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,
0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,0xDF,0xF7,0xDF,0xEF,0x80,0x1F,0xFF,0xFF,
/*以上为"D"的点阵*/
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,

0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
};

uchar code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};

uchar code a[16][4]={ {0,0,0,0},{0,0,0,1},{0,0,1,0},{0,0,1,1},
{0,1,0,0},{0,1,0,1},{0,1,1,0},{0,1,1,1},
{1,0,0,0},{1,0,0,1},{1,0,1,0},{1,0,1,1},
{1,1,0,0},{1,1,0,1},{1,1,1,0},{1,1,1,1}};

uchar data TD[18]; //装入临时数据时为逆序

//***********************************************函数声明
void delay1(unsigned int y);
void delay(uint de);
void load_oneline_data(uchar *LD); //装载一行数据
void send_oneline_data(uchar yid); //发送一行数据
void scan_oneline(uchar out); //扫描一行数据
void move_left_scan(uchar *pd);


/* ------74HC595移位扫描程序-------*/
void HC595(uchar dat)
{
uchar i;
for(i=0;i<8;i++)
{
if((dat<<i)&0x80) send_DATA=1;
else send_DATA=0;
yiwei_CLK=0;
NOP();
yiwei_CLK=1;
}
shuchu_CLK=0;
NOP();
shuchu_CLK=1;
}
/*----------延时函数程序----------*/
void delay1(uint y)
{ uint x,z;
for (x=0;x<y;x++)
{
for(z=0;z<114;z++);//延时0.5ms ,晶振22.1184MHz
}
}

void display_cswx()
{
for(b=0;b<600;b++)
{
for(k=0;k<8;k++)
{
for(j=0;j<8;j++)
{
HC595(tab[k]);
}
p35=a[m][0];
p34=a[m][1];
p33=a[m][2];
p32=a[m][3];
EN=0;
delay1(1);
EN=1;
}
}
m++;
if(m==16) m=0;
}

void display_czwy()
{ uint c;
uchar p,q,n;
for(c=0;c<2400;c++)
{
for(p=0;p<8;p++)
{
HC595(tab[q]);
}
p35=a[n][0];
p34=a[n][1];
p33=a[n][2];
p32=a[n][3];
EN=0;
delay1(1);
EN=1;
n++;
if(n==16) n=0;
}
q++;
if(q==8) q=0;
}

void display_ql()
{

for(b=0;b<30;b++)
{
for(k=0;k<8;k++)
{
for(j=0;j<8;j++)
{
HC595(tab[k]);
p35=a[m][0];
p34=a[m][1];
p33=a[m][2];
p32=a[m][3];
EN=0;
}
EN=1;
}
m++;
if(m==16) m=0;
}
}

void InitTimer1()
{
TMOD = 0x10;
TH1 = 0x28;
TL1 = 0x00;
EA = 1;
ET1 = 1;
TR1 = 1;
}


//*********左移显示函数*************
void move_left_scan(uchar *pd) //显示左移
{
uchar stup,temp,dely,movleft,*pt;
movleft=18;
while(movleft--)
{ for(temp=0;temp<16;temp++) //移动16次
{
for(dely=0;dely<8;dely++) //控制LED点阵显示屏的速度
{
for(stup=0;stup<16;stup++)
{
pt=pd+stup*2;
load_oneline_data(pt);
send_oneline_data(d+temp); //
scan_oneline(stup);
}
}
}
pd+=32;
}
}

//*********装载一行数据函数*************
void load_oneline_data(uchar *LD) //装载一行数据
{
uchar load;
for(load=0;load<9;load++)
{
TD[load*2]=*(LD+load*32);
TD[load*2+1]=*(LD+load*32+1);
//TD[16]=TD[17]=0XFF;
}
}
//*********发送一行数据函数*************
void send_oneline_data(uchar yid) //发送一行数据
{
uchar stup,tempD;
EN=1;
for(stup=0;stup<yid;stup++)
{ if(!(stup%8)) tempD=TD[stup/8];
yiwei_CLK=0;
if(tempD & 0x80) send_DATA=1;
else send_DATA=0;
yiwei_CLK=1;
tempD=tempD<<1;
}
shuchu_CLK=0;
NOP();
shuchu_CLK=1;
}
 楼主| admin 发表于 2012-9-2 08:12:12 | 显示全部楼层
//*********扫描一行数据函数*************
void scan_oneline(uchar m) //扫描一行数据
{
p35=a[m][0];
p34=a[m][1];
p33=a[m][2];
p32=a[m][3];
EN=0;
delay(1100); //大概延时5.5ms
EN=1;
}

void delay(uint de)
{
while(de--);
}

//**********主函数*******************
void main()
{ bit flag;
p44=1;
InitTimer1();
while(1)
{
move_left_scan(HZ);
}
}

void Timer1Interrupt() interrupt 3
{ bit flag;
uchar temp1;
TH1 = 0x28;
TL1 = 0x00; //定时器定时2.5ms
if(temp1>10)
{
flag=1;
temp1=0;
}
if((flag&p44)==0)
{ flag=0;
if((flag|p44)==0)
{
dat++;
while(!p44);
}
}
switch(dat)
{ case 0: HC595(0xff);break;
case 1: display_cswx();break;
case 2: display_czwy();break;
case 3: display_ql();break;
}
if(dat==4) dat=0;
}
*滑块验证:
您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

QQ|手机版|MCU资讯论坛 ( 京ICP备18035221号-2 )|网站地图

GMT+8, 2024-11-24 08:55 , Processed in 0.057094 second(s), 12 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表