完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
简单介绍下,我的初衷是控制步进电机旋转方向和速度,并以12864显示
设计中有四个按钮开关,从上到下依次是:控制旋转的开关;控制方向的开关;增加速度的按钮;减少速度的按钮。我遇到的问题是:1、点击“增速按钮"和”减速按钮“时,12864显示屏都会出现故障。但如果把sp(speed)从中断程序中放到main函数里,就不会出现显示故障。 请问sp(speed)放到中断程序中,哪里出了问题?怎么改? (注:sp(int i)作用是当按下加减速按钮时,12864的显示不同的速度等级) 2、proteus仿真遇到这个问题,怎么解决?
我发现第2个问题和main函数一开始的这一段有关: LCDMcs=1; //右屏开显示 LCDScs=0; hz_LCDDisp16(4,0,hz_ji); LCDMcs=0; //左屏开显示 LCDScs=1; hz_LCDDisp16(0,0,hz_zhuang); hz_LCDDisp16(0,16,hz_tai); hz_LCDDisp16(0,32,hz_maohao); hz_LCDDisp16(2,0,hz_fang); hz_LCDDisp16(2,16,hz_xiang); hz_LCDDisp16(2,32,hz_maohao); hz_LCDDisp16(4,0,hz_su); hz_LCDDisp16(4,16,hz_du); hz_LCDDisp16(4,32,hz_maohao); hz_LCDDisp16(4,48,s1);
============================================================ 以下是代码 和附件============================================================
新建文件夹.rar
(79.16 KB, 下载次数: 80
)
============================================================#include /*汉字*/uchar code hz_zhuang[]={0x00,0x08,0x30,0x00,0xFF,0x20,0x20,0x20,0x20,0xFF,0x20,0x20,0x22,0x2C,0x20,0x00,0x04,0x04,0x02,0x01,0xFF,0x80,0x40,0x30,0x0E,0x01,0x06,0x18,0x20,0x40,0x80,0x00};uchar code hz_tai[]={0x00,0x04,0x84,0x84,0x44,0x24,0x54,0x8F,0x14,0x24,0x44,0x84,0x84,0x04,0x00,0x00,0x41,0x39,0x00,0x00,0x3C,0x40,0x40,0x42,0x4C,0x40,0x40,0x70,0x04,0x09,0x31,0x00};uchar code hz_fang[]={0x08,0x08,0x08,0x08,0x08,0xF8,0x89,0x8E,0x88,0x88,0x88,0x88,0x08,0x08,0x08,0x00,0x00,0x80,0x40,0x20,0x18,0x07,0x00,0x00,0x40,0x80,0x40,0x3F,0x00,0x00,0x00,0x00};uchar code hz_xiang[]={0x00,0xF8,0x08,0x08,0x0C,0xCA,0x49,0x48,0x48,0xC8,0x08,0x08,0x08,0xF8,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x1F,0x08,0x08,0x08,0x1F,0x00,0x40,0x80,0x7F,0x00,0x00};uchar code hz_maohao[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x36,0x36,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};uchar code hz_kai[]={0x80,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x82,0x82,0xFE,0x82,0x82,0x82,0x80,0x00,0x00,0x80,0x40,0x30,0x0F,0x00,0x00,0x00,0x00,0x00,0xFF,0x00,0x00,0x00,0x00,0x00};uchar code hz_guan[]={0x00,0x00,0x10,0x11,0x16,0x10,0x10,0xF0,0x10,0x10,0x14,0x13,0x10,0x00,0x00,0x00,0x81,0x81,0x41,0x41,0x21,0x11,0x0D,0x03,0x0D,0x11,0x21,0x41,0x41,0x81,0x81,0x00};uchar code hz_zheng[]={0x00,0x02,0x02,0xC2,0x02,0x02,0x02,0xFE,0x82,0x82,0x82,0x82,0x82,0x02,0x00,0x00,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x7F,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x00};uchar code hz_fan[]={0x00,0x00,0xFC,0x24,0x24,0xE4,0x24,0x24,0x22,0x22,0x22,0xA3,0x62,0x00,0x00,0x00,0x40,0x30,0x8F,0x80,0x40,0x40,0x23,0x14,0x08,0x14,0x22,0x41,0x40,0x80,0x80,0x00};uchar code hz_su[]={0x40,0x40,0x42,0xCC,0x00,0x04,0xF4,0x94,0x94,0xFF,0x94,0x94,0xF4,0x04,0x00,0x00,0x00,0x40,0x20,0x1F,0x20,0x48,0x44,0x42,0x41,0x5F,0x41,0x42,0x44,0x48,0x40,0x00};uchar code hz_du[]={0x00,0x00,0xFC,0x24,0x24,0x24,0xFC,0x25,0x26,0x24,0xFC,0x24,0x24,0x24,0x04,0x00,0x40,0x30,0x8F,0x80,0x84,0x4C,0x55,0x25,0x25,0x25,0x55,0x4C,0x80,0x80,0x80,0x00};uchar code hz_ji[]={0x20,0x30,0xAC,0x63,0x30,0x00,0x02,0x02,0xFE,0x02,0x02,0x62,0x5A,0xC6,0x00,0x00,0x22,0x67,0x22,0x12,0x12,0x40,0x30,0x8F,0x80,0x43,0x2C,0x10,0x2C,0x43,0x80,0x00}; /****************************************************************************函数功能:LCD延时程序入口参数:t出口参数:****************************************************************************/void LCDdelay(unsigned int t){ unsigned int i,j; for(i=0;i *****************************************************************************/void CheckState() { unsigned char dat,DATA;//状态信息(判断是否忙) LCDDi=0; // 数据指令选择,D/I(RS)="L" ,表示 DB7∽DB0 为显示指令数据 LCDRW=1; //R/W="H" ,E="H"数据被读到DB7∽DB0 do { DATA=0x00; LCDEnable=1; //EN下降源 LCDdelay(2);//延时 dat=DATA; LCDEnable=0; dat=0x80 & dat; //仅当第7位为0时才可操作(判别busy信号) } while(!(dat==0x00));}/*****************************************************************************函数功能:写命令到LCD程序,RS(DI)=L,RW=L,EN=H,即来一个脉冲写一次入口参数:cmdcode出口参数:*****************************************************************************/void write_com(unsigned char cmdcode){ CheckState();//检测LCD是否忙 LCDDi=0; LCDRW=0; P0=cmdcode; LCDdelay(2); LCDEnable=1; LCDdelay(2); LCDEnable=0;}/*****************************************************************************函数功能:LCD初始化程序入口参数:出口参数:*****************************************************************************/void init_lcd(){ LCDdelay(100); LCDMcs=1;//刚开始关闭两屏 LCDScs=1; LCDdelay(100); write_com(LCDLCDDisp_Off); //写初始化命令 write_com(Page_Add+0); write_com(Start_Line+0); write_com(LCDCol_Add+0); write_com(LCDLCDDisp_On);}/*****************************************************************************函数功能:写数据到LCD程序,RS(DI)=H,RW=L,EN=H,即来一个脉冲写一次入口参数:LCDDispdata出口参数:*****************************************************************************/void write_data(unsigned char LCDDispdata){ CheckState();//检测LCD是否忙 LCDDi=1; LCDRW=0; P0=LCDDispdata; LCDdelay(2); LCDEnable=1; LCDdelay(2); LCDEnable=0;}/*****************************************************************************函数功能:清除LCD内存程序入口参数:pag,col,hzk出口参数:*****************************************************************************/void Clr_Scr(){ unsigned char j,k; LCDMcs=0; //左、右屏均开显示 LCDScs=0; write_com(Page_Add+0); write_com(LCDCol_Add+0); for(k=0;k<8;k++)//控制页数0-7,共8页 { write_com(Page_Add+k); //每页每页进行写 for(j=0;j<64;j++) //每页最多可写32个中文文字或64个ASCII字符 { write_com(LCDCol_Add+j); write_data(0x00);//控制列数0-63,共64列,写点内容,列地址自动加1 } }}/*****************************************************************************函数功能:指定位置显示汉字16*16程序入口参数:page,column,hzk出口参数:*****************************************************************************/void hz_LCDDisp16(unsigned char page,unsigned char column, unsigned char code *hzk){ unsigned char j=0,i=0; for(j=0;j<2;j++) { write_com(Page_Add+page+j); write_com(LCDCol_Add+column); for(i=0;i<16;i++) write_data(hzk[16*j+i]); }} #include "stdlib.h"#include "reg52.h"#include "CONFIG.H"***it SW1=P3^0;***it SW2=P3^1;***it KEY1=P3^2;***it KEY2=P3^3;unsigned char hh=6;int ang=900; //旋转角度int n=0;int z=1; //判断正转到位int f=0; //判断负转到位int i=0;int speed=1;code unsigned char runf[8]={0x03,0x01,0x09,0x08,0x0c,0x04,0x06,0x02}; //反转(逆时针)code unsigned char runz[8]={0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03}; //正转(顺时针)void DELAY();void intial(); void sp(int i){switch(i){case 1: hz_LCDDisp16(4,48,s1); break; case 2: hz_LCDDisp16(4,48,s2); break; case 3: hz_LCDDisp16(4,48,s3); break; case 4: hz_LCDDisp16(4,48,s4); break; case 5: hz_LCDDisp16(4,48,s5); break; case 6: hz_LCDDisp16(4,48,s6); break; case 7: hz_LCDDisp16(4,48,s7); break; case 8: hz_LCDDisp16(4,48,s8); break; default: break;}}main(){ intial(); Clr_Scr(); LCDMcs=1; //右屏开显示 LCDScs=0; hz_LCDDisp16(4,0,hz_ji); LCDMcs=0; //左屏开显示 LCDScs=1; hz_LCDDisp16(0,0,hz_zhuang); hz_LCDDisp16(0,16,hz_tai); hz_LCDDisp16(0,32,hz_maohao); hz_LCDDisp16(2,0,hz_fang); hz_LCDDisp16(2,16,hz_xiang); hz_LCDDisp16(2,32,hz_maohao); hz_LCDDisp16(4,0,hz_su); hz_LCDDisp16(4,16,hz_du); hz_LCDDisp16(4,32,hz_maohao); hz_LCDDisp16(4,48,s1); while(1){ if(SW1) //判断电机是否运行 { hz_LCDDisp16(0,48,hz_kai); if(SW2) //判断是否反转 { hz_LCDDisp16(2,48,hz_fan); if(ang==0) { for(i=0;i<8;i++) { P1=runf; DELAY(); } } else { if(f) { n=ang/45; while(n>0) { for(i=8-((i-1)%8);n>0;n--) { P1=runf[i%8]; i++; DELAY(); } } f=0;z=1; } } } else { hz_LCDDisp16(2,48,hz_zheng); if(ang==0) { for(i=0;i<8;i++) { P1=runz; DELAY(); } } else {if(z) {n=ang/45; while(n>0) { for(i=0;n>0;n--) { P1=runz[i%8]; i++; DELAY(); } } z=0;f=1; } } } } else { hz_LCDDisp16(0,48,hz_guan); if(SW2) {hz_LCDDisp16(2,48,hz_fan);} else {hz_LCDDisp16(2,48,hz_zheng);} } }}void intial(){TMOD=0x10;TH1=0x3c;//定时50msTL1=0xb0;TR1=1;IE=0x8d; } void DELAY(){unsigned char i,j; i=(50-hh)*10; for(;i>0;i--) { j=(50-hh)*10; for(;j>0;j--);}}void time_1()interrupt 3 using 3{TH1=0x3c;TL1=0xb0;} void int_0() interrupt 0 using 0{unsigned int i;hh=hh+2;speed=hh/2-2; sp(speed); for(i=10000000;i>0;i--) {if(hh>=20) { hh=20;speed=8;} }} void int_1() interrupt 2 using 2{unsigned int i;hh=hh-2;speed=hh/2-2;sp(speed); for(i=10000000;i>0;i--) {if(hh<=6) { hh=6;speed=1;} }} |
|
相关推荐
7个回答
|
|
额...后面稍稍有点乱,大家直接下载附件看就行了。再次感谢~
|
|
|
|
自己买个显示器12864就好了
|
|
|
|
|
|
|
|
我已经解决了。删掉中断的using就好了。虽然为什么要删掉我还是不知道
|
|
|
|
|
|
|
|
楼主第二个问题解决了吗,求告知怎么改
|
|
|
|
求楼主修改完整版,谢谢
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
726 浏览 0 评论
777 浏览 1 评论
基于瑞萨FPB-RA4E2智能床头灯项目——1编译环境搭建与点亮驱动ws2812全彩LED
680 浏览 0 评论
嵌入式学习-飞凌嵌入式ElfBoard ELF 1板卡-LCD显示图片编程示例之介绍mmap
1149 浏览 0 评论
《DNESP32S3使用指南-IDF版_V1.6》第二章 常用的C语言知识点
1120 浏览 0 评论
【youyeetoo X1 windows 开发板体验】少儿AI智能STEAM积木平台
11806 浏览 31 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-27 14:33 , Processed in 0.670581 second(s), Total 81, Slave 64 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号