需要s1按鍵為按一下正向移動在按一下暫停,s2為按一下反向移動在按一下暫停,找不到問題在哪里,暫停也不會在當(dāng)前進度暫停而是回到開始了。
#include<reg51.h>
sbit shcp=P1^2;//數(shù)據(jù)輸入時鐘線 595的11腳
sbit stcp=P1^1;//輸出存儲器鎖存時鐘線 595的12腳
sbit ds=P1^0;//數(shù)據(jù)線 595的14腳
sbit s1=P3^1;//按下后會暫停,再按就會繼續(xù)
sbit s2=P3^2;//按下后顯示數(shù)字的傳送方向取反
bit fx;//方向切換
unsigned char TIME1;//設(shè)置數(shù)據(jù)移動定時時間
unsigned int ABC;//設(shè)置控制顯示的字符
unsigned char DD=4;
unsigned int ZZ;//總字符
unsigned char code tab[]={
0x02,0x04,0x22,0x48,0x2A,0x52,0xA6,0x41,0x63,0xFE,0x26,0x40,0x2A,0x50,0x22,0x49,
0x00,0x06,0x3F,0xF8,0x22,0x00,0x22,0x00,0x23,0xFF,0x42,0x00,0x02,0x00,0x00,0x00,//顯示’新’字
0x04,0x20,0x08,0x20,0x10,0x20,0x3F,0xA0,0xC0,0x20,0x04,0x20,0x04,0x20,0x08,0xFF,
0xFE,0x20,0x11,0x20,0x11,0x20,0x21,0x20,0x41,0x20,0x07,0x20,0x00,0x20,0x00,0x00,//顯示‘華’字
0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,
0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00,//顯示’學(xué)‘字
0x00,0x00,0x7F,0xFF,0x44,0x20,0x5A,0x10,0x61,0xE0,0x08,0x01,0x30,0x82,0x24,0x8C,
0x24,0xF0,0xA4,0x80,0x64,0x80,0x24,0xFC,0x24,0x82,0x28,0x82,0x30,0x8E,0x00,0x00,//顯示‘院‘字
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
};
unsigned char code tab1[]={
0x00,0x00,0x7F,0xFF,0x44,0x20,0x5A,0x10,0x61,0xE0,0x08,0x01,0x30,0x82,0x24,0x8C,
0x24,0xF0,0xA4,0x80,0x64,0x80,0x24,0xFC,0x24,0x82,0x28,0x82,0x30,0x8E,0x00,0x00,//顯示’院‘字
0x02,0x20,0x0C,0x20,0x88,0x20,0x69,0x20,0x09,0x20,0x09,0x22,0x89,0x21,0x69,0x7E,
0x09,0x60,0x09,0xA0,0x19,0x20,0x28,0x20,0xC8,0x20,0x0A,0x20,0x0C,0x20,0x00,0x00,//顯示‘學(xué)’字
0x04,0x20,0x08,0x20,0x10,0x20,0x3F,0xA0,0xC0,0x20,0x04,0x20,0x04,0x20,0x08,0xFF,
0xFE,0x20,0x11,0x20,0x11,0x20,0x21,0x20,0x41,0x20,0x07,0x20,0x00,0x20,0x00,0x00,//顯示‘華’字
0x02,0x04,0x22,0x48,0x2A,0x52,0xA6,0x41,0x63,0xFE,0x26,0x40,0x2A,0x50,0x22,0x49,
0x00,0x06,0x3F,0xF8,0x22,0x00,0x22,0x00,0x23,0xFF,0x42,0x00,0x02,0x00,0x00,0x00,//顯示‘新’字
};
void delay(unsigned int dz)//設(shè)置延時子函數(shù)
{
unsigned char x1;
for(;dz>0;dz--)
for(x1=999;x1>0;x1--);
}
void writedata(unsigned char d1,unsigned char d2) //設(shè)置595顯示子函數(shù)
{
unsigned char i;
//設(shè)置CY存儲移位之后的數(shù)據(jù) 設(shè)置CY進位標(biāo)志位,單片機內(nèi)部的寄存器,移位之后的數(shù)據(jù)保存在CY
for(i=0;i<8;i++)//設(shè)置八次循環(huán)
{
d1=d1<<1;//令數(shù)據(jù)左移11110001
ds=CY;//設(shè)置發(fā)送數(shù)據(jù)
shcp=1;//上升沿發(fā)生移位,數(shù)據(jù)寄存器的數(shù)據(jù)鎖存。
shcp=0;
}
for(i=0;i<8;i++)//同樣設(shè)置八次循環(huán)
{
d2=d2<<1;//令數(shù)據(jù)左移
ds=CY;//設(shè)置發(fā)送數(shù)據(jù)
shcp=1;//上升沿發(fā)生移位,數(shù)據(jù)寄存器的數(shù)據(jù)鎖存 。
shcp=0;
}
stcp=0;
stcp=1;//上升沿將數(shù)據(jù)送到輸出鎖存器
stcp=0;
}
void main()
{
char i,aa;
TMOD=0x01;//設(shè)置定時器0與模式1與16位定時模式
TH0=(65536-10000)/256;//定時10.000ms
TL0=(65536-10000)%256;
ET0=1;//使能定時器0
EA=1;//設(shè)置開啟總中斷
TR0=1;//開始計數(shù)
ZZ=(DD+1)*32;
while(1) //設(shè)置無限循環(huán)
{
if(s1==0)//用于檢測按鍵
{
delay(30);//設(shè)置延時消除,按鍵抖動
if(s1==0)
{
fx=0;
aa=0;ABC=0;
if(fx==0)ABC=0;
TR0=0;
while(s1==0);
}
}
if(s2==0)//用于檢測按鍵
{
delay(30);//設(shè)置延時消除,按鍵抖動
if(s2==0)
{
fx=~fx;//設(shè)置取反方向
TR0=0;
aa=0;
//使顯示的數(shù)據(jù)正向移動
if(fx==1)ABC=ZZ;//使顯示的數(shù)據(jù)反向移動
while(s2==0);//等待按鍵松手
}
}
for(i=0;i<16;i++)//設(shè)置循環(huán)移位
{
//兩片138組成4-16線譯碼器
P2=i;//設(shè)置列數(shù)據(jù)驅(qū)動,138的驅(qū)動端口
if(fx==0)writedata(tab[ABC+aa],tab[ABC+aa+1]);//設(shè)置想要顯示的數(shù)據(jù)
if(fx==1)writedata(tab1[ABC+aa],tab1[ABC+aa+1]);//設(shè)置想要顯示的數(shù)據(jù)
delay(3);//延時
writedata(0,0);//清屏
aa+=2;//數(shù)據(jù)加 實現(xiàn)掃描
if(aa>30)aa=0;//循環(huán)16次 清零
}
}
}
void timer0() interrupt 3
{
TH0=(65536-10000)/256;//10.000ms 設(shè)置進入一次中斷
TL0=(65536-10000)%256;
TIME1++;
if(TIME1==10)//設(shè)置到100.000ms時間加以實現(xiàn)移動,控制移動速度
{
TIME1=0;
if(fx==0)//設(shè)置正向移動
{
ABC=ABC+2; //每次送兩個編碼數(shù)據(jù)
if(ABC>ZZ)//達到總字符
ABC=0;//數(shù)據(jù)清零
}
else//否則反向移動
{
ABC=ABC-2;//設(shè)置每次送兩個編碼數(shù)據(jù)
if(ABC<2)//數(shù)據(jù)完畢
ABC=ZZ;//回到總字符
}
}
}
|