该程序主要是通过按键来使音量变大变小静音 再通过显示屏显示出来。求帮助啊。。。。。
//头文件
#include <reg51.h>
#include <intrins.h>
#include <math.h>
//液晶函数
#include "1602.h"
#define uchar unsigned char
#define uint unsigned int
//定义按键
sbit k1=P2^0;
sbit k2=P2^1;
sbit k3=P2^2;
sbit k4=P2^3;
//定义输出
sbit out1=P3^0;
sbit out2=P3^1;
uchar vo=1;
//正反转时序A-B-C-D
unsigned char code FFW[8]={0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8,0xf9}; //反转
unsigned char code FFZ[8]={0xf9,0xf8,0xfc,0xf4,0xf6,0xf2,0xf3,0xf1}; //正转
unsigned int K;
//--延时程序
void delay1(unsigned int t)
{
unsigned int k;
while(t--)
{
for(k=0; k<80; k++)
{ }
}
}
//步进电机驱动1
void motor_ffw1()
{
unsigned char i;
unsigned int j;
//转1*n圈
for (j=0; j<2; j++)
{
for (i=0; i<8; i++) //一个周期转30度
{
if(K==1) P1 = FFW[i]&0x0f; //取数据
if(K==2) P1 = FFZ[i]&0x0f;
delay1(10); //调节转速
}
}
}
//显示字符:Volume: 100
//显示字符:Status: stop
void xianshi1()
{
//定义显示位置---显示字符
LED1602_adr(0x00); LED1602_writenumber('V');
LED1602_adr(0x01); LED1602_writenumber('o');
LED1602_adr(0x02); LED1602_writenumber('l');
LED1602_adr(0x03); LED1602_writenumber('u');
LED1602_adr(0x04); LED1602_writenumber('m');
LED1602_adr(0x05); LED1602_writenumber('e');
LED1602_adr(0x06); LED1602_writenumber(':');
LED1602_adr(0x07); LED1602_writenumber(0x30+vo/100);
LED1602_adr(0x08); LED1602_writenumber(0x30+vo%100/10);
LED1602_adr(0x09); LED1602_writenumber(0x30+vo%100);
//
LED1602_adr(0x40); LED1602_writenumber('s');
LED1602_adr(0x41); LED1602_writenumber('t');
LED1602_adr(0x42); LED1602_writenumber('a');
LED1602_adr(0x43); LED1602_writenumber('t');
LED1602_adr(0x44); LED1602_writenumber('u');
LED1602_adr(0x45); LED1602_writenumber('s');
LED1602_adr(0x46); LED1602_writenumber(':');
LED1602_adr(0x47); LED1602_writenumber('s');
}
//主函数
void main()
{
//端口配置
P0=0;P1=0;P2=0;P3=0;
//-延时
_delay_ms(100);
//-初始化液晶
lcd_init();
//-延时
_delay_ms(400);
while(1)
{
k1=k2=k3=k4=1;
if(k1==0)out1=1;vo=(vo+1)%101;K=1;motor_ffw1();out1=0; while(k1==0);
if(k2==0)out2=1;vo=(vo+1)%101;K=2;motor_ffw1();out2=0; while(k2==0);
if(k3==0)vo=0; while(k3==0);
if(k4==0)vo=5; while(k4==0);
xianshi1();
}
}
-
一周热门 更多>