#include
#define uchar unsigned char
#define uint unsigned int
uchar key_l,key,i;
uchar code temp1[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
uchar code temp2[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
uchar code aa[16]=" :";
uchar code smg[]=" shun zhuan mian kuai gen kuai ting zhi fan zhuan ";
sbit e=P2^6;
sbit rs=P2^4;
sbit rw=P2^5;
void delay(int tt)
{
while(tt--);
}
void w_cmd(uchar dd)
{
rs=0;
rw=0;
e=0;
delay(50);
P0=dd;
e=1;
delay(50);
e=0;
delay(50);
}
void w_dat(uchar dd)
{
rs=1;
rw=0;
e=0;
delay(50);
P0=dd;
e=1;
delay(50);
e=0;
}
void init(uchar smg4[],uchar time[])
{
w_cmd(0x38);
delay(2000);
w_cmd(0x38);
delay(500);
w_cmd(0x38);//注意顺序 ,设置工作方式,显示模式设置
delay(500);
w_cmd(0x08);//注意顺序,关闭显示
w_cmd(0x01);//清屏
w_cmd(0x07);//光标·画面滚动模式设置
w_cmd(0x0c);//显示及光标模式设置
w_cmd(0x80);//
for(i=0;i<16;i++)
w_dat(time[i]);
w_cmd(0x80+0X40);
for(i=0;i<16;i++)
w_dat(smg4[i]);
}
void Tb(uchar smg[],uchar n,uchar s,uchar l,uchar d)
{
unsigned char m;
w_cmd(0x82);
for(m=n;m
w_dat(smg[m]);
w_cmd(0x80+0X42);
for(m=l;m w_dat(smg[m]); } void main() { init(aa,aa); while(1) { P1=0xf0; key_l=P1; if(key_l!=0xf0) { delay(100); if(key_l!=0xf0) { P1=key_l|0x0f; key=P1; } } switch(key) { case 0xee: Tb(smg,0,10,11,21); for(i=0;i<8;i++) { P2=temp1[i]; delay(500); } break; case 0xde:Tb(smg,0,10,19,29); for(i=0;i<8;i++) { P2=temp1[i]; delay(300); } break; case 0xbe:Tb(smg,0,10,30,40); for(i=0;i<8;i++) { P2=temp1[i]; delay(100); } break; case 0x7e:P2=0xff;Tb(smg,0,10,39,49); break; case 0xed:Tb(smg,50,60,11,21); for(i=0;i<8;i++) { P2=temp2[i]; delay(200); } break; case 0xdd:Tb(smg,50,60,19,29); for(i=0;i<8;i++) { P2=temp2[i]; delay(120); } break; case 0xbd: P2=0xff;Tb(smg,50,60,40,50); break; } } }
这不只是C语言能解决的问题啊,要设计原理图,写程序。你是要实物还是仿真啊,仿真还好一些,要是实物那就更麻烦了。再说只悬赏30分,做单片机的就这么不值钱吗?
可以交流
典型关于步进电机问题