|
单片机源程序如下:
- #include "reg51.h"
- #include "intrins.h"
- sbit sck=P2^0;
- sbit rck=P2^2;
- sbit ser=P2^1;
- #define uchar unsigned char
- #define uint unsigned int
- uchar dat1[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07}; //列数组
- uchar dat2[8]={0x00,0x66,0x99,0x81,0x81,0x42,0x24,0x18}; //行数组
- void sendrowbyte(uchar Val) //74ls595驱动行
- {
- uchar i=0;
- sck=1;
- for(i=0;i<8;i++)
- {
- if(Val&0x80) ser=1;
- else ser=0;
- Val<<=1;
- sck=0;
- sck=1;
- }
- rck=0;
- rck=1;
- }
- void sendcolbyte(uchar Val) //74ls138驱动列
- {
- switch(Val)
- {
- case 0:P3=dat1[0];break;
- case 1:P3=dat1[1];break;
- case 2:P3=dat1[2];break;
- case 3:P3=dat1[3];break;
- case 4:P3=dat1[4];break;
- case 5:P3=dat1[5];break;
- case 6:P3=dat1[6];break;
- case 7:P3=dat1[7];break;
- default: break;
- }
- }
- void MOVE_RIGHT(void) //右移函数
- {
- uchar i;
- for(i=0;i<8;i++)
- dat2[i]=_crol_(dat2[i],1);
- }
- void MOVE_LEFT(void) //左移函数
- {
- uchar i;
- for(i=0;i<8;i++)
- dat2[i]=_cror_(dat2[i],1);
- }
- void MOVE_DOWN(void) //上移函数
- {
- uchar i;
- uchar t=dat1[0];
- for(i=0;i<7;i++)
- dat1[i]=dat1[i+1];
- dat1[7]=t;
- }
- void MOVE_UP(void) //下移函数
- {
- uchar i;
- uchar t=dat1[7];
- for(i=7;i>0;i--)
- dat1[i]=dat1[i-1];
- dat1[0]=t;
- }
- void TIMER0_init(void)
- {
- TMOD=0x01;
- TH0=0xfc;
- TL0=0x66;
- TR0=1;
- EA =1;
- ET0=1;
- }
- void main(void)
- {
- TIMER0_init();
- while(1)
- {
- ;
- }
- }
- void TIMER0_Interrupt(void) interrupt 1
- {
- static uchar i =0;
- static uchar kcount=0;
- static uchar kmode =0;
- static uint tim =0;
- TH0=0xfc;
- TL0=0x66;
- tim++;
- if(tim==500) //移动的间隔,为500ms
- {
- tim=0;
- if(kcount == 8) //移动的步数,为8的整数倍才会移动的完整
- {
- kcount=0;
- kmode++;
- if(kmode==4) kmode=0;
- }
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
一楼
|
-
0.png
(57.44 KB, 下载次数: 47)
|