- #include <reg51.h>
- #define uchar unsigned char
- #define uint unsigned int
- sbit SHCP=P3^6;//595的移位信号
- sbit STCP=P3^5;//是595的锁存信号
- sbit SDA=P3^4;//红数据
- sbit IA=P1^0;//行控制线A
- sbit IB=P1^1;//行控制线B
- sbit IC=P1^2;//行控制线C
- /********************************************************************/
- #define scan0 {IA=0;IB=0;IC=0;}
- #define scan1 {IA=1;IB=0;IC=0;}
- #define scan2 {IA=0;IB=1;IC=0;}
- #define scan3 {IA=1;IB=1;IC=0;}
- #define scan4 {IA=0;IB=0;IC=1;}
- #define scan5 {IA=1;IB=0;IC=1;}
- #define scan6 {IA=0;IB=1;IC=1;}
- #define scan7 {IA=1;IB=1;IC=1;}
- #define light 3
- extern uint uiAllData; //定义亮度
- uchar code hanzi[]; //汉字字模
- uchar Move,Speed,line,tome_count; //(移位 速度 行 ) 定义
- uint zimuo; //字模计数器
- uint uiAllData;
- uchar BUFF[10]; //缓存
- void DelayMs(void); // 延时
- void in_data(); // 调整移动数据
- void rxd_data(); // 发送移动数据
- uchar time_count=0; //计数
- void rxd_data1(); // 发送移动数据
- /******************************************************/
- /*****不影响其他端口的扫描*************************/
- void scan(unsigned char Value)
- {switch(Value)
- { case 0: scan0;break;
- case 1: scan1;break;
- case 2: scan2;break;
- case 3: scan3;break;
- case 4: scan4;break;
- case 5: scan5;break;
- case 6: scan6;break;
- case 7: scan7;break;
- default:break;
- }
- }
- /**************************延时***********************/
- void DelayMs(void)
- {
- uchar TempCyc;
- for(TempCyc=250;TempCyc>1;TempCyc--)
- {;}
- }
- /********************************************/
- /*主函数*/
- void main()
- {
- Move=0;
- zimuo=0;
- while(1)
- {
- //利用sizeof()语句 运算字幕有效数据的总数;
- while(zimuo<1024)//2048)//定义显示字幕数据的长度 2048/32=64 即显示完64个16*16大小的字符后 重新循环
- {
- while(Move<16) //数据移位。
- {
- for(Speed=0;Speed<3;Speed++) //移动速度控制
- {
- for(line=0;line<8;line++)
- {
- in_data(); //调整移动数据
- rxd_data(); //装载移动数据
- scan(line); //输出行扫描
-
- STCP=1;//锁存
- STCP=0;
-
- DelayMs(); //延时,等待一段时间,让这列显示的内容在人眼内产生“视觉暂留”现象。
- DelayMs();
-
- }
- }
- Move++; //移动一步
- }
- Move=0;
- zimuo=zimuo+64; //换下一个字 这里不在移动地址 就实现了静态显示
- }
-
- TMOD=0x01; //定时器0 16位定时定时器1方式2
- TH0=0x4c; //50ms
- TL0=0x00;
- TR0=1; //开定时器计数
- ET0=1; //开定时器中断
- EA=1; //开中断
- while(tome_count<9) //怎么样跳出这个循环????????
- {
- }
-
- zimuo=0;
- }
- }
-
- /**********************************************************/
- void in_data(void) //调整数据一个屏2个字的数据
- {
- char s;
- for(s=2;s>=0;s--) //一个屏能显示4个字 取最前面的字发送给595的最前面
- { //zimuo 是个计算显示到哪个字的计数器 s是取4个字的循环 line是显示到哪一行 根据这几个参数计算出一个屏中现在需要显示的数据 放入BUFF 内存中 等待发送给595
- BUFF[2*s]=hanzi[zimuo+32*s+2*line]; //要知道为什么这么算就需要知道取模的方向和原理 一行有8个字节 (一个中文16*16的字 一行有2个字节)
- BUFF[2*s+1]=hanzi[zimuo+1+32*s+2*line];//把一个字的首字节放入BUFF[0]中 后面一个字节放入BUFF[1] 以此类推剩下的3个字
- }
- }
- /***********************发送移动的数据****************************/
- void rxd_data(void) //串行发送数据
- {
- uchar s;
- uchar temp,k;
- for(s=0;s<4;s++) //发送4字节数据
- {
- temp=BUFF[s];
- temp=255-temp;
- SDA=0;
- for(k=0;k<8;k++)//一个字节8位 发送给595
- {
- SHCP=0; //上升沿移位595
- SDA=(bit)(temp&0x01);//通过IO口送一个位给 595 0x01
- temp=temp>>1; //字节移位 准备送下一位
- SHCP=1;
- }
- }
- }
- void Timer0Interrupt(void) interrupt 1 //定时器中断
- {
- TH0 = 0x04C;//定时50MS 这里的晶振是18.432M 测试无需理会晶振大小
- TL0 = 0x000;
-
- time_count++;
- if(time_count>8)//发送一次数据
- {
- time_count=0;
- line++; //下一行
- if(line>8) //共16行
- {
- line=0; //重新移动
- }
- rxd_data1();//发送数据
- scan(line); //打开行扫描
- STCP=1;//锁存
- STCP=0;
- }
-
- }
- void rxd_data1(void) //串行发送数据
- {
- uchar s;
- uchar k;
- for(s=0;s<4;s++)//发送4字节数据 一行4个字节
- {
- for(k=0;k<8;k++) //一个字节8位
- {
- SHCP=0; //上降沿移位595
- SDA=1;
- SHCP=1;
- }
- }
- }
- const uchar code hanzi[]={
- 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,/*"未命名文件",0*/
- 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,/*"未命名文件",0*/
- 0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,
- 0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,/*"未命名文件",0*/
- 0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,0x3F,
- 0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,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,/*"未命名文件",0*/
- 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,
- 0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,/*"未命名文件",0*/
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
- 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,/*"未命名文件",0*/
- 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,/*"未命名文件",0*/
- 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,/*"未命名文件",0*/
- 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,/*"未命名文件",0*/
- 0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,/*"未命名文件",0*/
- 0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*"未命名文件",0*/
- 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,/*"未命名文件",0*/
- };
复制代码 |