完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
lcd亮了,按键也对,现在就是光敏电阻和步进电机之间有问题 |
|
|
|
|
|
|
|
电机可以转,这是图片
这是仿真 你手动给P3^5引脚高和低电平,看看转不转! |
|
|
|
帮你实验好了!具体逻辑自己在调整吧!
这是全套的仿真和编译文件!
|
|
|
|
|
|
|
|
哦。 里面有液晶显示和电机正转的程序。另外两个还需要你自己调试了。 你电机控制有问题,这个达林顿管使用不当。 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
这样,我们不是分开实验了吗! 第一、只看电机转不转!不转,我给改了电路,转了。!!!注意啊,是改后才可以转了 第二、改变光敏,看看那个正反馈是否有电压变化,有。说明光敏电路好使 第三、IO接上拉,按键接地,取代光敏电阻。按下按键是低电平,不按则是高,模拟光敏!电机没有反应,说明是单片机内部编程问题 结论:电机不好使,我给改了。内部逻辑不对,我没改,你自己在查查 |
|
|
|
|
|
|
|
#include #include //IO口设置 a=IN1,b=IN2 ***it a=P2^4; //L298信号口,{ a=1 ;b=0;} //启动输出 正转 ***it b=P2^5; // { a=0 ;b=1;} //启动输出 反转 ***it K1 =P1^0 ; //减少键 ***it K2 =P1^1 ; //增加键 ***it K3 =P1^2 ; //正转键 ***it K4 =P1^3 ; //反转键 unsigned int speed_s=10; //设置的转速,单位r/s unsigned int speed_m=0; //测量的转速 unsigned char zhuanxiang=1; //转向标志,0不转,1正转,2反转.默认正转 .... #define LCD_DATA P0 ***it LCD_RS = P2^0; ***it LCD_RW = P2^1; ***it LCD_EN = P2^2; unsigned char dispBuff0[16]={'S','D',':',' ',' ',' ',' ',' ',' ',' ',' ','r','/','m','i','n'};//LCD第一行显示 不显示用空格 unsigned char dispBuff1[16]={'D','Q',':',' ',' ',' ',' ',' ',' ',' ',' ','r','/','m','i','n'};//LCD第二行显示 void Delay20ms() ; void LCD_WriteDat(unsigned char lcd_dat); void LCD_WriteCmd(unsigned char lcd_cmd); unsigned char LCD_ReadStatus(void); void LCD_Goto(unsigned char x,unsigned char y); void LCD_Display(unsigned char row,unsigned char *str); void LCD_Init(void) { Delay20ms(); LCD_WriteCmd(0x38); //8位机接口、双行显示、5×7字符点阵; LCD_WriteCmd(0x0c); //显示开启、光标不显示也不闪烁; LCD_WriteCmd(0x01); //清屏; LCD_WriteCmd(0x06); //光标右移一位、整屏不移动; LCD_Goto(0,0); } void LCD_WriteDat(unsigned char lcd_dat) //写数据 数字 字母 { unsigned char tmp; tmp = LCD_ReadStatus(); //读状态; while((tmp & 0x80)) //是否忙 ? { tmp = LCD_ReadStatus(); } LCD_RS = 1; //数据寄存器 LCD_RW = 0; //写 LCD_DATA = lcd_dat; _nop_(); LCD_EN = 0; _nop_(); _nop_(); LCD_EN = 1; } void LCD_WriteCmd(unsigned char lcd_cmd) //写指令数据到LCD { unsigned char tmp; tmp = LCD_ReadStatus(); while((tmp & 0x80)) { tmp = LCD_ReadStatus(); } LCD_RS = 0; //指令寄存器 LCD_RW = 0; //写 LCD_DATA = lcd_cmd; _nop_(); LCD_EN = 0; _nop_(); _nop_(); LCD_EN = 1; } unsigned char LCD_ReadStatus(void) { unsigned char tmp; #if 0 LCD_RS = 0; LCD_RW = 1; LCD_EN = 1; tmp = LCD_DATA; LCD_EN = 0; #endif LCD_DATA = 0xff; LCD_RS = 0; LCD_RW = 1; LCD_EN = 0; _nop_(); _nop_(); LCD_EN = 1; tmp = LCD_DATA; return tmp; } void LCD_Goto(unsigned char x,unsigned char y) { unsigned char tmp; if(y) //若是第二行; { tmp = 0xc0 + x; LCD_WriteCmd(tmp); } else { tmp = 0x80 + x; LCD_WriteCmd(tmp); } } void LCD_Display(unsigned char row,unsigned char *str) { if(row) { LCD_Goto(0,1); } else { LCD_Goto(0,0); } while(*str != ' |