完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
#include #include #include "array.h" //--重定义函数变量--// #define uchar unsigned char #define uint unsigned int #define ulong unsigned long //--定义SPI要使用的 IO--// ***it MOSIO = P3^4; ***it R_CLK = P3^5; ***it S_CLK = P3^6; //--全局函数声明--// void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0); /******************************************************************************* * 函 数 名 : main * 函数功能 : 主函数 * 输 入 : 无 * 输 出 : 无 *******************************************************************************/ void main(void) { int k, j, ms; //--定义一个指针数组指向每个汉字--// uchar *p[] ={tab17, tab1, tab2, tab3, tab4, tab5, tab6, tab7, tab8, tab9, tab10, tab11, tab12, tab13, tab14, tab15, tab16}; while(1) { for(ms = 20; ms > 0; ms--) //移动定格时间设置 { for(k = 0; k < 16; k++) //显示一个字 { HC595SendData(~(*(p[0] + 2*(k+j) + 1)),~(*(p[0] + 2*(k+j) )),tab0[2*k],tab0[2*k + 1]); //因为字模软件取的数组是高电平有效,所以列要取反 } //--清屏--// HC595SendData(0xff,0xff,0,0); //清屏 } j++; if(j == (17*15) ) { j = 0; } } } /******************************************************************************* * 函 数 名 : HC595SendData * 函数功能 : 通过595发送四个字节的数据 * 输 入 : BT3:第四个595输出数值 * * BT2: 第三个595输出数值 * * BT1:第二个595输出数值 * * BT0:第一个595输出数值 * 输 出 : 无 *******************************************************************************/ void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0) { uchar i; //--发送第一个字节--// for(i=0;i<8;i++) { MOSIO = BT3 >> 7 ; //从高位到低位 BT3 <<= 1; S_CLK = 0; S_CLK = 1; } //--发送第一个字节--// for(i=0;i<8;i++) { MOSIO = BT2 >>7; //从高位到低位 BT2 <<= 1; S_CLK = 0; S_CLK = 1; } //--发送第一个字节--// for(i=0;i<8;i++) { MOSIO = BT1 >> 7; //从高位到低位 BT1 <<= 1; S_CLK = 0; S_CLK = 1; } //--发送第一个字节--// for(i=0;i<8;i++) { MOSIO = BT0 >> 7; //从高位到低位 BT0 <<= 1; S_CLK = 0; S_CLK = 1; } //--输出--// R_CLK = 0; //set dataline low R_CLK = 1; //片选 R_CLK = 0; //set dataline low } |
|
相关推荐
2个回答
|
|
参看一下这个程序,希望能帮到你~~~~~
#include #define uchar unsigned char uchar i,j,k=15; ***it xsi=P2^0; ***it xrck=P2^1; ***it xsck=P2^2; ***it ysi=P2^3; ***it yrck=P2^4; ***it ysck=P2^5; ***it kg= P3^2; uchar code zbm[][32]={ {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,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,0xBF,0xF7,0xBF,0xFB,0xBF,0xFD,0x03,0xE0,0xFF,0xFF,0xFF,0xFF, 0x01,0xF0,0x7F,0xEF,0xBF,0xEF,0x9F,0xEF,0xDF,0xEF,0xFF,0xF1,0xFF,0xFF,0xFF,0xFF},/*"北",0*/ {0xF7,0xFF,0xF7,0xFF,0xF7,0xEF,0xF7,0xF3,0x37,0xFF,0xB7,0xFE,0xB6,0xDE,0xD5,0x80, 0xDB,0xFE,0x5B,0xFF,0x9B,0xFB,0xFB,0xF7,0xFB,0xE7,0xFB,0xFF,0xFF,0xFF,0xFF,0xFF},/*"京",1*/ {0xFF,0xEF,0x5F,0xF7,0xDF,0xFA,0xEF,0xFD,0x0F,0xFA,0xFF,0xDF,0xBF,0xEF,0xC7,0xF3, 0x58,0xFC,0xEF,0xFB,0xAF,0xF7,0xCF,0xEF,0xEF,0xCF,0xFF,0xDF,0xFF,0xDF,0xFF,0xFF},/*"欢",2*/ {0xBF,0xF7,0xBF,0xF7,0xBB,0xF6,0x37,0xF1,0xFF,0xF7,0x07,0xF6,0xF7,0xF6,0x7B,0xF7, 0xF9,0xEF,0x0F,0xE8,0xF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B,0xFD,0xBF,0xFD,0xFF,0xFD,0xFF,0xFD,0xFF,0xFF},/*"阵",4*/ {0xFF,0xEF,0xFF,0xF7,0xFF,0xF9,0x7F,0xFE,0x81,0xBD,0x75,0xDD,0x65,0xE5,0x55,0xF8}, {0xB6,0xFD,0x9A,0xFD,0x28,0x80,0xBC,0xFE,0xBF,0xFE,0xFF,0xFE,0xFF,0xFE,0xFF,0xFF},/*"屏",5*/ {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}, {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,}, }; void ys (uchar a) { //延时 uchar b; for (;a>0;a--) for (b=100;b>0;b--) ; } void yfs() {//Y轴发数 ysck=0; yrck=0; k++; if (k==16) { k=0; ysi=0; } else ysi=1; ysck=1; P2=P2|0X14; //相当于 xrck=1; yrck=1; } void xfs(uchar a) { //X轴发数 uchar b,a1,a2; a1=~zbm[6][a*2+1]; a2=~zbm[6][a*2]; xsck=0; xrck=0; for (b=0;b<8;b++) { a1=a1<<1; xsi=CY; xsck=1; xsck=0; } for (b=0;b<8;b++) { a2=a2<<1; xsi=CY; xsck=1; xsck=0; } } void fs(uchar a) { //X轴发数 uchar b; xsck=0; xrck=0; for (b=0;b<8;b++) { a=a<<1; xsi=CY; xsck=1; xsck=0; } } void gdhs(uchar *zz,uchar N,uchar Time) //流动显示N个汉字 滚动函数 { //参数三个:字符串字模首地址、字数、显示流动速度 uchar FontNum,i,j,row; //循环变量,字数计数、16次流动、16列扫描 for(FontNum=0;FontNum { for(j=0;j { k=15; for(row=0;row<16;row++) //显示16*16屏幕一次 { yfs(); //选通显示列 //行选线,P3 低四位 fs (~*(zz+FontNum*32+(i+row)*2+1)); //以移动偏移为基础获取新数据 fs(~*(zz+FontNum*32+(i+row)*2)); //获取显示数据 循环显示关键算法 ys (12); //适当延时 } } } } } void wbzd () interrupt 0 { //外部中断 j++; if (j>1) j=0; ys(10); while (!kg) { k=15; for (i=0;i<16;i++) { yfs(); xfs(i); ys(10); } } if (j==0) gdhs(zbm,8,2); if (j==1) gdhs(zbm1,10,1); } void main () { EA = 1; //打开总中断 EX0=1; IT0=1; while (1) { if (j==0) gdhs(zbm,8,5); if (j==1) gdhs(zbm1,10,3); } } |
|
|
|
所参看的例程里面那么多的新定义量,那该如何判断才不会出现别的错误?
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
464 浏览 0 评论
478 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
439 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
994 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1056 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11787 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 15:01 , Processed in 0.701512 second(s), Total 78, Slave 58 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号